diff options
-rw-r--r-- | ChangeLog | 21 | ||||
-rw-r--r-- | compile.c | 36 | ||||
-rw-r--r-- | insns.def | 18 | ||||
-rw-r--r-- | iseq.c | 12 | ||||
-rw-r--r-- | iseq.h | 59 | ||||
-rw-r--r-- | vm_core.h | 36 |
6 files changed, 110 insertions, 72 deletions
@@ -1,3 +1,24 @@ +Sun Oct 31 09:30:51 2010 Koichi Sasada <ko1@atdot.net> + + * vm_core.h: some refactoring. + - move decl. of rb_compile_option_struct to iseq.h. + - define enum iseq_type. + - define enum vm_special_object_type. + + * compile.c: some refactoring. + - apply above changes. + - (struct iseq_link_element): change value of type. + - remove unused decl. + - fix comment. + - rename iseq_build_body and iseq_build_exception to + iseq_build_from_ary_body and iseq_build_from_ary_exception. + + * iseq.h: define enum catch_type and enum defined_type. + + * insns.def: apply above changes. + + * iseq.c: define ISEQ_MAJOR_VERSION and ISEQ_MINOR_VERSION. + Sat Oct 30 23:38:59 2010 Kouhei Sutou <kou@cozmixng.org> * lib/rexml/encoding.rb: untabify. @@ -24,10 +24,10 @@ typedef struct iseq_link_element { enum { - ISEQ_ELEMENT_NONE = INT2FIX(0x00), - ISEQ_ELEMENT_LABEL = INT2FIX(0x01), - ISEQ_ELEMENT_INSN = INT2FIX(0x02), - ISEQ_ELEMENT_ADJUST = INT2FIX(0x03) + ISEQ_ELEMENT_NONE, + ISEQ_ELEMENT_LABEL, + ISEQ_ELEMENT_INSN, + ISEQ_ELEMENT_ADJUST, } type; struct iseq_link_element *next; struct iseq_link_element *prev; @@ -329,8 +329,6 @@ static int insn_data_length(INSN *iobj); static int insn_data_line_no(INSN *iobj); static int calc_sp_depth(int depth, INSN *iobj); -static void ADD_ELEM(ISEQ_ARG_DECLARE LINK_ANCHOR *anchor, LINK_ELEMENT *elem); - static INSN *new_insn_body(rb_iseq_t *iseq, int line_no, int insn_id, int argc, ...); static LABEL *new_label_body(rb_iseq_t *iseq, long line); static ADJUST *new_adjust_body(rb_iseq_t *iseq, LABEL *label, int line); @@ -1252,7 +1250,7 @@ static const struct st_hash_type cdhash_type = { }; /** - ruby insn object array -> raw instruction sequence + ruby insn object list -> raw instruction sequence */ static int iseq_set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *anchor) @@ -2859,7 +2857,7 @@ add_ensure_iseq(LINK_ANCHOR *ret, rb_iseq_t *iseq, int is_return) } static VALUE -setup_args(rb_iseq_t *iseq, LINK_ANCHOR *args, NODE *argn, unsigned long *flag) +setup_args(rb_iseq_t *iseq, LINK_ANCHOR *args, NODE *argn, VALUE *flag) { VALUE argc = INT2FIX(0); int nsplat = 0; @@ -3743,7 +3741,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) case NODE_OP_ASGN1: { DECL_ANCHOR(args); VALUE argc; - unsigned long flag = 0; + VALUE flag = 0; ID id = node->nd_mid; int boff = 0; @@ -4024,7 +4022,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) DECL_ANCHOR(args); ID mid = node->nd_mid; VALUE argc; - unsigned long flag = 0; + VALUE flag = 0; VALUE parent_block = iseq->compile_data->current_block; iseq->compile_data->current_block = Qfalse; @@ -4121,7 +4119,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) case NODE_ZSUPER:{ DECL_ANCHOR(args); VALUE argc; - unsigned long flag = 0; + VALUE flag = 0; VALUE parent_block = iseq->compile_data->current_block; INIT_ANCHOR(args); @@ -4292,7 +4290,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) case NODE_YIELD:{ DECL_ANCHOR(args); VALUE argc; - unsigned long flag = 0; + VALUE flag = 0; INIT_ANCHOR(args); if (iseq->type == ISEQ_TYPE_TOP) { @@ -4907,7 +4905,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) case NODE_ATTRASGN:{ DECL_ANCHOR(recv); DECL_ANCHOR(args); - unsigned long flag = 0; + VALUE flag = 0; VALUE argc; INIT_ANCHOR(recv); @@ -5170,7 +5168,7 @@ get_exception_sym2type(VALUE sym) if (sym == symEnsure) return CATCH_TYPE_ENSURE; if (sym == symRetry) return CATCH_TYPE_RETRY; if (sym == symBreak) return CATCH_TYPE_BREAK; - if (sym == symRedo) return CATCH_TYPE_REDO; + if (sym == symRedo) return CATCH_TYPE_REDO; if (sym == symNext) return CATCH_TYPE_NEXT; rb_raise(rb_eSyntaxError, "invalid exception symbol: %s", RSTRING_PTR(rb_inspect(sym))); @@ -5178,7 +5176,7 @@ get_exception_sym2type(VALUE sym) } static int -iseq_build_exception(rb_iseq_t *iseq, struct st_table *labels_table, +iseq_build_from_ary_exception(rb_iseq_t *iseq, struct st_table *labels_table, VALUE exception) { int i; @@ -5227,7 +5225,7 @@ insn_make_insn_table(void) } static int -iseq_build_body(rb_iseq_t *iseq, LINK_ANCHOR *anchor, +iseq_build_from_ary_body(rb_iseq_t *iseq, LINK_ANCHOR *anchor, VALUE body, struct st_table *labels_table) { /* TODO: body should be frozen */ @@ -5370,9 +5368,7 @@ rb_iseq_build_from_ary(rb_iseq_t *iseq, VALUE locals, VALUE args, int i; ID *tbl; struct st_table *labels_table = st_init_numtable(); - DECL_ANCHOR(anchor); - INIT_ANCHOR(anchor); iseq->local_table_size = RARRAY_LENINT(locals); @@ -5430,10 +5426,10 @@ rb_iseq_build_from_ary(rb_iseq_t *iseq, VALUE locals, VALUE args, } /* exception */ - iseq_build_exception(iseq, labels_table, exception); + iseq_build_from_ary_exception(iseq, labels_table, exception); /* body */ - iseq_build_body(iseq, anchor, body, labels_table); + iseq_build_from_ary_body(iseq, anchor, body, labels_table); return iseq->self; } @@ -336,7 +336,9 @@ putspecialobject () (VALUE val) { - switch (value_type) { + enum vm_special_object_type type = value_type; + + switch (type) { case VM_SPECIAL_OBJECT_VMCORE: val = rb_mRubyVMFrozenCore; break; @@ -746,12 +748,14 @@ adjuststack */ DEFINE_INSN defined -(rb_num_t type, VALUE obj, VALUE needstr) +(rb_num_t op_type, VALUE obj, VALUE needstr) (VALUE v) (VALUE val) { VALUE klass; const char *expr_type = 0; + enum defined_type type = op_type; + val = Qnil; switch (type) { @@ -994,9 +998,9 @@ send const rb_method_entry_t *me; VALUE recv, klass; rb_block_t *blockptr = 0; - int num = caller_setup_args(th, GET_CFP(), op_flag, (int)op_argc, + VALUE flag = op_flag; + int num = caller_setup_args(th, GET_CFP(), flag, (int)op_argc, (rb_iseq_t *)blockiseq, &blockptr); - rb_num_t flag = op_flag; ID id = op_id; /* get receiver */ @@ -1020,13 +1024,15 @@ invokesuper (VALUE val) // inc += - (int)(op_argc + ((op_flag & VM_CALL_ARGS_BLOCKARG_BIT) ? 1 : 0)); { rb_block_t *blockptr = !(op_flag & VM_CALL_ARGS_BLOCKARG_BIT) ? GET_BLOCK_PTR() : 0; - int num = caller_setup_args(th, GET_CFP(), op_flag, + VALUE flag = op_flag; + int num = caller_setup_args(th, GET_CFP(), flag, (int)op_argc, blockiseq, &blockptr); VALUE recv, klass; ID id; - VALUE flag = VM_CALL_SUPER_BIT | VM_CALL_FCALL_BIT; const rb_method_entry_t *me; + flag = VM_CALL_SUPER_BIT | VM_CALL_FCALL_BIT; + recv = GET_SELF(); vm_search_superclass(GET_CFP(), GET_ISEQ(), recv, TOPN(num), &id, &klass); @@ -19,6 +19,9 @@ #include "insns.inc" #include "insns_info.inc" +#define ISEQ_MAJOR_VERSION 1 +#define ISEQ_MINOR_VERSION 2 + VALUE rb_cISeq; #define hidden_obj_p(obj) (!SPECIAL_CONST_P(obj) && !RBASIC(obj)->klass) @@ -1331,8 +1334,8 @@ iseq_data_to_ary(rb_iseq_t *iseq) * :catch_table, :bytecode] */ rb_ary_push(val, rb_str_new2("YARVInstructionSequence/SimpleDataFormat")); - rb_ary_push(val, INT2FIX(1)); /* major */ - rb_ary_push(val, INT2FIX(2)); /* minor */ + rb_ary_push(val, INT2FIX(ISEQ_MAJOR_VERSION)); /* major */ + rb_ary_push(val, INT2FIX(ISEQ_MINOR_VERSION)); /* minor */ rb_ary_push(val, INT2FIX(1)); rb_ary_push(val, misc); rb_ary_push(val, iseq->name); @@ -1508,6 +1511,11 @@ Init_ISeq(void) rb_define_method(rb_cISeq, "to_a", iseq_to_a, 0); rb_define_method(rb_cISeq, "eval", iseq_eval, 0); +#if 0 /* TBD */ + rb_define_method(rb_cISeq, "marshal_dump", iseq_marshal_dump, 0); + rb_define_method(rb_cISeq, "marshal_load", iseq_marshal_load, 1); +#endif + /* disable this feature because there is no verifier. */ /* rb_define_singleton_method(rb_cISeq, "load", iseq_s_load, -1); */ (void)iseq_s_load; @@ -26,22 +26,17 @@ VALUE rb_iseq_build_from_ary(rb_iseq_t *iseq, VALUE locals, VALUE args, VALUE rb_iseq_load(VALUE data, VALUE parent, VALUE opt); struct st_table *ruby_insn_make_insn_table(void); -#define ISEQ_TYPE_TOP INT2FIX(1) -#define ISEQ_TYPE_METHOD INT2FIX(2) -#define ISEQ_TYPE_BLOCK INT2FIX(3) -#define ISEQ_TYPE_CLASS INT2FIX(4) -#define ISEQ_TYPE_RESCUE INT2FIX(5) -#define ISEQ_TYPE_ENSURE INT2FIX(6) -#define ISEQ_TYPE_EVAL INT2FIX(7) -#define ISEQ_TYPE_MAIN INT2FIX(8) -#define ISEQ_TYPE_DEFINED_GUARD INT2FIX(9) - -#define CATCH_TYPE_RESCUE ((int)INT2FIX(1)) -#define CATCH_TYPE_ENSURE ((int)INT2FIX(2)) -#define CATCH_TYPE_RETRY ((int)INT2FIX(3)) -#define CATCH_TYPE_BREAK ((int)INT2FIX(4)) -#define CATCH_TYPE_REDO ((int)INT2FIX(5)) -#define CATCH_TYPE_NEXT ((int)INT2FIX(6)) +struct rb_compile_option_struct { + int inline_const_cache; + int peephole_optimization; + int tailcall_optimization; + int specialized_instruction; + int operands_unification; + int instructions_unification; + int stack_caching; + int trace_instruction; + int debug_level; +}; struct iseq_insn_info_entry { unsigned short position; @@ -50,7 +45,14 @@ struct iseq_insn_info_entry { }; struct iseq_catch_table_entry { - VALUE type; + enum catch_type { + CATCH_TYPE_RESCUE, + CATCH_TYPE_ENSURE, + CATCH_TYPE_RETRY, + CATCH_TYPE_BREAK, + CATCH_TYPE_REDO, + CATCH_TYPE_NEXT, + } type; VALUE iseq; unsigned long start; unsigned long end; @@ -94,16 +96,19 @@ struct iseq_compile_data { }; /* defined? */ -#define DEFINED_IVAR INT2FIX(1) -#define DEFINED_IVAR2 INT2FIX(2) -#define DEFINED_GVAR INT2FIX(3) -#define DEFINED_CVAR INT2FIX(4) -#define DEFINED_CONST INT2FIX(5) -#define DEFINED_METHOD INT2FIX(6) -#define DEFINED_YIELD INT2FIX(7) -#define DEFINED_REF INT2FIX(8) -#define DEFINED_ZSUPER INT2FIX(9) -#define DEFINED_FUNC INT2FIX(10) + +enum defined_type { + DEFINED_IVAR = 1, + DEFINED_IVAR2, + DEFINED_GVAR, + DEFINED_CVAR, + DEFINED_CONST, + DEFINED_METHOD, + DEFINED_YIELD, + DEFINED_REF, + DEFINED_ZSUPER, + DEFINED_FUNC, +}; #if defined __GNUC__ && __GNUC__ >= 4 #pragma GCC visibility pop @@ -122,17 +122,7 @@ typedef unsigned long rb_num_t; struct iseq_compile_data_ensure_node_stack; -typedef struct rb_compile_option_struct { - int inline_const_cache; - int peephole_optimization; - int tailcall_optimization; - int specialized_instruction; - int operands_unification; - int instructions_unification; - int stack_caching; - int trace_instruction; - int debug_level; -} rb_compile_option_t; +typedef struct rb_compile_option_struct rb_compile_option_t; struct iseq_inline_cache_entry { VALUE ic_vmstat; @@ -162,7 +152,18 @@ struct rb_iseq_struct { /* static data */ /***************/ - VALUE type; /* instruction sequence type */ + enum iseq_type { + ISEQ_TYPE_TOP, + ISEQ_TYPE_METHOD, + ISEQ_TYPE_BLOCK, + ISEQ_TYPE_CLASS, + ISEQ_TYPE_RESCUE, + ISEQ_TYPE_ENSURE, + ISEQ_TYPE_EVAL, + ISEQ_TYPE_MAIN, + ISEQ_TYPE_DEFINED_GUARD, + } type; /* instruction sequence type */ + VALUE name; /* String: iseq name */ VALUE filename; /* file information where this sequence from */ VALUE filepath; /* real file path or nil */ @@ -374,8 +375,7 @@ struct rb_unblock_callback { struct rb_mutex_struct; -typedef struct rb_thread_struct -{ +typedef struct rb_thread_struct { VALUE self; rb_vm_t *vm; @@ -552,9 +552,11 @@ typedef struct { #define VM_CALL_SUPER_BIT (0x01 << 7) #define VM_CALL_OPT_SEND_BIT (0x01 << 8) -#define VM_SPECIAL_OBJECT_VMCORE 0x01 -#define VM_SPECIAL_OBJECT_CBASE 0x02 -#define VM_SPECIAL_OBJECT_CONST_BASE 0x03 +enum vm_special_object_type { + VM_SPECIAL_OBJECT_VMCORE = 1, + VM_SPECIAL_OBJECT_CBASE, + VM_SPECIAL_OBJECT_CONST_BASE, +}; #define VM_FRAME_MAGIC_METHOD 0x11 #define VM_FRAME_MAGIC_BLOCK 0x21 |