yarv-diff:42
From: ko1 atdot.net
Date: 3 Jul 2005 05:50:18 -0000
Subject: [yarv-diff:42] r197 - in trunk: . rb tmpl
Author: ko1
Date: 2005-07-03 14:50:17 +0900 (Sun, 03 Jul 2005)
New Revision: 197
Modified:
trunk/ChangeLog
trunk/compile.c
trunk/compile.h
trunk/disasm.c
trunk/insns.def
trunk/opt_operand.def
trunk/rb/yasm.rb
trunk/test.rb
trunk/tmpl/optinsn.inc.tmpl
trunk/yarvcore.c
trunk/yarvcore.h
Log:
* compile.c, compile.h : INSN_OBJECT, LABEL_OBJECT -> INSN, LABEL,
ISEQ_LINK_ELEMENT, ISEQ_LINK_ANCHOR -> LINK_ELEMENT, LINK_ANCHOR,
and some fixes
* tmpl/optinsn.inc.tmpl : ditto
* yarvcore.c, yarvcore.h : remove label_object, insn_object
prepare_iseq_build, cleanup_iseq_build are added
* insns.def : remove unused variable from send
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2005-07-01 19:20:44 UTC (rev 196)
+++ trunk/ChangeLog 2005-07-03 05:50:17 UTC (rev 197)
@@ -4,6 +4,20 @@
# from Mon, 03 May 2004 01:24:19 +0900
#
+2005-07-03(Sun) 13:53:47 +0900 Koichi Sasada <ko1 atdot.net>
+
+ * compile.c, compile.h : INSN_OBJECT, LABEL_OBJECT -> INSN, LABEL,
+ ISEQ_LINK_ELEMENT, ISEQ_LINK_ANCHOR -> LINK_ELEMENT, LINK_ANCHOR,
+ and some fixes
+
+ * tmpl/optinsn.inc.tmpl : ditto
+
+ * yarvcore.c, yarvcore.h : remove label_object, insn_object
+ prepare_iseq_build, cleanup_iseq_build are added
+
+ * insns.def : remove unused variable from send
+
+
2005-07-02(Sat) 04:19:22 +0900 Koichi Sasada <ko1 atdot.net>
* insns.def : add GC protect for opt_aset
Modified: trunk/compile.c
===================================================================
--- trunk/compile.c 2005-07-01 19:20:44 UTC (rev 196)
+++ trunk/compile.c 2005-07-03 05:50:17 UTC (rev 197)
@@ -23,34 +23,72 @@
#define va_init_list(a,b) va_start(a)
#endif
+/* types */
+#define ISEQ_ELEMENT_NONE INT2FIX(0x00)
+#define ISEQ_ELEMENT_LABEL INT2FIX(0x01)
+#define ISEQ_ELEMENT_INSN INT2FIX(0x02)
+#define ISEQ_ELEMENT_SEQ INT2FIX(0x03)
+
+typedef struct iseq_link_element{
+ int type;
+ struct iseq_link_element *next;
+ struct iseq_link_element *prev;
+} LINK_ELEMENT;
+
+typedef struct iseq_link_anchor{
+ LINK_ELEMENT anchor;
+ LINK_ELEMENT *last;
+} LINK_ANCHOR;
+
+typedef struct iseq_label_data{
+ struct iseq_link_element link;
+ int label_no;
+ int position;
+ int sc_state;
+ int set;
+} LABEL;
+
+typedef struct iseq_insn_data{
+ struct iseq_link_element link;
+ int insn_id;
+ int line_no;
+ int operand_size;
+ int sc_state;
+ VALUE *operands;
+} INSN;
+
+
/* for debug */
#if CPDEBUG > 0
static long gl_node_level = 0;
static long gl_tmp = 0;
-static void debug_list(ISEQ_LINK_ANCHOR *anchor);
+static void debug_list(LINK_ANCHOR *anchor);
#endif
-void iseq_disasm_list_dump(ISEQ_LINK_ELEMENT* elem);
+void dump_disasm_list(LINK_ELEMENT* elem);
+static int insn_data_length(INSN *insnobj);
+static int insn_data_line_no(INSN *insnobj);
+static int insn_ret_num(int insn);
-static void ADD_LINKED_LIST(ISEQ_LINK_ANCHOR *anchor, ISEQ_LINK_ELEMENT* elem);
+static void ADD_ELEM(LINK_ANCHOR *anchor, LINK_ELEMENT* elem);
-static INSN_OBJECT *new_insn_body(struct iseq_object *iseqobj, int line_no,
+static INSN *new_insn_body(struct iseq_object *iseqobj, int line_no,
int insn_id, int argc, ...);
-static LABEL_OBJECT *new_label_body(struct iseq_object *iseqobj, int line);
+static LABEL *new_label_body(struct iseq_object *iseqobj, int line);
-static int iseq_compile_each(VALUE self, ISEQ_LINK_ANCHOR *anchor, NODE* n, int);
-static int iseq_setup(VALUE self, ISEQ_LINK_ANCHOR *anchor);
+static int iseq_compile_each(VALUE self, LINK_ANCHOR *anchor, NODE* n, int);
+static int iseq_setup(VALUE self, LINK_ANCHOR *anchor);
-static int iseq_optimize(struct iseq_object *iseqobj, ISEQ_LINK_ANCHOR *anchor);
-static int iseq_insns_unification(struct iseq_object *iseqobj, ISEQ_LINK_ANCHOR *anchor);
-static int set_sequence_stackcaching(struct iseq_object *iseqobj, ISEQ_LINK_ANCHOR *anchor);
-static int set_sequence(struct iseq_object *iseqobj, ISEQ_LINK_ANCHOR *anchor);
+static int iseq_optimize(struct iseq_object *iseqobj, LINK_ANCHOR *anchor);
+static int iseq_insns_unification(struct iseq_object *iseqobj, LINK_ANCHOR *anchor);
+static int set_sequence_stackcaching(struct iseq_object *iseqobj, LINK_ANCHOR *anchor);
+static int set_sequence(struct iseq_object *iseqobj, LINK_ANCHOR *anchor);
static int set_exception_table(struct iseq_object *iseqobj);
static int set_localtbl(struct iseq_object *iseqobj, ID* tbl);
-static int set_arguments(VALUE self, struct iseq_object *iseqobj, ISEQ_LINK_ANCHOR *anchor, NODE *node);
-static NODE* set_block_local_tbl(VALUE self, struct iseq_object *iseqobj, NODE *node, ISEQ_LINK_ANCHOR *anchor);
+static int set_arguments(VALUE self, struct iseq_object *iseqobj, LINK_ANCHOR *anchor, NODE *node);
+static NODE* set_block_local_tbl(VALUE self, struct iseq_object *iseqobj, NODE *node, LINK_ANCHOR *anchor);
static int set_exception_tbl(struct iseq_object *iseqobj);
static int set_optargs_table(struct iseq_object *iseqobj);
@@ -73,7 +111,7 @@
iseqobj->node = node;
if(iseqobj->type == ISEQ_TYPE_BLOCK){
- node = set_block_local_tbl(self, iseqobj, node, &list_anchor);
+ node = set_block_local_tbl(self, iseqobj, node, list_anchor);
}
/*
compile_each return nested array.
@@ -94,16 +132,16 @@
if(nd_type(sn_body->nd_head) == NODE_ARGS){
/* some method attribute process */
ndargs = sn_body->nd_head;
- set_arguments(self, iseqobj, &list_anchor, ndargs);
+ set_arguments(self, iseqobj, list_anchor, ndargs);
/* with sn_body->nd_head */
if(iseqobj->type == ISEQ_TYPE_METHOD){
iseqobj->rewind_frame_size = iseqobj->local_size + MREWIND_DSIZE();
- COMPILE(&list_anchor, "normal method", sn_body->nd_next);
+ COMPILE(list_anchor, "normal method", sn_body->nd_next);
}
else if(iseqobj->type == ISEQ_TYPE_CLASS){
iseqobj->rewind_frame_size = iseqobj->local_size + REWIND_DSIZE();
- COMPILE(&list_anchor, "class/module", sn_body->nd_next);
+ COMPILE(list_anchor, "class/module", sn_body->nd_next);
}
else{
rb_bug("must be class or method");
@@ -115,11 +153,11 @@
if(iseqobj->type == ISEQ_TYPE_CLASS){
iseqobj->rewind_frame_size = iseqobj->local_size + REWIND_DSIZE();
- COMPILE(&list_anchor, "class/module", sn_body);
+ COMPILE(list_anchor, "class/module", sn_body);
}
else if(iseqobj->type == ISEQ_TYPE_BLOCK){
iseqobj->rewind_frame_size = iseqobj->local_size + REWIND_DSIZE();
- COMPILE(&list_anchor, "normal block", sn_body);
+ COMPILE(list_anchor, "normal block", sn_body);
}
else{
rb_bug("must be class or block");
@@ -131,14 +169,14 @@
/* some method attribute process */
debugs("empty method\n");
- set_arguments(self, iseqobj, &list_anchor, sn_body);
- ADD_INSN(&list_anchor, nd_line(sn_body), putnil);
+ set_arguments(self, iseqobj, list_anchor, sn_body);
+ ADD_INSN(list_anchor, nd_line(sn_body), putnil);
iseqobj->rewind_frame_size = iseqobj->local_size + MREWIND_DSIZE();
break;
default:
- COMPILE(&list_anchor, "other scope", sn_body);
+ COMPILE(list_anchor, "other scope", sn_body);
iseqobj->rewind_frame_size = iseqobj->local_size + REWIND_DSIZE();
break;
@@ -146,40 +184,40 @@
}
else{
/* sn_body == 0 */
- ADD_INSN(&list_anchor, 0, putnil);
+ ADD_INSN(list_anchor, 0, putnil);
iseqobj->rewind_frame_size = iseqobj->local_size + REWIND_DSIZE();
}
}
else{
if(iseqobj->type == ISEQ_TYPE_BLOCK){
- LABEL_OBJECT* endl;
+ LABEL* endl;
endl = iseqobj->compile_data->end_label = NEW_LABEL(0);
iseqobj->compile_data->start_label = NEW_LABEL(0);
iseqobj->rewind_frame_size = iseqobj->local_size + REWIND_DSIZE();
- ADD_LABEL(&list_anchor, iseqobj->compile_data->start_label);
- COMPILE(&list_anchor, "block body", node);
- ADD_LABEL(&list_anchor, iseqobj->compile_data->end_label);
+ ADD_LABEL(list_anchor, iseqobj->compile_data->start_label);
+ COMPILE(list_anchor, "block body", node);
+ ADD_LABEL(list_anchor, iseqobj->compile_data->end_label);
}
else if(iseqobj->type == ISEQ_TYPE_TOP){
set_localtbl(iseqobj, ruby_scope->local_tbl);
iseqobj->rewind_frame_size = iseqobj->local_size + REWIND_DSIZE();
- COMPILE(&list_anchor, "top level node", node);
+ COMPILE(list_anchor, "top level node", node);
}
else if(iseqobj->type == ISEQ_TYPE_RESCUE){
set_exception_tbl(iseqobj);
iseqobj->rewind_frame_size = iseqobj->local_size + REWIND_DSIZE();
- COMPILE(&list_anchor, "rescue", node);
+ COMPILE(list_anchor, "rescue", node);
}
else if(iseqobj->type == ISEQ_TYPE_ENSURE){
set_exception_tbl(iseqobj);
iseqobj->rewind_frame_size = iseqobj->local_size + REWIND_DSIZE();
- COMPILE_POPED(&list_anchor, "ensure", node);
+ COMPILE_POPED(list_anchor, "ensure", node);
}
else if(node == 0){
- COMPILE(&list_anchor, "nil", node);
+ COMPILE(list_anchor, "nil", node);
}
else{
rb_bug("unknown scope");
@@ -191,14 +229,14 @@
if(iseqobj->type == ISEQ_TYPE_RESCUE ||
iseqobj->type == ISEQ_TYPE_ENSURE){
- ADD_INSN2(&list_anchor, 0, getdynamic, I2F(1), I2F(0));
- ADD_INSN1(&list_anchor, 0, throw, I2F(0));
+ ADD_INSN2(list_anchor, 0, getdynamic, I2F(1), I2F(0));
+ ADD_INSN1(list_anchor, 0, throw, I2F(0));
}
else{
- ADD_INSN1(&list_anchor, 0, end, I2F(iseqobj->rewind_frame_size));
+ ADD_INSN1(list_anchor, 0, end, I2F(iseqobj->rewind_frame_size));
}
- return iseq_setup(self, &list_anchor);
+ return iseq_setup(self, list_anchor);
}
@@ -254,12 +292,12 @@
return ptr;
}
-static struct insn_object *compile_data_alloc_insn(struct iseq_object *iseqobj){
- return (struct insn_object*)compile_data_alloc(iseqobj, sizeof(struct insn_object));
+static INSN *compile_data_alloc_insn(struct iseq_object *iseqobj){
+ return (INSN*)compile_data_alloc(iseqobj, sizeof(INSN));
}
-static struct label_object *compile_data_alloc_label(struct iseq_object *iseqobj){
- return (struct label_object*)compile_data_alloc(iseqobj, sizeof(struct label_object));
+static LABEL *compile_data_alloc_label(struct iseq_object *iseqobj){
+ return (LABEL*)compile_data_alloc(iseqobj, sizeof(LABEL));
}
@@ -268,10 +306,10 @@
*/
-static void verify_list(char *info, ISEQ_LINK_ANCHOR *anchor){
+static void verify_list(char *info, LINK_ANCHOR *anchor){
#if CPDEBUG > 0
int flag = 0;
- ISEQ_LINK_ELEMENT* list = anchor->anchor.next,
+ LINK_ELEMENT* list = anchor->anchor.next,
* plist= &anchor->anchor;
while(list){
if(plist != list->prev){
@@ -293,7 +331,7 @@
/*
* elem1, elem2 => elem1, elem2, elem
*/
-static void ADD_LINKED_LIST(ISEQ_LINK_ANCHOR *anchor, ISEQ_LINK_ELEMENT* elem){
+static void ADD_ELEM(LINK_ANCHOR *anchor, LINK_ELEMENT* elem){
elem->prev = anchor->last;
anchor->last->next = elem;
anchor->last = elem;
@@ -305,8 +343,8 @@
/*
* elem1, elemX => elem1, elem2, elemX
*/
-static void INSERT_ELEM_NEXT(ISEQ_LINK_ELEMENT* elem1,
- ISEQ_LINK_ELEMENT* elem2){
+static void INSERT_ELEM_NEXT(LINK_ELEMENT* elem1,
+ LINK_ELEMENT* elem2){
elem2->next = elem1->next;
elem2->prev = elem1;
elem1->next = elem2;
@@ -318,8 +356,8 @@
/*
* elemX, elem1 => elemX, elem2, elem1
*/
-static void INSERT_ELEM_PREV(ISEQ_LINK_ELEMENT* elem1,
- ISEQ_LINK_ELEMENT* elem2){
+static void INSERT_ELEM_PREV(LINK_ELEMENT* elem1,
+ LINK_ELEMENT* elem2){
elem2->prev = elem1->prev;
elem2->next = elem1;
elem1->prev = elem2;
@@ -333,8 +371,8 @@
/*
* elemX, elem1, elemY => elemX, elem2, elemY
*/
-static void REPLACE_ELEM(ISEQ_LINK_ELEMENT* elem1,
- ISEQ_LINK_ELEMENT* elem2){
+static void REPLACE_ELEM(LINK_ELEMENT* elem1,
+ LINK_ELEMENT* elem2){
elem2->prev = elem1->prev;
elem2->next = elem1->next;
if(elem1->prev){
@@ -345,31 +383,31 @@
}
}
-static void REMOVE_ELEM(ISEQ_LINK_ELEMENT *elem){
+static void REMOVE_ELEM(LINK_ELEMENT *elem){
elem->prev->next = elem->next;
if(elem->next){
elem->next->prev = elem->prev;
}
}
-static ISEQ_LINK_ELEMENT *FIRST_ELEMENT(ISEQ_LINK_ANCHOR *anchor){
+static LINK_ELEMENT *FIRST_ELEMENT(LINK_ANCHOR *anchor){
return anchor->anchor.next;
}
-static ISEQ_LINK_ELEMENT *LAST_ELEMENT(ISEQ_LINK_ANCHOR *anchor){
+static LINK_ELEMENT *LAST_ELEMENT(LINK_ANCHOR *anchor){
return anchor->last;
}
-static ISEQ_LINK_ELEMENT *POP_ELEMENT(ISEQ_LINK_ANCHOR *anchor){
- ISEQ_LINK_ELEMENT *elem = anchor->last;
+static LINK_ELEMENT *POP_ELEMENT(LINK_ANCHOR *anchor){
+ LINK_ELEMENT *elem = anchor->last;
anchor->last = anchor->last->prev;
anchor->last->next = 0;
verify_list("pop", anchor);
return elem;
}
-static int LIST_SIZE(ISEQ_LINK_ANCHOR *anchor){
- ISEQ_LINK_ELEMENT *elem = anchor->anchor.next;
+static int LIST_SIZE(LINK_ANCHOR *anchor){
+ LINK_ELEMENT *elem = anchor->anchor.next;
int size = 0;
while(elem){
size += 1;
@@ -385,7 +423,7 @@
* anc1: e1, e2, e3, e4, e5
* anc2: e4, e5 (broken)
*/
-static void APPEND_LIST(ISEQ_LINK_ANCHOR *anc1, ISEQ_LINK_ANCHOR *anc2){
+static void APPEND_LIST(LINK_ANCHOR *anc1, LINK_ANCHOR *anc2){
if(anc2->anchor.next){
anc1->last->next = anc2->anchor.next;
anc2->anchor.next->prev = anc1->last;
@@ -394,8 +432,8 @@
verify_list("append", anc1);
}
-static ISEQ_LINK_ANCHOR *REVERSE_LIST(ISEQ_LINK_ANCHOR *anc){
- ISEQ_LINK_ELEMENT *first, *last, *elem, *e;
+static LINK_ANCHOR *REVERSE_LIST(LINK_ANCHOR *anc){
+ LINK_ELEMENT *first, *last, *elem, *e;
first = &anc->anchor;
elem = first->next;
last = anc->last;
@@ -423,9 +461,9 @@
return anc;
}
-static void debug_list(ISEQ_LINK_ANCHOR *anchor){
#if CPDEBUG > 0
- ISEQ_LINK_ELEMENT* list = FIRST_ELEMENT(anchor);
+static void debug_list(LINK_ANCHOR *anchor){
+ LINK_ELEMENT* list = FIRST_ELEMENT(anchor);
int i = 0;
printf("----\n");
printf("anch: %p, frst: %p, last: %p\n", &anchor->anchor, anchor->anchor.next, anchor->last);
@@ -435,13 +473,13 @@
}
printf("----\n");
- iseq_disasm_list_dump(anchor->anchor.next);
+ dump_disasm_list(anchor->anchor.next);
verify_list("debug list", anchor);
+}
#endif
-}
-static LABEL_OBJECT *new_label_body(struct iseq_object *iseqobj, int line){
- LABEL_OBJECT *labelobj = compile_data_alloc_label(iseqobj);
+static LABEL *new_label_body(struct iseq_object *iseqobj, int line){
+ LABEL *labelobj = compile_data_alloc_label(iseqobj);
static int label_no = 0;
labelobj->link.type = ISEQ_ELEMENT_LABEL;
@@ -452,9 +490,9 @@
return labelobj;
}
-static struct insn_object *new_insn_core(struct iseq_object *iseqobj, int line_no,
+static INSN *new_insn_core(struct iseq_object *iseqobj, int line_no,
int insn_id, int argc, VALUE *argv){
- INSN_OBJECT *insnobj = compile_data_alloc_insn(iseqobj);
+ INSN *insnobj = compile_data_alloc_insn(iseqobj);
insnobj->link.type = ISEQ_ELEMENT_INSN;
insnobj->link.next = 0;
@@ -466,7 +504,7 @@
return insn_optimize(insnobj);
}
-static struct insn_object *new_insn_body(struct iseq_object *iseqobj, int line_no,
+static INSN *new_insn_body(struct iseq_object *iseqobj, int line_no,
int insn_id, int argc, ...){
VALUE *operands = 0;
va_list argv;
@@ -488,9 +526,9 @@
return new_insn_core(iseqobj, line_no, insn_id, argc, operands);
}
-static struct insn_object *new_insn_send(struct iseq_object *iseqobj, int line_no,
+static INSN *new_insn_send(struct iseq_object *iseqobj, int line_no,
VALUE id, VALUE argc, VALUE block, VALUE flag){
- INSN_OBJECT *iobj = 0;
+ INSN *iobj = 0;
#ifdef OPT_BASIC_OPERATIONS
if(block == 0 && flag == I2F(0)){
ID mid = SYM2ID(id);
@@ -553,44 +591,7 @@
return ret;
}
-
-#if 0
-
-void iseq_array_to_linkedlist_each(ISEQ_LINK_ANCHOR *anchor, VALUE aval){
- struct RArray *ary = RARRAY(aval);
- int i, len = ary->len;
-
- for(i=0; i<len; i++){
- VALUE obj = ary->ptr[i];
- if(obj == Qnil){
- /* ignore */
- }
- else if(BUILTIN_TYPE(obj) == T_ARRAY){
- iseq_array_to_linkedlist_each(anchor, obj);
- }
- else if(BUILTIN_TYPE(obj) == T_DATA){
- /* maybe Insn or Label */
- ISEQ_LINK_ELEMENT *le =
- (ISEQ_LINK_ELEMENT *)DATA_PTR(obj);
-
- if(anchor->last->type == ISEQ_ELEMENT_INSN){
- struct insn_object *iobj;
- iobj = (struct insn_object *)anchor->last;
- if(iobj->insn_id == BIN(jump)){
- if(RARRAY(iobj->operands)->ptr[0] == obj){
- anchor->last = anchor->last->prev;
- }
- }
- }
-
- ADD_LINKED_LIST(anchor, le);
- }
- }
-}
-
-#endif
-
-static int iseq_setup(VALUE self, ISEQ_LINK_ANCHOR *anchor){
+static int iseq_setup(VALUE self, LINK_ANCHOR *anchor){
struct iseq_object *iseqobj;
GetISeqVal(self, iseqobj);
@@ -598,28 +599,28 @@
// iseq_array_to_linkedlist_each(anchor, seq_ary);
GC_CHECK();
- if(CPDEBUG > 5)iseq_disasm_list_dump(FIRST_ELEMENT(anchor));
+ if(CPDEBUG > 5)dump_disasm_list(FIRST_ELEMENT(anchor));
GC_CHECK();
debugs("[compile step 3.1 (iseq_optimize)]\n");
iseq_optimize(iseqobj, anchor);
- if(CPDEBUG > 5)iseq_disasm_list_dump(FIRST_ELEMENT(anchor));
+ if(CPDEBUG > 5)dump_disasm_list(FIRST_ELEMENT(anchor));
GC_CHECK();
debugs("[compile step 3.2 (iseq_insns_unification)]\n");
iseq_insns_unification(iseqobj, anchor);
- if(CPDEBUG > 5)iseq_disasm_list_dump(FIRST_ELEMENT(anchor));
+ if(CPDEBUG > 5)dump_disasm_list(FIRST_ELEMENT(anchor));
GC_CHECK();
debugs("[compile step 3.3 (set_sequence_stackcaching)]\n");
set_sequence_stackcaching(iseqobj, anchor);
- if(CPDEBUG > 5)iseq_disasm_list_dump(FIRST_ELEMENT(anchor));
+ if(CPDEBUG > 5)dump_disasm_list(FIRST_ELEMENT(anchor));
GC_CHECK();
debugs("[compile step 4 (set_sequence)]\n");
set_sequence(iseqobj, anchor);
- if(CPDEBUG > 5)iseq_disasm_list_dump(FIRST_ELEMENT(anchor));
+ if(CPDEBUG > 5)dump_disasm_list(FIRST_ELEMENT(anchor));
GC_CHECK();
GC_CHECK();
@@ -687,7 +688,7 @@
}
-NODE* set_block_local_tbl(VALUE self, struct iseq_object *iseqobj, NODE *node, ISEQ_LINK_ANCHOR *anchor){
+NODE* set_block_local_tbl(VALUE self, struct iseq_object *iseqobj, NODE *node, LINK_ANCHOR *anchor){
VALUE vars = rb_ary_new();
VALUE tmp;
NODE *nargs, *ntmp, *nelem;
@@ -720,8 +721,8 @@
id = rb_intern(buff);
/* idx-th param, current level*/
ADD_INSN2(anchor, nd_line(node), getdynamic, I2F(idx), I2F(0));
- COMPILE(&anc, "set_block_local_tbl#masgn/other", nelem);
- ADD_LINKED_LIST(anchor, LAST_ELEMENT(&anc));
+ COMPILE(anc, "set_block_local_tbl#masgn/other", nelem);
+ ADD_ELEM(anchor, LAST_ELEMENT(anc));
rb_ary_push(vars, I2F(id));
}
else{
@@ -749,8 +750,8 @@
}
iseqobj->argc = 1;
ADD_INSN2(anchor, nd_line(node), getdynamic, I2F(1), I2F(0)); /* first param, current level*/
- COMPILE(&anc, "set_block_local_tbl#lasgn/dasgn", nargs);
- ADD_LINKED_LIST(anchor, POP_ELEMENT(&anc));
+ COMPILE(anc, "set_block_local_tbl#lasgn/dasgn", nargs);
+ ADD_ELEM(anchor, POP_ELEMENT(anc));
rb_ary_push(vars, I2F(tid));
debugi("set_block_local_tbl#lasgin/dasgn", (nargs->nd_vid));
break;
@@ -841,7 +842,7 @@
/**
*/
-int set_arguments(VALUE self, struct iseq_object *iseqobj, ISEQ_LINK_ANCHOR *optargs, NODE *node){
+int set_arguments(VALUE self, struct iseq_object *iseqobj, LINK_ANCHOR *optargs, NODE *node){
int i, j;
if(node){
@@ -855,7 +856,7 @@
/* optional initializer */
if(node->nd_opt){
NODE* optarg = node->nd_opt;
- LABEL_OBJECT* label;
+ LABEL* label;
VALUE labels = rb_ary_new();
i = 0;
while(optarg){
@@ -925,11 +926,11 @@
/**
ruby insn object array -> raw instruction sequence
*/
-static int set_sequence(struct iseq_object *iseqobj, ISEQ_LINK_ANCHOR *anchor){
- struct label_object *lobj;
- struct insn_object *iobj;
+static int set_sequence(struct iseq_object *iseqobj, LINK_ANCHOR *anchor){
+ LABEL *lobj;
+ INSN *iobj;
struct insn_info_struct *insn_info_tbl;
- ISEQ_LINK_ELEMENT *list;
+ LINK_ELEMENT *list;
VALUE *generated_iseq;
int k, pos, stack_max = 0;
@@ -941,13 +942,13 @@
while(list){
switch(list->type){
case ISEQ_ELEMENT_INSN:{
- iobj = (struct insn_object*)list;
+ iobj = (INSN*)list;
pos += insn_data_length(iobj);
k+=1;
break;
}
case ISEQ_ELEMENT_LABEL:{
- lobj = (struct label_object*)list;
+ lobj = (LABEL*)list;
lobj->position = pos;
lobj->set = Qtrue;
break;
@@ -957,8 +958,8 @@
break;
}
default:
- iseq_disasm_list_dump(FIRST_ELEMENT(anchor));
- iseq_disasm_list_dump(list);
+ dump_disasm_list(FIRST_ELEMENT(anchor));
+ dump_disasm_list(list);
rb_bug("error: set_sequence");
break;
}
@@ -981,7 +982,7 @@
char *types;
VALUE *operands;
- iobj = (struct insn_object*)list;
+ iobj = (INSN*)list;
operands = iobj->operands;
insn = iobj->insn_id;
generated_iseq[pos] = insn;
@@ -991,7 +992,7 @@
/* operand check */
if(iobj->operand_size != len - 1){
- iseq_disasm_list_dump(list);
+ dump_disasm_list(list);
rb_bug("operand size miss! (%d for %d)", iobj->operand_size, len - 1);
return 0;
}
@@ -1001,7 +1002,7 @@
// printf("--> [%c - (%d-%d)]\n", type, k, j);
switch(type){
case 'L':{ /* label(destination position) */
- lobj = (LABEL_OBJECT*)operands[j];
+ lobj = (LABEL*)operands[j];
if(lobj->set != Qtrue){
rb_bug("unknown label");
}
@@ -1018,7 +1019,7 @@
for(i=0; i<RARRAY(lits)->len; i++){
VALUE pair = RARRAY(lits)->ptr[i];
- lobj = (LABEL_OBJECT *)(RARRAY(pair)->ptr[1] & ~1);
+ lobj = (LABEL *)(RARRAY(pair)->ptr[1] & ~1);
if(lobj->set != Qtrue){
rb_bug("unknown label");
@@ -1088,7 +1089,7 @@
}
static int label_get_position(VALUE self){
- LABEL_OBJECT *lobj = (LABEL_OBJECT *) self;
+ LABEL *lobj = (LABEL *) self;
return lobj->position;
}
@@ -1146,10 +1147,10 @@
return COMPILE_OK;
}
-static ISEQ_LINK_ELEMENT *
-get_destination_insn(struct insn_object *iobj){
- LABEL_OBJECT *lobj = (LABEL_OBJECT *)OPERAND_AT(iobj, 0);
- ISEQ_LINK_ELEMENT *list;
+static LINK_ELEMENT *
+get_destination_insn(INSN *iobj){
+ LABEL *lobj = (LABEL *)OPERAND_AT(iobj, 0);
+ LINK_ELEMENT *list;
list = lobj->link.next;
while(list){
@@ -1161,9 +1162,9 @@
return list;
}
-static ISEQ_LINK_ELEMENT *
-get_next_insn(struct insn_object *iobj){
- ISEQ_LINK_ELEMENT *list = iobj->link.next;
+static LINK_ELEMENT *
+get_next_insn(INSN *iobj){
+ LINK_ELEMENT *list = iobj->link.next;
while(list){
if(list->type == ISEQ_ELEMENT_INSN){
@@ -1174,9 +1175,9 @@
return 0;
}
-static ISEQ_LINK_ELEMENT *
-get_prev_insn(struct insn_object *iobj){
- ISEQ_LINK_ELEMENT *list = iobj->link.prev;
+static LINK_ELEMENT *
+get_prev_insn(INSN *iobj){
+ LINK_ELEMENT *list = iobj->link.prev;
while(list){
if(list->type == ISEQ_ELEMENT_INSN){
@@ -1187,8 +1188,8 @@
return 0;
}
-static int iseq_optimize(struct iseq_object *iseqobj, ISEQ_LINK_ANCHOR *anchor){
- ISEQ_LINK_ELEMENT *list;
+static int iseq_optimize(struct iseq_object *iseqobj, LINK_ANCHOR *anchor){
+ LINK_ELEMENT *list;
/*
* useless jump elimination:
* jump LABEL1
@@ -1203,10 +1204,10 @@
list = FIRST_ELEMENT(anchor);
while(list){
if(list->type == ISEQ_ELEMENT_INSN){
- struct insn_object *niobj, *diobj, *piobj, *iobj = (struct insn_object *)list;
+ INSN *niobj, *diobj, *piobj, *iobj = (INSN *)list;
if(iobj->insn_id == BIN(jump)){
- diobj = (struct insn_object*)get_destination_insn(iobj);
- niobj = (struct insn_object*)get_next_insn(iobj);
+ diobj = (INSN*)get_destination_insn(iobj);
+ niobj = (INSN*)get_next_insn(iobj);
if(diobj == niobj){
REMOVE_ELEM(&iobj->link);
@@ -1216,11 +1217,11 @@
continue;
}
else if(diobj->insn_id == BIN(end)){
- struct insn_object *eiobj = new_insn_core(iseqobj, iobj->line_no, BIN(end),
+ INSN *eiobj = new_insn_core(iseqobj, iobj->line_no, BIN(end),
diobj->operand_size, diobj->operands);
/* replace */
- REPLACE_ELEM((ISEQ_LINK_ELEMENT *)iobj,
- (ISEQ_LINK_ELEMENT *)eiobj);
+ REPLACE_ELEM((LINK_ELEMENT *)iobj,
+ (LINK_ELEMENT *)eiobj);
}
/*
* if L1
@@ -1235,10 +1236,10 @@
* ...
* L2:
*/
- else if ((piobj = (struct insn_object*)get_prev_insn(iobj)) != 0 &&
+ else if ((piobj = (INSN*)get_prev_insn(iobj)) != 0 &&
(piobj->insn_id == BIN(if) ||
piobj->insn_id == BIN(unless))){
- if(niobj == (INSN_OBJECT*)get_destination_insn(piobj)){
+ if(niobj == (INSN*)get_destination_insn(piobj)){
piobj->insn_id = (piobj->insn_id == BIN(if)) ? BIN(unless) : BIN(if);
OPERAND_AT(piobj, 0) = OPERAND_AT(iobj, 0);
REMOVE_ELEM(&iobj->link);
@@ -1251,17 +1252,17 @@
return COMPILE_OK;
}
-static INSN_OBJECT* new_unified_insn(struct iseq_object *iseqobj,
- int insn_id, int size, ISEQ_LINK_ELEMENT *seq_list){
- INSN_OBJECT *iobj = 0;
- ISEQ_LINK_ELEMENT *list = seq_list;
+static INSN* new_unified_insn(struct iseq_object *iseqobj,
+ int insn_id, int size, LINK_ELEMENT *seq_list){
+ INSN *iobj = 0;
+ LINK_ELEMENT *list = seq_list;
int i, argc = 0;
VALUE *operands = 0, *ptr = 0;
/* count argc */
for(i=0; i<size; i++){
- iobj = (struct insn_object*)list;
+ iobj = (INSN*)list;
argc += iobj->operand_size;
list = list->next;
}
@@ -1273,7 +1274,7 @@
/* copy operands */
list = seq_list;
for(i=0; i<size; i++){
- iobj = (struct insn_object*)list;
+ iobj = (INSN*)list;
MEMCPY(ptr, iobj->operands, VALUE, iobj->operand_size);
ptr += iobj->operand_size;
list = list->next;
@@ -1288,25 +1289,25 @@
* label address resolving.
* It's future work (if compile time was bottle neck).
*/
-static int iseq_insns_unification(struct iseq_object *iseqobj, ISEQ_LINK_ANCHOR *anchor){
+static int iseq_insns_unification(struct iseq_object *iseqobj, LINK_ANCHOR *anchor){
#ifdef OPT_INSTRUCTIONS_UNIFICATION
- ISEQ_LINK_ELEMENT *list;
- struct insn_object *iobj, *niobj;
+ LINK_ELEMENT *list;
+ INSN *iobj, *niobj;
int id, j, k;
list = FIRST_ELEMENT(anchor);
while(list){
if(list->type == ISEQ_ELEMENT_INSN){
- iobj = (struct insn_object*)list;
+ iobj = (INSN*)list;
id = iobj->insn_id;
if(unified_insns_data[id] != 0){
int **entry = unified_insns_data[id];
for(j=1; j<(int)entry[0]; j++){
int *unified = entry[j];
- ISEQ_LINK_ELEMENT *li = list->next;
+ LINK_ELEMENT *li = list->next;
for(k=2; k<unified[1]; k++){
if(li->type != ISEQ_ELEMENT_INSN ||
- ((struct insn_object *)li)->insn_id != unified[k]){
+ ((INSN *)li)->insn_id != unified[k]){
goto miss;
}
li = li->next;
@@ -1315,14 +1316,14 @@
niobj = new_unified_insn(iseqobj, unified[0], unified[1]-1, list);
/* insert to list */
- niobj->link.prev = (ISEQ_LINK_ELEMENT *)iobj->link.prev;
+ niobj->link.prev = (LINK_ELEMENT *)iobj->link.prev;
niobj->link.next = li;
if(li){
- li->prev = (ISEQ_LINK_ELEMENT *)niobj;
+ li->prev = (LINK_ELEMENT *)niobj;
}
- list->prev->next = (ISEQ_LINK_ELEMENT *)niobj;
- list = (ISEQ_LINK_ELEMENT *)niobj;
+ list->prev->next = (LINK_ELEMENT *)niobj;
+ list = (LINK_ELEMENT *)niobj;
break;
miss:;
}
@@ -1341,7 +1342,7 @@
#include "opt_sc.inc"
-int insn_set_sc_state(INSN_OBJECT *iobj, int state){
+int insn_set_sc_state(INSN *iobj, int state){
int nstate;
int insn_id;
@@ -1352,11 +1353,11 @@
if(insn_id == BIN(jump) ||
insn_id == BIN(if) ||
insn_id == BIN(unless)){
- LABEL_OBJECT *lobj = (LABEL_OBJECT*) OPERAND_AT(iobj, 0);
+ LABEL *lobj = (LABEL*) OPERAND_AT(iobj, 0);
if(lobj->sc_state != 0){
if(lobj->sc_state != nstate){
- iseq_disasm_list_dump((ISEQ_LINK_ELEMENT*) iobj);
+ dump_disasm_list((LINK_ELEMENT*) iobj);
printf("%d, %d: ", lobj->sc_state, nstate);
rb_bug("insn_set_sc_state error\n");
return 0;
@@ -1376,7 +1377,7 @@
return nstate;
}
-int label_set_sc_state(struct label_object *lobj, int state){
+int label_set_sc_state(LABEL *lobj, int state){
if(lobj->sc_state != 0){
if(lobj->sc_state != state){
state = lobj->sc_state;
@@ -1392,9 +1393,9 @@
#endif
-static int set_sequence_stackcaching(struct iseq_object *iseqobj, ISEQ_LINK_ANCHOR *anchor){
+static int set_sequence_stackcaching(struct iseq_object *iseqobj, LINK_ANCHOR *anchor){
#ifdef OPT_STACK_CACHING
- ISEQ_LINK_ELEMENT *list;
+ LINK_ELEMENT *list;
int state, insn_id;
/* initialize */
@@ -1406,20 +1407,20 @@
redo_point:
switch(list->type){
case ISEQ_ELEMENT_INSN:{
- INSN_OBJECT *iobj = (INSN_OBJECT *)list;
+ INSN *iobj = (INSN *)list;
insn_id = iobj->insn_id;
- // iseq_disasm_list_dump(list);
+ // dump_disasm_list(list);
switch(insn_id){
case BIN(nop):{
/* exception merge point */
if(state != SCS_AX){
- struct insn_object *rpobj = new_insn_body(iseqobj, 0, BIN(reput), 0);
+ INSN *rpobj = new_insn_body(iseqobj, 0, BIN(reput), 0);
/* replace this insn */
- REPLACE_ELEM(list, (ISEQ_LINK_ELEMENT *)rpobj);
- list = (ISEQ_LINK_ELEMENT *)rpobj;
+ REPLACE_ELEM(list, (LINK_ELEMENT *)rpobj);
+ list = (LINK_ELEMENT *)rpobj;
goto redo_point;
}
break;
@@ -1464,8 +1465,8 @@
break;
}
case ISEQ_ELEMENT_LABEL:{
- struct label_object *lobj;
- lobj = (struct label_object *)list;
+ LABEL *lobj;
+ lobj = (LABEL *)list;
state = label_set_sc_state(lobj, state);
}
@@ -1480,7 +1481,7 @@
-int compile_dstr(VALUE self, struct iseq_object *iseqobj, ISEQ_LINK_ANCHOR *ret, NODE *node){
+int compile_dstr(VALUE self, struct iseq_object *iseqobj, LINK_ANCHOR *ret, NODE *node){
NODE *list = node->nd_next;
VALUE lit = node->nd_lit;
int cnt = 0;
@@ -1527,8 +1528,8 @@
}
static int compile_branch_condition(VALUE self, struct iseq_object *iseqobj,
- ISEQ_LINK_ANCHOR *ret, NODE *cond,
- LABEL_OBJECT *then_label, LABEL_OBJECT *else_label){
+ LINK_ANCHOR *ret, NODE *cond,
+ LABEL *then_label, LABEL *else_label){
switch(nd_type(cond)){
case NODE_NOT:
@@ -1536,14 +1537,14 @@
break;
case NODE_AND:{
- LABEL_OBJECT *label = NEW_LABEL(nd_line(cond));
+ LABEL *label = NEW_LABEL(nd_line(cond));
compile_branch_condition(self, iseqobj, ret, cond->nd_1st, label, else_label);
ADD_LABEL(ret, label);
compile_branch_condition(self, iseqobj, ret, cond->nd_2nd, then_label, else_label);
break;
}
case NODE_OR:{
- LABEL_OBJECT *label = NEW_LABEL(nd_line(cond));
+ LABEL *label = NEW_LABEL(nd_line(cond));
compile_branch_condition(self, iseqobj, ret, cond->nd_1st, then_label, label);
ADD_LABEL(ret, label);
compile_branch_condition(self, iseqobj, ret, cond->nd_2nd, then_label, else_label);
@@ -1559,7 +1560,7 @@
}
static int compile_array(VALUE self, struct iseq_object *iseqobj,
- ISEQ_LINK_ANCHOR *ret, NODE *node_root, VALUE opt_p){
+ LINK_ANCHOR *ret, NODE *node_root, VALUE opt_p){
NODE *node = node_root;
int len = node->nd_alen, line = nd_line(node);
DECL_ANCHOR(anchor);
@@ -1568,7 +1569,7 @@
if(opt_p && nd_type(node->nd_head) != NODE_LIT){
opt_p = Qfalse;
}
- COMPILE(&anchor, "element", node->nd_head);
+ COMPILE(anchor, "element", node->nd_head);
node = node->nd_next;
}
@@ -1584,8 +1585,8 @@
ADD_INSN1(ret, nd_line(node_root), duparray, ary);
}
else{
- ADD_INSN1(&anchor, line, newarray, I2F(len));
- APPEND_LIST(ret, &anchor);
+ ADD_INSN1(anchor, line, newarray, I2F(len));
+ APPEND_LIST(ret, anchor);
}
return COMPILE_OK;
@@ -1606,15 +1607,15 @@
}
static int make_masgn_lhs(VALUE self, struct iseq_object *iseqobj,
- ISEQ_LINK_ANCHOR *ret, NODE *node){
+ LINK_ANCHOR *ret, NODE *node){
switch(nd_type(node)){
case NODE_ATTRASGN:{
- struct insn_object *iobj;
+ INSN *iobj;
VALUE dupidx;
COMPILE(ret, "masgn lhs (NODE_ATTRASGN)", node);
- iobj = (INSN_OBJECT*)ret->last;
+ iobj = (INSN*)ret->last;
ret->last = ret->last->prev;
dupidx = iobj->operands[1]; // RARRAY(iobj->operands)->ptr[1]; /* send sym, num, ... */
@@ -1622,7 +1623,7 @@
iobj->operands[1] = dupidx;
ADD_INSN1(ret, nd_line(node), topn, dupidx);
- ADD_LINKED_LIST(ret, (ISEQ_LINK_ELEMENT*) iobj);
+ ADD_ELEM(ret, (LINK_ELEMENT*) iobj);
ADD_INSN (ret, nd_line(node), pop); /* result */
ADD_INSN (ret, nd_line(node), pop); /* rhs */
break;
@@ -1631,8 +1632,8 @@
default:{
DECL_ANCHOR(anchor);
- COMPILE_POPED(&anchor, "masgn lhs", node);
- ADD_LINKED_LIST(ret, LAST_ELEMENT(&anchor));
+ COMPILE_POPED(anchor, "masgn lhs", node);
+ ADD_ELEM(ret, LAST_ELEMENT(anchor));
}
}
@@ -1640,7 +1641,7 @@
}
static int defined_expr(VALUE self, struct iseq_object *iseqobj,
- ISEQ_LINK_ANCHOR *ret, NODE *node, LABEL_OBJECT *lfinish, VALUE needstr){
+ LINK_ANCHOR *ret, NODE *node, LABEL *lfinish, VALUE needstr){
char *estr = 0;
switch(nd_type(node)){
@@ -1683,7 +1684,7 @@
return 1;
case NODE_COLON2:
if(rb_is_const_id(node->nd_mid)){
- LABEL_OBJECT *lcont = NEW_LABEL(nd_line(node));
+ LABEL *lcont = NEW_LABEL(nd_line(node));
defined_expr(self, iseqobj, ret, node->nd_head, lfinish, Qfalse);
ADD_INSNL(ret, nd_line(node), if, lcont);
@@ -1695,7 +1696,7 @@
ADD_INSN3(ret, nd_line(node), defined, I2F(DEFINED_CONST), ID2SYM(node->nd_mid), needstr);
}
else{
- LABEL_OBJECT *lcont = NEW_LABEL(nd_line(node));
+ LABEL *lcont = NEW_LABEL(nd_line(node));
defined_expr(self, iseqobj, ret, node->nd_head, lfinish, Qfalse);
ADD_INSNL(ret, nd_line(node), if, lcont);
@@ -1718,7 +1719,7 @@
case NODE_VCALL:
case NODE_FCALL:
if(nd_type(node) == NODE_CALL){
- LABEL_OBJECT *lcont = NEW_LABEL(nd_line(node));
+ LABEL *lcont = NEW_LABEL(nd_line(node));
defined_expr(self, iseqobj, ret, node->nd_recv, lfinish, Qfalse);
ADD_INSNL(ret, nd_line(node), if, lcont);
@@ -1760,7 +1761,7 @@
node: Ruby compiled node
poped: This node will be poped
*/
-static int iseq_compile_each(VALUE self, ISEQ_LINK_ANCHOR *ret, NODE* node, int poped){
+static int iseq_compile_each(VALUE self, LINK_ANCHOR *ret, NODE* node, int poped){
VALUE tmp; /* reserved for macro */
int type;
@@ -1821,24 +1822,24 @@
DECL_ANCHOR(cond_seq);
DECL_ANCHOR(then_seq);
DECL_ANCHOR(else_seq);
- LABEL_OBJECT *then_label, *else_label, *end_label;
+ LABEL *then_label, *else_label, *end_label;
then_label = NEW_LABEL(nd_line(node));
else_label = NEW_LABEL(nd_line(node));
end_label = NEW_LABEL(nd_line(node));
- compile_branch_condition(self, iseqobj, &cond_seq, node->nd_cond, then_label, else_label);
- COMPILE_(&then_seq, "then", node->nd_body, poped);
- COMPILE_(&else_seq, "else", node->nd_else, poped);
+ compile_branch_condition(self, iseqobj, cond_seq, node->nd_cond, then_label, else_label);
+ COMPILE_(then_seq, "then", node->nd_body, poped);
+ COMPILE_(else_seq, "else", node->nd_else, poped);
- ADD_SEQ (ret, &cond_seq);
+ ADD_SEQ (ret, cond_seq);
ADD_LABEL(ret, then_label);
- ADD_SEQ (ret, &then_seq);
+ ADD_SEQ (ret, then_seq);
ADD_INSNL(ret, nd_line(node), jump, end_label);
ADD_LABEL(ret, else_label);
- ADD_SEQ (ret, &else_seq);
+ ADD_SEQ (ret, else_seq);
ADD_LABEL(ret, end_label);
@@ -1848,13 +1849,13 @@
NODE* vals;
NODE* val;
NODE* tempnode = node;
- LABEL_OBJECT* endlabel, *elselabel;
+ LABEL* endlabel, *elselabel;
DECL_ANCHOR(head);
DECL_ANCHOR(body_seq);
DECL_ANCHOR(cond_seq);
VALUE special_literals = rb_ary_new();
- COMPILE(&head, "case base", node->nd_head);
+ COMPILE(head, "case base", node->nd_head);
node = node->nd_body;
type = nd_type(node);
@@ -1866,16 +1867,16 @@
endlabel = NEW_LABEL(nd_line(node));
elselabel = NEW_LABEL(nd_line(node));
- ADD_SEQ (ret, &head); /* case VAL */
+ ADD_SEQ (ret, head); /* case VAL */
while(type == NODE_WHEN){
- LABEL_OBJECT *l1;
+ LABEL *l1;
l1 = NEW_LABEL(nd_line(node));
- ADD_LABEL(&body_seq, l1);
- ADD_INSN (&body_seq, nd_line(node), pop);
- COMPILE_(&body_seq, "when body", node->nd_body, poped);
- ADD_INSNL(&body_seq, nd_line(node), jump, endlabel);
+ ADD_LABEL(body_seq, l1);
+ ADD_INSN (body_seq, nd_line(node), pop);
+ COMPILE_ (body_seq, "when body", node->nd_body, poped);
+ ADD_INSNL(body_seq, nd_line(node), jump, endlabel);
vals = node->nd_head;
if(vals && nd_type(vals) == NODE_ARRAY){
@@ -1891,10 +1892,10 @@
special_literals = Qfalse;
}
- COMPILE(&cond_seq, "when cond", val);
- ADD_INSN1(&cond_seq, nd_line(node), topn, INT2FIX(1));
- ADD_SEND (&cond_seq, nd_line(node), ID2SYM(idEqq), INT2FIX(1));
- ADD_INSNL(&cond_seq, nd_line(node), if, l1);
+ COMPILE (cond_seq, "when cond", val);
+ ADD_INSN1(cond_seq, nd_line(node), topn, INT2FIX(1));
+ ADD_SEND (cond_seq, nd_line(node), ID2SYM(idEqq), INT2FIX(1));
+ ADD_INSNL(cond_seq, nd_line(node), if, l1);
vals = vals->nd_next;
}
}
@@ -1910,19 +1911,19 @@
}
/* else */
if(node){
- ADD_LABEL(&cond_seq, elselabel);
- ADD_INSN (&cond_seq, nd_line(node), pop);
- COMPILE_ (&cond_seq, "else", node, poped);
- ADD_INSNL(&cond_seq, nd_line(node), jump, endlabel);
+ ADD_LABEL(cond_seq, elselabel);
+ ADD_INSN (cond_seq, nd_line(node), pop);
+ COMPILE_ (cond_seq, "else", node, poped);
+ ADD_INSNL(cond_seq, nd_line(node), jump, endlabel);
}
else{
debugs("== else(implicit)\n");
- ADD_LABEL(&cond_seq, elselabel);
- ADD_INSN (&cond_seq, nd_line(tempnode), pop);
+ ADD_LABEL(cond_seq, elselabel);
+ ADD_INSN (cond_seq, nd_line(tempnode), pop);
if(!poped){
- ADD_INSN(&cond_seq, nd_line(tempnode), putnil);
+ ADD_INSN(cond_seq, nd_line(tempnode), putnil);
}
- ADD_INSNL(&cond_seq, nd_line(tempnode), jump, endlabel);
+ ADD_INSNL(cond_seq, nd_line(tempnode), jump, endlabel);
}
if(special_literals){
@@ -1933,24 +1934,24 @@
rb_ary_push(iseqobj->compile_data->mark_ary, special_literals);
}
- ADD_SEQ (ret, &cond_seq);
- ADD_SEQ (ret, &body_seq);
+ ADD_SEQ (ret, cond_seq);
+ ADD_SEQ (ret, body_seq);
ADD_LABEL(ret, endlabel);
break;
}
case NODE_WHEN:{
NODE* vals;
NODE* val;
- LABEL_OBJECT* endlabel;
+ LABEL* endlabel;
DECL_ANCHOR(body_seq);
endlabel = NEW_LABEL(nd_line(node));
while(nd_type(node) == NODE_WHEN){
- LABEL_OBJECT *l1 = NEW_LABEL(nd_line(node));
- ADD_LABEL(&body_seq, l1);
- COMPILE_ (&body_seq, "when", node->nd_body, poped);
- ADD_INSNL(&body_seq, nd_line(node), jump, endlabel);
+ LABEL *l1 = NEW_LABEL(nd_line(node));
+ ADD_LABEL(body_seq, l1);
+ COMPILE_ (body_seq, "when", node->nd_body, poped);
+ ADD_INSNL(body_seq, nd_line(node), jump, endlabel);
vals = node->nd_head;
if(vals && nd_type(vals) == NODE_ARRAY){
@@ -1970,7 +1971,7 @@
COMPILE_ (ret, "else", node, poped);
ADD_INSNL(ret, nd_line(node), jump, endlabel);
- ADD_SEQ (ret, &body_seq);
+ ADD_SEQ (ret, body_seq);
ADD_LABEL(ret, endlabel);
break;
@@ -1982,18 +1983,18 @@
}
case NODE_WHILE:
case NODE_UNTIL:{
- LABEL_OBJECT *prev_start_label = iseqobj->compile_data->start_label;
- LABEL_OBJECT * prev_end_label = iseqobj->compile_data->end_label;
- LABEL_OBJECT * prev_redo_label = iseqobj->compile_data->redo_label;
+ LABEL *prev_start_label = iseqobj->compile_data->start_label;
+ LABEL * prev_end_label = iseqobj->compile_data->end_label;
+ LABEL * prev_redo_label = iseqobj->compile_data->redo_label;
VALUE prev_loopval_popped = iseqobj->compile_data->loopval_popped;
- LABEL_OBJECT * next_label = iseqobj->compile_data->start_label =
+ LABEL * next_label = iseqobj->compile_data->start_label =
NEW_LABEL(nd_line(node)); /* next */
- LABEL_OBJECT * redo_label = iseqobj->compile_data->redo_label =
+ LABEL * redo_label = iseqobj->compile_data->redo_label =
NEW_LABEL(nd_line(node)); /* redo */
- LABEL_OBJECT * break_label = iseqobj->compile_data->end_label =
+ LABEL * break_label = iseqobj->compile_data->end_label =
NEW_LABEL(nd_line(node)); /* break */
- LABEL_OBJECT * end_label = NEW_LABEL(nd_line(node));
+ LABEL * end_label = NEW_LABEL(nd_line(node));
iseqobj->compile_data->loopval_popped = poped;
@@ -2028,8 +2029,8 @@
case NODE_ITER:
case NODE_FOR:{
VALUE prevblock = iseqobj->compile_data->current_block;
- LABEL_OBJECT * retry_label = NEW_LABEL(nd_line(node));
- LABEL_OBJECT * retry_end_l = NEW_LABEL(nd_line(node));
+ LABEL * retry_label = NEW_LABEL(nd_line(node));
+ LABEL * retry_end_l = NEW_LABEL(nd_line(node));
VALUE name = rb_str_new2("b@");
rb_str_concat(name, iseqobj->name);
iseqobj->compile_data->current_block = NEW_CHILD_ISEQOBJ(node, name,
@@ -2111,9 +2112,9 @@
break;
}
case NODE_RESCUE:{
- LABEL_OBJECT * lstart = NEW_LABEL(nd_line(node));
- LABEL_OBJECT * lend = NEW_LABEL(nd_line(node));
- LABEL_OBJECT * lcont = NEW_LABEL(nd_line(node));
+ LABEL * lstart = NEW_LABEL(nd_line(node));
+ LABEL * lend = NEW_LABEL(nd_line(node));
+ LABEL * lcont = NEW_LABEL(nd_line(node));
VALUE rescue = NEW_CHILD_ISEQOBJ(node->nd_resq, rb_str_new2("rescue clause"),
self, ISEQ_TYPE_RESCUE);
@@ -2138,7 +2139,7 @@
case NODE_RESBODY:{
NODE *resq = node;
NODE *narg;
- LABEL_OBJECT * label_miss, * label_hit;
+ LABEL * label_miss, * label_hit;
while(resq){
label_miss = NEW_LABEL(nd_line(node));
@@ -2170,24 +2171,24 @@
case NODE_ENSURE:{
VALUE ensure = NEW_CHILD_ISEQOBJ(node->nd_ensr, rb_str_new2("ensure clause"),
self, ISEQ_TYPE_ENSURE);
- LABEL_OBJECT * lstart = NEW_LABEL(nd_line(node));
- LABEL_OBJECT * lend = NEW_LABEL(nd_line(node));
- LABEL_OBJECT * lcont = NEW_LABEL(nd_line(node));
+ LABEL * lstart = NEW_LABEL(nd_line(node));
+ LABEL * lend = NEW_LABEL(nd_line(node));
+ LABEL * lcont = NEW_LABEL(nd_line(node));
DECL_ANCHOR(ensr);
VALUE prev_in_ensure = iseqobj->compile_data->in_ensure;
iseqobj->compile_data->in_ensure = Qtrue;
- COMPILE_POPED(&ensr, "ensure ensr", node->nd_ensr);
+ COMPILE_POPED(ensr, "ensure ensr", node->nd_ensr);
ADD_LABEL(ret, lstart);
COMPILE_(ret, "ensure head", node->nd_head, poped);
ADD_LABEL(ret, lend);
- if(ensr.anchor.next == 0){
+ if(ensr->anchor.next == 0){
ADD_INSN(ret, nd_line(node), nop);
}
else{
- ADD_SEQ(ret, &ensr);
+ ADD_SEQ(ret, ensr);
}
ADD_LABEL(ret, lcont);
@@ -2198,7 +2199,7 @@
case NODE_AND:
case NODE_OR:{
- LABEL_OBJECT * end_label = NEW_LABEL(nd_line(node));
+ LABEL * end_label = NEW_LABEL(nd_line(node));
COMPILE(ret, "nd_1st", node->nd_1st);
if(!poped){
ADD_INSN(ret, nd_line(node), dup);
@@ -2236,13 +2237,13 @@
llen = 0;
while(lhsn){
- make_masgn_lhs(self, iseqobj, &mlhs_seq, lhsn->nd_head);
+ make_masgn_lhs(self, iseqobj, mlhs_seq, lhsn->nd_head);
llen += 1;
lhsn = lhsn->nd_next;
}
if(node->nd_args && (long)node->nd_args != -1){
- make_masgn_lhs(self, iseqobj, &mlhs_seq, node->nd_args);
+ make_masgn_lhs(self, iseqobj, mlhs_seq, node->nd_args);
lhs_splat = Qtrue;
}
@@ -2321,7 +2322,7 @@
default:
rb_bug("unknown rhs: %s", node_name(nd_type(node->nd_value)));
}
- ADD_SEQ(ret, REVERSE_LIST(&mlhs_seq));
+ ADD_SEQ(ret, REVERSE_LIST(mlhs_seq));
if(!poped){
ADD_INSN(ret, nd_line(node), putnil);
@@ -2429,11 +2430,11 @@
*/
COMPILE(ret, "NODE_OP_ASGN1 recv", node->nd_recv);
- compile_array(self, iseqobj, &args, node->nd_args->nd_next, Qfalse);
- POP_ELEMENT(&args); POP_ELEMENT(&args);
+ compile_array(self, iseqobj, args, node->nd_args->nd_next, Qfalse);
+ POP_ELEMENT(args); POP_ELEMENT(args);
argc = node->nd_args->nd_alen - 2;
- ADD_SEQ (ret, &args);
+ ADD_SEQ (ret, args);
ADD_INSN1(ret, nd_line(node), dupn, I2F(argc+1));
ADD_SEND (ret, nd_line(node), ID2SYM(idAREF), I2F(argc));
@@ -2447,8 +2448,8 @@
nil
end
*/
- LABEL_OBJECT * label = NEW_LABEL(nd_line(node));
- LABEL_OBJECT * lfin = NEW_LABEL(nd_line(node));
+ LABEL * label = NEW_LABEL(nd_line(node));
+ LABEL * lfin = NEW_LABEL(nd_line(node));
if(id == 0){
ADD_INSN (ret, nd_line(node), dup);
@@ -2481,8 +2482,8 @@
}
case NODE_OP_ASGN2:{
ID atype = node->nd_next->nd_mid;
- LABEL_OBJECT * lfin = NEW_LABEL(nd_line(node));
- LABEL_OBJECT * lcfin = NEW_LABEL(nd_line(node));
+ LABEL * lfin = NEW_LABEL(nd_line(node));
+ LABEL * lcfin = NEW_LABEL(nd_line(node));
/*
class C; attr_accessor :c; end
r = C.new
@@ -2558,7 +2559,7 @@
}
case NODE_OP_ASGN_AND:
case NODE_OP_ASGN_OR:{
- LABEL_OBJECT * lfin = NEW_LABEL(nd_line(node));
+ LABEL * lfin = NEW_LABEL(nd_line(node));
COMPILE (ret, "NODE_OP_ASGN_AND#nd_head", node->nd_head);
ADD_INSN(ret, nd_line(node), dup);
@@ -2636,45 +2637,45 @@
/* reciever */
if(type == NODE_CALL){
- COMPILE(&recv, "recv", node->nd_recv);
+ COMPILE(recv, "recv", node->nd_recv);
}
else if(type == NODE_FCALL ||
type == NODE_VCALL){
- ADD_INSN(&recv, nd_line(node), putself);
+ ADD_INSN(recv, nd_line(node), putself);
}
/* args */
if(type != NODE_VCALL && node->nd_args){
if(nd_type(node->nd_args) == NODE_SPLAT){
- COMPILE(&args, "args(splat)", node->nd_args->nd_head);
+ COMPILE(args, "args(splat)", node->nd_args->nd_head);
argc = I2F(1);
flag |= VM_CALL_ARGS_SPLAT_BIT;
}
else if(nd_type(node->nd_args) == NODE_ARGSCAT){
- compile_array(self, iseqobj, &args, node->nd_args->nd_head, Qfalse);
- POP_ELEMENT(&args);
+ compile_array(self, iseqobj, args, node->nd_args->nd_head, Qfalse);
+ POP_ELEMENT(args);
- argc = I2F(LIST_SIZE(&args) + 1);
- COMPILE(&args, "args(cat: splat)", node->nd_args->nd_body);
+ argc = I2F(LIST_SIZE(args) + 1);
+ COMPILE(args, "args(cat: splat)", node->nd_args->nd_body);
flag |= VM_CALL_ARGS_SPLAT_BIT;
}
else{
- compile_array(self, iseqobj, &args, node->nd_args, Qfalse);
- argc = OPERAND_AT(POP_ELEMENT(&args), 0);
+ compile_array(self, iseqobj, args, node->nd_args, Qfalse);
+ argc = OPERAND_AT(POP_ELEMENT(args), 0);
}
}
else{
argc = I2F(0);
}
- ADD_SEQ(ret, &recv);
- ADD_SEQ(ret, &args);
+ ADD_SEQ(ret, recv);
+ ADD_SEQ(ret, args);
if(parent_block){
if(parent_block & 1){
flag |= VM_CALL_ARGS_BLOCKARG_BIT;
- ADD_SEQ(ret, (ISEQ_LINK_ANCHOR *)(parent_block & (~1)));
+ ADD_SEQ(ret, (LINK_ANCHOR *)(parent_block & (~1)));
}
else{
block = parent_block;
@@ -2700,22 +2701,22 @@
/* args */
if(type != NODE_VCALL && node->nd_args){
if(nd_type(node->nd_args) == NODE_SPLAT){
- COMPILE(&args, "args(splat)", node->nd_args->nd_head);
+ COMPILE(args, "args(splat)", node->nd_args->nd_head);
argc = I2F(1);
flag |= VM_CALL_ARGS_SPLAT_BIT;
}
else if(nd_type(node->nd_args) == NODE_ARGSCAT){
- compile_array(self, iseqobj, &args, node->nd_args->nd_head, Qfalse);
- POP_ELEMENT(&args);
+ compile_array(self, iseqobj, args, node->nd_args->nd_head, Qfalse);
+ POP_ELEMENT(args);
- argc = LIST_SIZE(&args) + 1;
- COMPILE(&args, "args(cat: splat)", node->nd_args->nd_body);
+ argc = LIST_SIZE(args) + 1;
+ COMPILE(args, "args(cat: splat)", node->nd_args->nd_body);
flag |= VM_CALL_ARGS_SPLAT_BIT;
}
else{
- compile_array(self, iseqobj, &args, node->nd_args, Qfalse);
- argc = OPERAND_AT(POP_ELEMENT(&args), 0);
+ compile_array(self, iseqobj, args, node->nd_args, Qfalse);
+ argc = OPERAND_AT(POP_ELEMENT(args), 0);
}
}
else{
@@ -2723,7 +2724,7 @@
}
ADD_INSN(ret, nd_line(node), putnil); /* dummy reciever */
- ADD_SEQ(ret, &args);
+ ADD_SEQ(ret, args);
ADD_INSN2(ret, nd_line(node), super, argc, I2F(flag));
if(poped){
@@ -2771,9 +2772,9 @@
switch(type){
case NODE_ARRAY:{
- compile_array(self, iseqobj, &list, node->nd_head, Qfalse);
- size = OPERAND_AT(POP_ELEMENT(&list), 0);
- ADD_SEQ (ret, &list);
+ compile_array(self, iseqobj, list, node->nd_head, Qfalse);
+ size = OPERAND_AT(POP_ELEMENT(list), 0);
+ ADD_SEQ (ret, list);
break;
}
case NODE_ZARRAY:
@@ -2833,20 +2834,20 @@
if(node->nd_head){
if(nd_type(node->nd_head) == NODE_ARRAY){
- compile_array(self, iseqobj, &args, node->nd_head, Qfalse);
- POP_ELEMENT(&args);
- argc = LIST_SIZE(&args);
+ compile_array(self, iseqobj, args, node->nd_head, Qfalse);
+ POP_ELEMENT(args);
+ argc = LIST_SIZE(args);
debugs("argc: %d\n", argc);
}
else{
- COMPILE(&args, "nd_head(1)", node->nd_head);
+ COMPILE(args, "nd_head(1)", node->nd_head);
argc = 1;
}
}
else{
argc = 0;
}
- ADD_SEQ (ret, &args);
+ ADD_SEQ (ret, args);
ADD_INSN2(ret, nd_line(node), yield, I2F(argc), I2F(0));
if(poped){
@@ -2892,8 +2893,8 @@
debugi("nd_vid", node->nd_vid);
if(!poped){
if(iseqobj->compile_data->cached_const == Qfalse){
- LABEL_OBJECT * lstart = NEW_LABEL(nd_line(node));
- LABEL_OBJECT * lend = NEW_LABEL(nd_line(node));
+ LABEL * lstart = NEW_LABEL(nd_line(node));
+ LABEL * lend = NEW_LABEL(nd_line(node));
ADD_LABEL(ret, lstart);
ADD_INSN2(ret, nd_line(node), getinlinecache, NEW_INLINE_CACHE_ENTRY(), lend);
@@ -2931,30 +2932,30 @@
DECL_ANCHOR(val);
if(nd_type(node) == NODE_MATCH){
- ADD_INSN1(&recv, nd_line(node), putobject, node->nd_lit);
- ADD_INSN2(&val, nd_line(node), getspecial, I2F(0), I2F(0));
+ ADD_INSN1(recv, nd_line(node), putobject, node->nd_lit);
+ ADD_INSN2(val, nd_line(node), getspecial, I2F(0), I2F(0));
}
else{
- COMPILE(&recv, "reciever", node->nd_recv);
- COMPILE(&val, "value", node->nd_value);
+ COMPILE(recv, "reciever", node->nd_recv);
+ COMPILE(val, "value", node->nd_value);
}
#ifdef OPT_BASIC_OPERATIONS
/* TODO: detect by node */
- if((&recv)->last == (&recv)->anchor.next &&
- INSN_OF((&recv)->last) == BIN(putobject)){
- ADD_SEQ (ret, &val);
- ADD_INSN1(ret, nd_line(node), opt_regexpmatch1, OPERAND_AT(recv.last, 0));
+ if(recv->last == recv->anchor.next &&
+ INSN_OF(recv->last) == BIN(putobject)){
+ ADD_SEQ (ret, val);
+ ADD_INSN1(ret, nd_line(node), opt_regexpmatch1, OPERAND_AT(recv->last, 0));
}
else{
- ADD_SEQ(ret, &recv);
- ADD_SEQ(ret, &val);
+ ADD_SEQ(ret, recv);
+ ADD_SEQ(ret, val);
ADD_INSN(ret, nd_line(node), opt_regexpmatch2);
}
#else
- ADD_SEQ(ret, &recv);
- ADD_SEQ(ret, &val);
+ ADD_SEQ(ret, recv);
+ ADD_SEQ(ret, val);
ADD_SEND(ret, nd_line(node), ID2SYM(idEqTilde), INT2FIX(1));
#endif
if(poped){
@@ -3083,12 +3084,12 @@
}
case NODE_BLOCK_PASS:{
VALUE prevblock = iseqobj->compile_data->current_block;
- LABEL_OBJECT * retry_label = NEW_LABEL(nd_line(node));
- LABEL_OBJECT * retry_end_l = NEW_LABEL(nd_line(node));
+ LABEL * retry_label = NEW_LABEL(nd_line(node));
+ LABEL * retry_end_l = NEW_LABEL(nd_line(node));
DECL_ANCHOR(current_block);
- iseqobj->compile_data->current_block = (VALUE)¤t_block | 1;
- COMPILE(¤t_block, "block pass proc", node->nd_body);
+ iseqobj->compile_data->current_block = (VALUE)current_block | 1;
+ COMPILE(current_block, "block pass proc", node->nd_body);
ADD_LABEL(ret, retry_label);
COMPILE_ (ret, "iter caller (NODE_BLOCK_PASS)", node->nd_iter, poped);
@@ -3201,8 +3202,8 @@
/* constant */
debugi("nd_mid", node->nd_mid);
if(iseqobj->compile_data->cached_const == Qfalse){
- LABEL_OBJECT * lstart = NEW_LABEL(nd_line(node));
- LABEL_OBJECT * lend = NEW_LABEL(nd_line(node));
+ LABEL * lstart = NEW_LABEL(nd_line(node));
+ LABEL * lend = NEW_LABEL(nd_line(node));
/* add cache insn */
iseqobj->compile_data->cached_const = Qtrue;
@@ -3234,8 +3235,8 @@
case NODE_COLON3:{
debugi("colon3#nd_mid", node->nd_mid);
if(iseqobj->compile_data->cached_const == Qfalse){
- LABEL_OBJECT * lstart = NEW_LABEL(nd_line(node));
- LABEL_OBJECT * lend = NEW_LABEL(nd_line(node));
+ LABEL * lstart = NEW_LABEL(nd_line(node));
+ LABEL * lend = NEW_LABEL(nd_line(node));
/* add cache insn */
ADD_LABEL(ret, lstart);
@@ -3276,9 +3277,9 @@
}
case NODE_FLIP2:
case NODE_FLIP3:{
- LABEL_OBJECT * lend = NEW_LABEL(nd_line(node));
- LABEL_OBJECT * lfin = NEW_LABEL(nd_line(node));
- LABEL_OBJECT * ltrue = NEW_LABEL(nd_line(node));
+ LABEL * lend = NEW_LABEL(nd_line(node));
+ LABEL * lfin = NEW_LABEL(nd_line(node));
+ LABEL * ltrue = NEW_LABEL(nd_line(node));
ADD_INSN2(ret, nd_line(node), getspecial, I2F(node->nd_cnt), I2F(0));
ADD_INSNL(ret, nd_line(node), if, lend);
@@ -3353,7 +3354,7 @@
}
case NODE_DEFINED:{
if(!poped){
- LABEL_OBJECT * lfinish = NEW_LABEL(nd_line(node));
+ LABEL * lfinish = NEW_LABEL(nd_line(node));
defined_expr(self, iseqobj, ret, node->nd_head, lfinish, Qtrue);
ADD_LABEL(ret, lfinish);
}
@@ -3401,25 +3402,25 @@
VALUE argc;
if(node->nd_args){
- compile_array(self, iseqobj, &args, node->nd_args, Qfalse);
- argc = OPERAND_AT(POP_ELEMENT(&args), 0);
+ compile_array(self, iseqobj, args, node->nd_args, Qfalse);
+ argc = OPERAND_AT(POP_ELEMENT(args), 0);
}
else{
argc = I2F(0); /* massign */
}
if(node->nd_recv == (NODE *)1){
- ADD_INSN(&recv, nd_line(node), putself);
+ ADD_INSN(recv, nd_line(node), putself);
}
else{
- COMPILE(&recv, "recv", node->nd_recv);
+ COMPILE(recv, "recv", node->nd_recv);
}
debugp_param("argc" , argc);
debugp_param("nd_mid", ID2SYM(node->nd_mid));
- ADD_SEQ(ret, &recv);
- ADD_SEQ(ret, &args);
+ ADD_SEQ(ret, recv);
+ ADD_SEQ(ret, args);
ADD_SEND(ret, nd_line(node), ID2SYM(node->nd_mid), argc);
@@ -3496,37 +3497,20 @@
}
}
-int insn_ret_num(int insn){
+static int insn_ret_num(int insn){
INSN_CHECK(insn);
return insn_stack_push_num_info[insn];
}
-/**************************************/
-/* methods of Instruction Class */
-/**************************************/
-
-
-int insn_data_length(struct insn_object *insnobj){
+static int insn_data_length(INSN *insnobj){
return insn_len(insnobj->insn_id);
}
-int insn_length(VALUE self){
- struct insn_object *insnobj;
- GetInsnVal(self, insnobj);
- return insn_data_length(insnobj);
-}
-
-unsigned long insn_data_line_no(struct insn_object *insnobj){
+static int insn_data_line_no(INSN *insnobj){
return insn_len(insnobj->line_no);
}
-unsigned long insn_line_no(VALUE self){
- struct insn_object *insnobj;
- GetInsnVal(self, insnobj);
- return insn_data_line_no(insnobj);
-}
-
-VALUE insn_data_to_s_detail(struct insn_object *insnobj){
+VALUE insn_data_to_s_detail(INSN *insnobj){
VALUE str = rb_str_new(0,0);
char buff[0x100];
@@ -3543,7 +3527,7 @@
case 'L': /* label(destination position) */
{
char buff[0x100];
- LABEL_OBJECT *lobj = (LABEL_OBJECT *)OPERAND_AT(insnobj, j);
+ LABEL *lobj = (LABEL *)OPERAND_AT(insnobj, j);
snprintf(buff, sizeof(buff), "<L%03d>", lobj->label_no);
rb_str_concat(str, rb_str_new2(buff));
break;
@@ -3580,12 +3564,6 @@
return str;
}
-VALUE insn_to_s_detail(VALUE self){
- struct insn_object *insnobj;
- GetInsnVal(self, insnobj);
- return insn_data_to_s_detail(insnobj);
-}
-
VALUE insns_name_array(){
VALUE ary = rb_ary_new();
int i;
@@ -3595,3 +3573,38 @@
return ary;
}
+void dump_disasm_list(struct iseq_link_element *link){
+ int pos = 0;
+ INSN *iobj;
+ LABEL *lobj;
+ VALUE str;
+
+ printf("-- raw disasm--------\n");
+
+ while(link){
+ switch(link->type){
+ case ISEQ_ELEMENT_INSN:{
+ iobj = (INSN*)link;
+ str = insn_data_to_s_detail(iobj);
+ printf("%04d %-65s(%4d)\n",pos, StringValueCStr(str), insn_data_line_no(iobj));
+ pos += insn_data_length(iobj);
+ break;
+ }
+ case ISEQ_ELEMENT_LABEL:{
+ lobj = (LABEL*)link;
+ printf("<L%03d>\n", lobj->label_no);
+ break;
+ }
+ case ISEQ_ELEMENT_NONE:{
+ printf("[none]\n");
+ break;
+ }
+ default:
+ /* ignore */
+ printf("%d\n", FIX2INT(link->type));
+ rb_bug("dump_disasm_list error");
+ }
+ link = link->next;
+ }
+ printf("---------------------\n");
+}
Modified: trunk/compile.h
===================================================================
--- trunk/compile.h 2005-07-01 19:20:44 UTC (rev 196)
+++ trunk/compile.h 2005-07-03 05:50:17 UTC (rev 197)
@@ -102,38 +102,38 @@
/* add an instruction */
#define ADD_INSN(seq, line, insn) \
- ADD_LINKED_LIST(seq, (struct iseq_link_element *) new_insn_body(iseqobj, line, BIN(insn), 0))
+ ADD_ELEM(seq, (LINK_ELEMENT *) new_insn_body(iseqobj, line, BIN(insn), 0))
/* add an instruction with label operand */
#define ADD_INSNL(seq, line, insn, label) \
- ADD_LINKED_LIST(seq, (struct iseq_link_element *) \
- new_insn_body(iseqobj, line, BIN(insn), 1, (VALUE)label))
+ ADD_ELEM(seq, (LINK_ELEMENT *) \
+ new_insn_body(iseqobj, line, BIN(insn), 1, (VALUE)label))
/* add an instruction with some operands (1, 2, 3, 5) */
#define ADD_INSN1(seq, line, insn, op1) \
- ADD_LINKED_LIST(seq, (struct iseq_link_element *) \
- new_insn_body(iseqobj, line, BIN(insn), 1, (VALUE)op1))
+ ADD_ELEM(seq, (LINK_ELEMENT *) \
+ new_insn_body(iseqobj, line, BIN(insn), 1, (VALUE)op1))
#define ADD_INSN2(seq, line, insn, op1, op2) \
- ADD_LINKED_LIST(seq, (struct iseq_link_element *) \
- new_insn_body(iseqobj, line, BIN(insn), 2, (VALUE)op1, (VALUE)op2))
+ ADD_ELEM(seq, (LINK_ELEMENT *) \
+ new_insn_body(iseqobj, line, BIN(insn), 2, (VALUE)op1, (VALUE)op2))
#define ADD_INSN3(seq, line, insn, op1, op2, op3) \
- ADD_LINKED_LIST(seq, (struct iseq_link_element *) \
- new_insn_body(iseqobj, line, BIN(insn), 3, (VALUE)op1, (VALUE)op2, (VALUE)op3))
+ ADD_ELEM(seq, (LINK_ELEMENT *) \
+ new_insn_body(iseqobj, line, BIN(insn), 3, (VALUE)op1, (VALUE)op2, (VALUE)op3))
/* Specific Insn factory */
#define ADD_SEND(seq, line, id, argc) \
ADD_SEND_R(seq, line, id, argc, (VALUE)Qfalse, (VALUE)I2F(0))
#define ADD_SEND_R(seq, line, id, argc, block, flag) \
- ADD_LINKED_LIST(seq, (struct iseq_link_element *) \
- new_insn_send(iseqobj, line, \
- (VALUE)id, (VALUE)argc, (VALUE)block, (VALUE)flag))
+ ADD_ELEM(seq, (LINK_ELEMENT *) \
+ new_insn_send(iseqobj, line, \
+ (VALUE)id, (VALUE)argc, (VALUE)block, (VALUE)flag))
/* add label */
#define ADD_LABEL(seq, label) \
- ADD_LINKED_LIST(seq, (struct iseq_link_element *)label)
+ ADD_ELEM(seq, (LINK_ELEMENT *)label)
#define ADD_CATCH_ENTRY(type, ls, le, iseq, sp, lc) \
(tmp = rb_ary_new(), \
@@ -161,10 +161,10 @@
iseq_compile_each(self, anchor, node, poped)))
#define OPERAND_AT(insn, idx) \
- (((INSN_OBJECT*)(insn))->operands[idx])
+ (((INSN*)(insn))->operands[idx])
#define INSN_OF(insn) \
- (((INSN_OBJECT*)(insn))->insn_id)
+ (((INSN*)(insn))->insn_id)
#define I2F(x) INT2FIX(x)
@@ -172,7 +172,7 @@
#define COMPILE_ERROR(strs) \
{ \
VALUE tmp = ruby_errinfo; \
- if(CPDEBUG)rb_bug(strs); \
+ if(CPDEBUG)rb_bug strs; \
ruby_errinfo = iseqobj->compile_data->err_info; \
rb_compile_error strs; \
iseqobj->compile_data->err_info = ruby_errinfo; \
@@ -186,7 +186,8 @@
#define COMPILE_NG 0
#define DECL_ANCHOR(name) \
- ISEQ_LINK_ANCHOR name = {{0,}, &name.anchor}
+ LINK_ANCHOR name##_body__ = {{0,}, &name##_body__.anchor}; \
+ LINK_ANCHOR *name = & name##_body__;
#endif // _COMPILER_H_INCLUDED_
Modified: trunk/disasm.c
===================================================================
--- trunk/disasm.c 2005-07-01 19:20:44 UTC (rev 196)
+++ trunk/disasm.c 2005-07-03 05:50:17 UTC (rev 197)
@@ -254,47 +254,6 @@
return str;
}
-/**
- * raw dump
- */
-VALUE iseq_disasm_list_dump(struct iseq_link_element *link){
- int pos = 0;
- struct insn_object *iobj;
- struct label_object *lobj;
- VALUE str;
-
- printf("-- raw disasm--------\n");
-
- while(link){
- switch(link->type){
- case ISEQ_ELEMENT_INSN:{
- iobj = (struct insn_object*)link;
- str = insn_data_to_s_detail(iobj);
- printf("%04d %-65s(%4d)\n",pos, StringValueCStr(str), insn_data_line_no(iobj));
- pos += insn_data_length(iobj);
- break;
- }
- case ISEQ_ELEMENT_LABEL:{
- lobj = (struct label_object*)link;
- printf("<L%03d>\n", lobj->label_no);
- break;
- }
- case ISEQ_ELEMENT_NONE:{
- printf("[none]\n");
- break;
- }
- default:
- /* ignore */
- printf("%d\n", FIX2INT(link->type));
- rb_bug("iseq_disasm_list_dump error");
- }
- link = link->next;
- }
- printf("---------------------\n");
- return Qtrue;
-}
-
-
/*
node.h
$Date: 2004/05/07 08:44:14 $
Modified: trunk/insns.def
===================================================================
--- trunk/insns.def 2005-07-01 19:20:44 UTC (rev 196)
+++ trunk/insns.def 2005-07-03 05:50:17 UTC (rev 197)
@@ -1103,7 +1103,6 @@
(VALUE val)
{
NODE *mn;
- int i;
VALUE recv;
VALUE procblock = 0; /* block arg */
VALUE klass;
Modified: trunk/opt_operand.def
===================================================================
--- trunk/opt_operand.def 2005-07-01 19:20:44 UTC (rev 196)
+++ trunk/opt_operand.def 2005-07-03 05:50:17 UTC (rev 197)
@@ -21,7 +21,6 @@
putobject Qfalse
end 5
-__END__
send *, *, Qfalse, 0, *
send *, 0, Qfalse, 0, *
send *, 1, Qfalse, 0, *
Modified: trunk/rb/yasm.rb
===================================================================
--- trunk/rb/yasm.rb 2005-07-01 19:20:44 UTC (rev 196)
+++ trunk/rb/yasm.rb 2005-07-03 05:50:17 UTC (rev 197)
@@ -1,6 +1,7 @@
#
# YASM: YARV Assembler
#
+raise "YASM is currently not supported"
=begin
@@ -78,6 +79,7 @@
# 3.times{|i|
# p a
# }
+# end
m4 = yasm.method(:m4, :a){|x|
x.putobject 3
x.send :times, 0, x.block(:i){|y|
@@ -121,6 +123,25 @@
x.end
}
+top = yasm.top{|x|
+ x.methoddef(:m1, :a){|y|
+ y.putself
+ y.getlocal :a
+ y.send :p, 1
+ y.end
+ }
+ x.putself
+ x.putobject 1
+ x.send :m1, 1
+ x.end
+}
+
+top = yasm.top{|x|
+ x.putself
+ x.putobject 1
+ x.send :p, 1
+}
+
#=> run
YARVCore::eval_parsed(top)
Modified: trunk/test.rb
===================================================================
--- trunk/test.rb 2005-07-01 19:20:44 UTC (rev 196)
+++ trunk/test.rb 2005-07-03 05:50:17 UTC (rev 197)
@@ -9,49 +9,7 @@
###########################################################
$prog =<<'__EOP__'
-n = 60 #Integer(ARGV.shift || 1)
-size = 30
-
-def mkmatrix(rows, cols)
- count = 1
- mx = Array.new(rows)
- (0 .. (rows - 1)).each do |bi|
- row = Array.new(cols, 0)
- (0 .. (cols - 1)).each do |j|
- row[j] = count
- count += 1
- end
- mx[bi] = row
- end
- mx
-end
-
-def mmult(rows, cols, m1, m2)
- m3 = Array.new(rows)
- (0 .. (rows - 1)).each do |bi|
- row = Array.new(cols, 0)
- (0 .. (cols - 1)).each do |j|
- val = 0
- (0 .. (cols - 1)).each do |k|
- val += m1.at(bi).at(k) * m2.at(k).at(j)
- end
- row[j] = val
- end
- m3[bi] = row
- end
- m3
-end
-
-m1 = mkmatrix(size, size)
-m2 = mkmatrix(size, size)
-mm = Array.new
-
-n.times do
- mm = mmult(size, size, m1, m2)
-end
-# puts "#{mm[0][0]} #{mm[2][3]} #{mm[3][2]} #{mm[4][4]}"
-
__EOP__
###########################################################
Modified: trunk/tmpl/optinsn.inc.tmpl
===================================================================
--- trunk/tmpl/optinsn.inc.tmpl 2005-07-01 19:20:44 UTC (rev 196)
+++ trunk/tmpl/optinsn.inc.tmpl 2005-07-03 05:50:17 UTC (rev 197)
@@ -12,7 +12,7 @@
or rb/insns2vm.rb
*/
-static INSN_OBJECT *insn_optimize(INSN_OBJECT *insnobj){
+static INSN *insn_optimize(INSN *insnobj){
#ifdef OPT_OPERANDS_UNIFICATION
/* optimize rule */
switch(insnobj->insn_id){
Modified: trunk/yarvcore.c
===================================================================
--- trunk/yarvcore.c 2005-07-01 19:20:44 UTC (rev 196)
+++ trunk/yarvcore.c 2005-07-03 05:50:17 UTC (rev 197)
@@ -15,8 +15,6 @@
VALUE mYarvCore;
VALUE cYarvISeq;
-VALUE cYarvInsn;
-VALUE cYarvLabel;
VALUE cYarvVM;
VALUE cYarvThread;
VALUE mYarvInsns;
@@ -246,12 +244,6 @@
return iseq;
}
-static void yarv_free(void *ptr){
- if(ptr){
- ruby_xfree(ptr);
- }
-}
-
VALUE iseq_jitcompile(VALUE iseq);
static VALUE yarv_jitcompile(VALUE self, VALUE obj, VALUE selector){
if(IS_YARV_WORKING()){
@@ -340,12 +332,9 @@
return obj;
}
-static VALUE iseq_init(VALUE self, VALUE node, VALUE name, VALUE file_name,
- VALUE parent, VALUE type){
- struct iseq_object *iseqobj;
- VALUE err;
-
- GetISeqVal(self, iseqobj);
+static VALUE prepare_iseq_build(struct iseq_object *iseqobj,
+ VALUE name, VALUE file_name,
+ VALUE parent, VALUE type){
iseqobj->name = name;
iseqobj->file_name = file_name;
iseqobj->iseq_mark_ary = rb_ary_new();
@@ -373,11 +362,11 @@
GetISeqVal(parent, piseqobj);
iseqobj->parent_iseqobj = piseqobj;
}
-
- iseq_compile(self, node);
-
+ return Qtrue;
+}
+static VALUE cleanup_iseq_build(struct iseq_object *iseqobj){
+ VALUE err;
err = iseqobj->compile_data->err_info;
-
compile_data_free(iseqobj->compile_data);
iseqobj->compile_data = 0;
@@ -385,7 +374,19 @@
ruby_nerrs = 0;
rb_exc_raise(err);
}
+ return Qtrue;
+}
+
+static VALUE iseq_init(VALUE self, VALUE node, VALUE name, VALUE file_name,
+ VALUE parent, VALUE type){
+ struct iseq_object *iseqobj;
+ GetISeqVal(self, iseqobj);
+
+ prepare_iseq_build(iseqobj, name, file_name, parent, type);
+ iseq_compile(self, node);
+ cleanup_iseq_build(iseqobj);
+
return self;
}
@@ -407,115 +408,6 @@
return rb_str_new2(buff);
}
-VALUE iseq_insns(VALUE self){
- struct iseq_object *iseqobj;
- GetISeqVal(self, iseqobj);
- return Qnil;
- // return iseqobj->insns_ary;
-}
-
-
-/*********/
-/* Label */
-/*********/
-
-static VALUE label_alloc(VALUE klass){
- VALUE obj;
- struct label_object *labelobj;
-
- obj = Data_Make_Struct(klass, struct label_object, 0, yarv_free, labelobj);
- return obj;
-}
-
-static VALUE label_init(VALUE self, VALUE label_no){
- struct label_object *labelobj;
- Data_Get_Struct(self, struct label_object, labelobj);
- labelobj->link.type = ISEQ_ELEMENT_LABEL;
- labelobj->link.next = 0;
- labelobj->label_no = label_no;
- labelobj->sc_state = 0;
- return self;
-}
-
-static VALUE label_to_s(VALUE self){
- struct label_object *lobj;
- char buff[0x100];
-
- GetLabelVal(self, lobj);
- snprintf(buff, sizeof(buff), "<L%03d>", lobj->label_no);
- return rb_str_new2(buff);
-}
-
-static VALUE label_position(VALUE self){
- struct label_object *lobj;
- GetLabelVal(self, lobj);
-
- return INT2FIX(lobj->position);
-}
-
-/***************/
-/* Instruction */
-/***************/
-
-static void insn_mark(void *ptr){
- struct insn_object *insnobj;
- if(ptr){
- insnobj = ptr;
- }
-}
-
-static VALUE insn_alloc(VALUE klass){
- VALUE obj;
- struct insn_object *insnobj;
-
- obj = Data_Make_Struct(klass, struct insn_object, insn_mark, yarv_free, insnobj);
- return obj;
-}
-
-static VALUE insn_init(VALUE self, int insn_id, int line_no, VALUE operands){
- rb_bug("unsuppoted");
- return self;
-}
-
-static VALUE insn_make(VALUE self, VALUE insn_id, VALUE line_no, VALUE operands){
- VALUE args[3];
- args[0] = FIX2INT(insn_id);
- args[1] = FIX2INT(line_no);
- args[2] = RARRAY(operands)->len == 0 ? 0 : operands;
-
- return rb_class_new_instance(3, args, cYarvInsn);
-}
-
-static VALUE insn_to_s(VALUE self){
- struct insn_object *insnobj;
- char buff[0x100];
-
- GetInsnVal(self, insnobj);
- snprintf(buff, sizeof(buff),
- "<Insn:%s (%d)>", insn_name(insnobj->insn_id), (int)insnobj->line_no);
-
- return rb_str_new2(buff);
-}
-
-
-static VALUE insn_insn_id(VALUE self){
- struct insn_object *insnobj;
- GetInsnVal(self, insnobj);
-
- return INT2FIX(insnobj->insn_id);
-}
-
-static VALUE insn_line_no(VALUE self){
- struct insn_object *insnobj;
- GetInsnVal(self, insnobj);
- return INT2FIX(insnobj->line_no);
-}
-
-static VALUE insn_operands(VALUE self){
- return Qnil;
-}
-
-
/******/
/* VM */
/******/
@@ -805,28 +697,9 @@
rb_define_method(cYarvISeq, "initialize", iseq_init, 5);
rb_define_method(cYarvISeq, "inspect", iseq_inspect, 0);
rb_define_method(cYarvISeq, "disasm", iseq_disasm, 0);
- rb_define_method(cYarvISeq, "insns", iseq_insns, 0);
rb_define_method(cYarvISeq, "assemble", iseq_assemble, 3);
// rb_define_singleton_method(cYarvISeq, "new_from_insn_ary", iseq_init_from_insn_ary, 1);
-
- /* declare YARVCore::InstructionSequence::Instruction */
- cYarvInsn = rb_define_class_under(cYarvISeq, "Instruction", rb_cObject);
- rb_define_alloc_func(cYarvInsn, insn_alloc);
- rb_define_method(cYarvInsn, "initialize", insn_init, 3);
- rb_define_method(cYarvInsn, "to_s", insn_to_s, 0);
- rb_define_method(cYarvInsn, "inspect", insn_to_s, 0);
- rb_define_method(cYarvInsn, "insn_id", insn_insn_id, 0);
- rb_define_method(cYarvInsn, "line_no", insn_line_no, 0);
- rb_define_method(cYarvInsn, "operands", insn_operands, 0);
- rb_define_singleton_method(cYarvInsn, "make", insn_make, 3);
- /* declare YARVCore::InstructionSequence::Label */
- cYarvLabel = rb_define_class_under(cYarvISeq, "Label", rb_cObject);
- rb_define_alloc_func(cYarvLabel, label_alloc);
- rb_define_method(cYarvLabel, "initialize", label_init, 1);
- rb_define_method(cYarvLabel, "to_s", label_to_s, 0);
- rb_define_method(cYarvLabel, "inspect", label_to_s, 0);
- rb_define_method(cYarvLabel, "position", label_position, 0);
/* declare YARVCore::VM */
cYarvVM = rb_define_class_under(mYarvCore, "VM", rb_cObject);
rb_define_alloc_func(cYarvVM, vm_alloc);
@@ -855,9 +728,9 @@
/* declare YARVCore::ThrowObject */
cYarvThrowObject = rb_define_class_under(mYarvCore, "ThrowObject", rb_cObject);
- /* declare YARVCore::Instructions */
- mYarvInsns = rb_define_module_under(mYarvCore, "Instructions");
+ /* YARV test functions */
+
rb_define_global_function("once", yarv_once, 0);
rb_define_global_function("cfunc", cfunc, 0);
rb_define_global_function("yarv_caller", yarv_caller, 1);
Modified: trunk/yarvcore.h
===================================================================
--- trunk/yarvcore.h 2005-07-01 19:20:44 UTC (rev 196)
+++ trunk/yarvcore.h 2005-07-03 05:50:17 UTC (rev 197)
@@ -12,8 +12,6 @@
/* classes and modules */
extern VALUE mYarvCore;
extern VALUE cYarvISeq;
-extern VALUE cYarvInsn;
-extern VALUE cYarvLabel;
extern VALUE cYarvVM;
extern VALUE cYarvThread;
extern VALUE mYarvInsns;
@@ -42,53 +40,8 @@
extern ID idMethodMissing;
extern ID idEach;
-
extern unsigned long yarvGlobalStateVersion;
-
-/* internal structure */
-
-#define GetLabelVal(obj, lobj) \
- Data_Get_Struct(obj, struct label_object, lobj)
-
-
-#define ISEQ_ELEMENT_NONE INT2FIX(0x00)
-#define ISEQ_ELEMENT_LABEL INT2FIX(0x01)
-#define ISEQ_ELEMENT_INSN INT2FIX(0x02)
-#define ISEQ_ELEMENT_SEQ INT2FIX(0x03)
-
-typedef struct iseq_link_element{
- int type;
- struct iseq_link_element *next;
- struct iseq_link_element *prev;
-} ISEQ_LINK_ELEMENT;
-
-
-typedef struct label_object{
- struct iseq_link_element link;
- int label_no;
- long position;
- unsigned long sc_state;
- VALUE set;
-} LABEL_OBJECT;
-
-
-#define GetInsnVal(obj, iobj) \
- Data_Get_Struct(obj, struct insn_object, iobj)
-
-typedef struct insn_object{
- struct iseq_link_element link;
- int insn_id;
- unsigned long line_no;
- VALUE *operands;
- unsigned int operand_size;
- unsigned int sc_state;
-} INSN_OBJECT;
-
-
-#define GetISeqVal(obj, tobj) \
- Data_Get_Struct(obj, struct iseq_object, tobj)
-
struct insn_info_struct{
unsigned short position;
unsigned short line_no;
@@ -123,20 +76,15 @@
char *buff;
};
-typedef struct iseq_link_anchor{
- ISEQ_LINK_ELEMENT anchor;
- ISEQ_LINK_ELEMENT *last;
-} ISEQ_LINK_ANCHOR;
-
struct iseq_compile_data{
/* GC is needed */
VALUE err_info;
VALUE mark_ary;
/* GC is not needed */
- LABEL_OBJECT* start_label;
- LABEL_OBJECT* end_label;
- LABEL_OBJECT* redo_label;
+ struct iseq_label_data* start_label;
+ struct iseq_label_data* end_label;
+ struct iseq_label_data* redo_label;
VALUE current_block;
VALUE loopval_popped; /* used by NODE_BREAK */
VALUE in_ensure; /* used by NODE_RETURN */
@@ -146,6 +94,9 @@
struct iseq_compile_data_storage *storage_current;
};
+#define GetISeqVal(obj, tobj) \
+ Data_Get_Struct(obj, struct iseq_object, tobj)
+
struct iseq_object{
VALUE name; /* String: iseq name */
VALUE *iseq; /* iseq */
--
ML: yarv-diff quickml.atdot.net
Info: http://www.atdot.net/~ko1/quickml