[前][次][番号順一覧][スレッド一覧][生データ]

yarv-diff:19

From: ko1 atdot.net
Date: 27 Jun 2005 11:09:34 -0000
Subject: [yarv-diff:19] r174 - in trunk: . test

Author: ko1
Date: 2005-06-27 20:09:33 +0900 (Mon, 27 Jun 2005)
New Revision: 174

Added:
   trunk/vm_dump.c
   trunk/vm_evalbody.h
Removed:
   trunk/vm_evalbody.inc
Modified:
   trunk/ChangeLog
   trunk/compile.c
   trunk/compile.h
   trunk/debug.h
   trunk/depend
   trunk/disasm.c
   trunk/insnhelper.h
   trunk/insns.def
   trunk/test/test_bin.rb
   trunk/vm.c
   trunk/vm.h
   trunk/yarvcore.c
Log:
	* yarvcore.c, compile.c, disasm.c : remove unused variables

	* vm.h, insnhelper.h, debug.h : fix to reduce warning

	* vm.c, vm_dump.c : move VM state dump (debug) functions to vm_dump.c

	* depend : adde reconf rule

	* insnhelper.h : 

	* vm_evalbody.inc : rename to vm_evalbody.h



Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2005-06-27 07:55:26 UTC (rev 173)
+++ trunk/ChangeLog	2005-06-27 11:09:33 UTC (rev 174)
@@ -4,6 +4,22 @@
 #  from Mon, 03 May 2004 01:24:19 +0900
 #
 
+2005-06-27(Mon) 20:04:10 +0900
+
+	* yarvcore.c, compile.c, disasm.c : remove unused variables
+
+	* vm.h, insnhelper.h, debug.h : fix to reduce warning
+
+	* vm.c, vm_dump.c : move VM state dump (debug) functions to vm_dump.c
+
+	* depend : adde reconf rule
+
+	* insnhelper.h : 
+
+	* vm_evalbody.inc : rename to vm_evalbody.h
+
+	
+
 2005-06-27(Mon) 16:50:31 +0900  Koichi Sasada  <ko1 atdot.net>
 
 	* insns2vm.rb : fix generating unif insn

Modified: trunk/compile.c
===================================================================
--- trunk/compile.c	2005-06-27 07:55:26 UTC (rev 173)
+++ trunk/compile.c	2005-06-27 11:09:33 UTC (rev 174)
@@ -25,10 +25,13 @@
 
 
 /* for debug */
+#if CPDEBUG > 0
 static long gl_node_level = 0;
 static long gl_tmp = 0;
 static void debug_list(ISEQ_LINK_ANCHOR *anchor);
+#endif
 
+void iseq_disasm_list_dump(ISEQ_LINK_ELEMENT* elem);
 
 static void ADD_LINKED_LIST(ISEQ_LINK_ANCHOR *anchor, ISEQ_LINK_ELEMENT* elem);
 
@@ -59,7 +62,6 @@
 
 VALUE iseq_compile(VALUE self, VALUE narg){
   DECL_ANCHOR(list_anchor);
-  VALUE tmp;
   struct iseq_object *iseqobj;
   NODE *node = (NODE*)narg;
 
@@ -205,7 +207,7 @@
 static int iseq_translate_direct_threaded_code(struct iseq_object *iseqobj){
 #ifdef DISPATCH_DIRECT_THREADED_CODE
   void **table = (void **)thread_eval_body(0);
-  int i, len;
+  int i;
   
   iseqobj->iseq_dt = ALLOC_N(VALUE, iseqobj->size);
   MEMCPY(iseqobj->iseq_dt, iseqobj->iseq, VALUE, iseqobj->size);
@@ -298,6 +300,8 @@
   verify_list("add", anchor);
 }
 
+/*******************************************/
+#if 0
 /*
  * elem1, elemX => elem1, elem2, elemX
  */
@@ -323,6 +327,8 @@
     elem2->prev->next = elem2;
   }
 }
+#endif
+/*******************************************/
 
 /*
  * elemX, elem1, elemY => elemX, elem2, elemY
@@ -802,7 +808,6 @@
 
     /* optional initializer */
     if(node->nd_opt){
-      int oargs = 0;
       NODE* optarg = node->nd_opt;
       LABEL_OBJECT* label;
       VALUE labels = rb_ary_new();
@@ -871,16 +876,6 @@
   return COMPILE_OK;
 }
 
-static int next_instruction_position(VALUE self, struct RArray *ary, int pos){
-  int i;
-  for(i=pos+1; i<ary->len; i++){
-    if(CLASS_OF(ary->ptr[i]) == cYarvInsn){
-      return i;
-    }
-  }
-  return -1;
-}
-
 /**
   ruby insn object array -> raw instruction sequence
  */
@@ -978,7 +973,6 @@
           VALUE map  = rb_hash_new();
 
           for(i=0; i<RARRAY(lits)->len; i++){
-            int offset;
             VALUE pair = RARRAY(lits)->ptr[i];
             lobj = (LABEL_OBJECT *)(RARRAY(pair)->ptr[1] & ~1);
             
@@ -1214,7 +1208,7 @@
 
 static INSN_OBJECT* new_unified_insn(struct iseq_object *iseqobj,
                                      int insn_id, int size, ISEQ_LINK_ELEMENT *seq_list){
-  INSN_OBJECT *iobj;
+  INSN_OBJECT *iobj = 0;
   ISEQ_LINK_ELEMENT *list = seq_list;
   int i, argc = 0;
   VALUE *operands = 0, *ptr = 0;
@@ -1253,7 +1247,7 @@
 #ifdef OPT_INSNS_UNIFICATION
   ISEQ_LINK_ELEMENT *list;
   struct insn_object *iobj, *niobj;
-  int id, j, k, insn;
+  int id, j, k;
   
   list = FIRST_ELEMENT(anchor);
   while(list){
@@ -1356,8 +1350,7 @@
 static int set_sequence_stackcaching(struct iseq_object *iseqobj, ISEQ_LINK_ANCHOR *anchor){
 #ifdef OPT_STACK_CACHING
   ISEQ_LINK_ELEMENT *list;
-  int i, state, insn_id;
-  unsigned long size;
+  int state, insn_id;
 
   /* initialize */
   state = SCS_XX;
@@ -1445,7 +1438,6 @@
 int compile_dstr(VALUE self, struct iseq_object *iseqobj, ISEQ_LINK_ANCHOR *ret, NODE *node){
   NODE *list = node->nd_next;
   VALUE lit  = node->nd_lit;
-  VALUE tmp;
   int cnt = 0;
 
   debugp_param("nd_lit", lit);
@@ -1524,8 +1516,7 @@
 static int compile_array(VALUE self, struct iseq_object *iseqobj,
                          ISEQ_LINK_ANCHOR *ret, NODE *node_root, VALUE opt_p){
   NODE *node = node_root;
-  VALUE obj, tmp;
-  int i, len = node->nd_alen, line = nd_line(node);
+  int len = node->nd_alen, line = nd_line(node);
   DECL_ANCHOR(anchor);
   
   while(node){
@@ -1575,7 +1566,6 @@
   switch(nd_type(node)){
   case NODE_ATTRASGN:{
     struct insn_object *iobj;
-    VALUE sendinsn;// = rb_ary_pop(lhs);
     VALUE dupidx;
 
     COMPILE(ret, "masgn lhs (NODE_ATTRASGN)", node);
@@ -1727,10 +1717,8 @@
  */
 static int iseq_compile_each(VALUE self, ISEQ_LINK_ANCHOR *ret, NODE* node, int poped){
   VALUE tmp; /* reserved for macro */
-  NODE *n = node;
-  VALUE args[10];
   
-  int lv, type;
+  int type;
   struct iseq_object *iseqobj;
 
   GetISeqVal(self, iseqobj);
@@ -2778,12 +2766,11 @@
   }
   case NODE_HASH:{
     DECL_ANCHOR(list);
-    VALUE size;
+    VALUE size = 0;
     int type = node->nd_head ? nd_type(node->nd_head) : NODE_ZARRAY;
     
     switch(type){
     case NODE_ARRAY:{
-      VALUE iary;
       compile_array(self, iseqobj, &list, node->nd_head, Qfalse);
       size = OPERAND_AT(POP_ELEMENT(&list), 0);
       ADD_SEQ  (ret, &list);
@@ -2990,7 +2977,7 @@
     break;
   }
   case NODE_DSTR:{
-    VALUE dstr = compile_dstr(self, iseqobj, ret, node);
+    compile_dstr(self, iseqobj, ret, node);
     
     if(poped){
       ADD_INSN(ret, nd_line(node), pop);
@@ -3292,7 +3279,6 @@
     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_OBJECT * lfalse = 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);
@@ -3542,7 +3528,6 @@
 
 VALUE insn_data_to_s_detail(struct insn_object *insnobj){
   VALUE str = rb_str_new(0,0);
-  VALUE tmp;
   char buff[0x100];
 
   snprintf(buff, sizeof(buff), "%-16s", insn_name(insnobj->insn_id));

Modified: trunk/compile.h
===================================================================
--- trunk/compile.h	2005-06-27 07:55:26 UTC (rev 173)
+++ trunk/compile.h	2005-06-27 11:09:33 UTC (rev 174)
@@ -61,17 +61,26 @@
 #define debug_nodeprint_close()  gl_node_level --;
 
 #define debugs debug_indent(-1, CPDEBUG, gl_node_level*2), printf
+#define debug_compile(msg, v) (debug_indent(-1, CPDEBUG, gl_node_level*2), printf("%s", msg), (v))
 
 #else
 
-#define debugp(header, value)              value
-#define debugi(header, id)                 id
-#define debugp_verbose(header, value)      value
-#define debugp_verbose_node(header, value) value
-#define debugp_param(header, value)        value
+static inline ID r_id(id){
+  return id;
+}
+static inline VALUE r_value(value){
+  return value;
+}
+
+#define debugi(header, id)                 r_id(id)
+#define debugp(header, value)              r_value(value)
+#define debugp_verbose(header, value)      r_value(value)
+#define debugp_verbose_node(header, value) r_value(value)
+#define debugp_param(header, value)        r_value(value)
 #define debug_nodeprint(node)
 #define debug_nodeprint_close()
-#define debugs 
+#define debugs                             if(0)printf
+#define debug_compile(msg, v) (v)
 #endif
 
 
@@ -138,18 +147,18 @@
 
 /* compile node */
 #define COMPILE(anchor, desc, node) \
-  (debugs("== " desc "\n"), \
-   iseq_compile_each(self, anchor, node, 0))
+  (debug_compile("== " desc "\n", \
+                 iseq_compile_each(self, anchor, node, 0)))
 
 /* compile node, this node's value will be poped */
 #define COMPILE_POPED(anchor, desc, node)    \
-  (debugs("== " desc "\n"),          \
-   iseq_compile_each(self, anchor, node, 1))
+  (debug_compile("== " desc "\n", \
+                 iseq_compile_each(self, anchor, node, 1)))
 
 /* compile node, which is poped when 'poped' is true */
 #define COMPILE_(anchor, desc, node, poped)  \
-  (debugs("== " desc "\n"),          \
-   iseq_compile_each(self, anchor, node, poped))
+  (debug_compile("== " desc "\n", \
+                 iseq_compile_each(self, anchor, node, poped)))
 
 #define OPERAND_AT(insn, idx) \
   (((INSN_OBJECT*)(insn))->operands[idx])

Modified: trunk/debug.h
===================================================================
--- trunk/debug.h	2005-06-27 07:55:26 UTC (rev 173)
+++ trunk/debug.h	2005-06-27 11:09:33 UTC (rev 174)
@@ -34,7 +34,7 @@
 
 #else
 
-#define GC_CHECK() 0
+#define GC_CHECK() 
 
 #endif
 

Modified: trunk/depend
===================================================================
--- trunk/depend	2005-06-27 07:55:26 UTC (rev 173)
+++ trunk/depend	2005-06-27 11:09:33 UTC (rev 174)
@@ -1,6 +1,6 @@
 compile.o:   compile.c yarvcore.h compile.h version.h debug.h insns.inc insns_info.inc optinsn.inc opt_sc.inc optunifs.inc
 disasm.o:    disasm.c yarvcore.h version.h debug.h
-vm.o:        vm.c vm.h version.h insnhelper.h insns.inc yarvcore.h debug.h vm.inc vmtc.inc $(srcdir)/vm_evalbody.inc
+vm.o:        vm.c vm.h version.h insnhelper.h insns.inc yarvcore.h debug.h vm.inc vmtc.inc $(srcdir)/vm_evalbody.h
 yarvcore.o:  yarvcore.c yarvcore.h version.h debug.h rev.inc
 debug.o:     debug.h
 yarvsubst.o: yarv.h
@@ -80,3 +80,6 @@
 yasm: yasmdata.rb all
 	$(RUBY) -I$(srcdir) $(srcdir)/yasmtest.rb
 
+reconf:
+	make clean
+	$(RUBY) $(srcdir)/extconf.rb

Modified: trunk/disasm.c
===================================================================
--- trunk/disasm.c	2005-06-27 07:55:26 UTC (rev 173)
+++ trunk/disasm.c	2005-06-27 11:09:33 UTC (rev 174)
@@ -53,7 +53,7 @@
 
   switch(type){
   case 'L': /* LONG */
-    snprintf(buff, sizeof(buff), "%d", pos + len + op);
+    snprintf(buff, sizeof(buff), "%d", (int)pos + len + op);
     ret = rb_str_new2(buff);
     break;
 
@@ -103,9 +103,7 @@
                        struct iseq_object *iseqobj, VALUE child){
   int insn = iseq[pos];
   int len  = insn_len(insn);
-  int slen = 0;
   int i, j;
-  long idx;
   char *types = insn_op_types(insn);
   VALUE str = rb_str_new(0, 0);
   char buff[0x100];
@@ -166,8 +164,7 @@
   VALUE str = rb_str_new(0, 0);
   VALUE child = rb_ary_new();
   unsigned long size;
-  int i,j;
-  long idx;
+  int i;
   ID *tbl;
   char buff[0x200];
 
@@ -191,7 +188,7 @@
   for(i=0; i<iseqobj->catch_table_size; i++){
     struct catch_table_entry *entry = &iseqobj->catch_table[i];
     sprintf(buff, "|type: %02d, st: %04d, ed: %04d, sp: %04d, cont: %04d\n",
-            entry->type, entry->start, entry->end, entry->sp, entry->cont);
+            (int)entry->type, (int)entry->start, (int)entry->end, (int)entry->sp, (int)entry->cont);
     rb_str_cat2(str, buff);
     if(entry->iseq){
       rb_str_concat(str, iseq_disasm(entry->iseq));

Modified: trunk/insnhelper.h
===================================================================
--- trunk/insnhelper.h	2005-06-27 07:55:26 UTC (rev 173)
+++ trunk/insnhelper.h	2005-06-27 11:09:33 UTC (rev 174)
@@ -42,12 +42,20 @@
 
 #define RESTORE_REGS()       (0)
 
+#ifdef COLLECT_USAGE_ANALYSIS
+#define USAGE_ANALYSIS_REGISTER_HELPER(a, b, v) \
+  (USAGE_ANALYSIS_REGISTER(a, b), (v))
+#else
+#define USAGE_ANALYSIS_REGISTER_HELPER(a, b, v) \
+  (v)
+#endif
+
 /* PC */
-#define GET_PC()           (USAGE_ANALYSIS_REGISTER(0, 0), REG_PC)
-#define SET_PC(x)          (REG_PC = (USAGE_ANALYSIS_REGISTER(0, 1), (x)))
+#define GET_PC()           (USAGE_ANALYSIS_REGISTER_HELPER(0, 0, REG_PC))
+#define SET_PC(x)          (REG_PC = (USAGE_ANALYSIS_REGISTER_HELPER(0, 1, x)))
 #define GET_CURRENT_INSN() (*GET_PC())
 #define GET_OPERAND(n)     (GET_PC()[(n)])
-#define ADD_PC(n)          (SET_PC(REG_PC += (n)))
+#define ADD_PC(n)          (SET_PC(REG_PC + (n)))
 
 #ifdef DISPATCH_DIRECT_THREADED_CODE
 #define GET_PC_COUNT()     (REG_PC - GET_ISEQ()->iseq_dt)
@@ -59,20 +67,20 @@
 
 
 /* FP */
-#define GET_CFP()  (USAGE_ANALYSIS_REGISTER(2, 0), REG_CFP)
-#define SET_CFP(x) (th->cfp = REG_CFP = (USAGE_ANALYSIS_REGISTER(2, 1), (x)))
-#define GET_LFP()  (USAGE_ANALYSIS_REGISTER(3, 0), REG_LFP)
-#define SET_LFP(x) (th->lfp = REG_LFP = (USAGE_ANALYSIS_REGISTER(3, 1), (x)))
-#define GET_DFP()  (USAGE_ANALYSIS_REGISTER(4, 0), REG_DFP)
-#define SET_DFP(x) (th->dfp = REG_DFP = (USAGE_ANALYSIS_REGISTER(4, 1), (x)))
+#define GET_CFP()  (USAGE_ANALYSIS_REGISTER_HELPER(2, 0, REG_CFP))
+#define SET_CFP(x) (th->cfp = REG_CFP = (USAGE_ANALYSIS_REGISTER_HELPER(2, 1, (x))))
+#define GET_LFP()  (USAGE_ANALYSIS_REGISTER_HELPER(3, 0, REG_LFP))
+#define SET_LFP(x) (th->lfp = REG_LFP = (USAGE_ANALYSIS_REGISTER_HELPER(3, 1, (x))))
+#define GET_DFP()  (USAGE_ANALYSIS_REGISTER_HELPER(4, 0, REG_DFP))
+#define SET_DFP(x) (th->dfp = REG_DFP = (USAGE_ANALYSIS_REGISTER_HELPER(4, 1, (x))))
 
 #define GET_CONTINUATION_FRAME_PTR(cfp) \
   ((struct continuation_frame *)((cfp) + CC_DIFF_WC()))
 
 /* SP */
-#define GET_SP()   (USAGE_ANALYSIS_REGISTER(1, 0), REG_SP)
-#define SET_SP(x)  (th->sp = REG_SP  = (USAGE_ANALYSIS_REGISTER(1, 1), (x)))
-#define INC_SP(x)  (th->sp = REG_SP += (USAGE_ANALYSIS_REGISTER(1, 1), (x)))
+#define GET_SP()   (USAGE_ANALYSIS_REGISTER_HELPER(1, 0, REG_SP))
+#define SET_SP(x)  (th->sp = REG_SP  = (USAGE_ANALYSIS_REGISTER_HELPER(1, 1, (x))))
+#define INC_SP(x)  (th->sp = REG_SP += (int)(USAGE_ANALYSIS_REGISTER_HELPER(1, 1, (VALUE*)(x))))
 #define SET_SV(x)  (*GET_SP() = (x))
   /* set current stack value as x */
 
@@ -81,9 +89,9 @@
 
 
 /* instruction sequence C struct */
-#define GET_ISEQOBJ(cfp) (USAGE_ANALYSIS_REGISTER(6, 0), *((cfp) + 1))
-#define GET_ISEQ()       (USAGE_ANALYSIS_REGISTER(6, 0), \
-                          (struct iseq_object*)DATA_PTR(*(GET_CFP() + 1)))
+#define GET_ISEQOBJ(cfp) (USAGE_ANALYSIS_REGISTER_HELPER(6, 0, *((cfp) + 1)))
+#define GET_ISEQ()       (USAGE_ANALYSIS_REGISTER_HELPER(6, 0, \
+                          (struct iseq_object*)DATA_PTR(*(GET_CFP() + 1))))
 
 #define CLEAR_ENV(env) (GET_ENV_CTRL(env)->is_orphan = Qundef)
 
@@ -113,7 +121,7 @@
 /* deal with values                                       */
 /**********************************************************/
 
-#define GET_SELF() (USAGE_ANALYSIS_REGISTER(5, 0), *GET_CFP())
+#define GET_SELF() (USAGE_ANALYSIS_REGISTER_HELPER(5, 0, *GET_CFP()))
 
 
 /**********************************************************/

Modified: trunk/insns.def
===================================================================
--- trunk/insns.def	2005-06-27 07:55:26 UTC (rev 173)
+++ trunk/insns.def	2005-06-27 11:09:33 UTC (rev 174)
@@ -270,7 +270,7 @@
 (VALUE klass)
 (VALUE val)
 {
-  val = thread_get_ev_const(self, th, GET_ISEQ(), klass, id);
+  val = eval_get_ev_const(th, GET_ISEQ(), klass, id);
 }
 
 /**
@@ -403,9 +403,7 @@
 (VALUE val)
 {
   int i;
-  int len = 0;
   VALUE v;
-  VALUE buff;
 
   val = rb_str_new(0, 0);
   for(i=num-1; i>=0; i--){
@@ -860,7 +858,7 @@
     break;
   case DEFINED_CONST:
     klass = TOPN(0); POP();
-    if(thread_get_ev_defined(self, th, GET_ISEQ(), klass, SYM2ID(obj))){
+    if(eval_get_ev_defined(th, GET_ISEQ(), klass, SYM2ID(obj))){
       expr_type = "constant";
     }
     break;
@@ -1142,91 +1140,9 @@
       INC_SP(i-1);
     }
   }
-  
-  /********************************************************
-   * method search
-   */
 
-//#undef  INLINE_METHOD_CACHE
-//#define FAKE_INLINE_METHOD_CACHE
-//#define FAKE_INLINE_METHOD_CACHE2
-//#define INLINE_METHOD_CACHE
-//#define ONLY_GLOBAL_METHOD_CACHE
+  mn = eval_method_search(id, klass, ic);
 
-#ifdef __GCC__
-
-#define LIKELY(x)   (__builtin_expect(x, 1))
-#define UNLIKELY(x) (__builtin_expect(x, 0))
-
-#else
-
-#define LIKELY(x)   ((x) == 1)
-#define UNLIKELY(x) ((x) == 0)
-
-#endif
-
-#if 0
-1  error
-#elif defined(FAKE_INLINE_METHOD_CACHE)
-  {
-    /* don't support polymorphic method call */
-    if(LIKELY(ic->ic_method != 0)){
-      mn = ic->ic_method;
-    }
-    else{
-      ic->ic_method = mn = rb_method_node(klass, id);
-    }
-  }
-#elif defined(FAKE_INLINE_METHOD_CACHE2)
-  {
-    if(LIKELY(klass == ic->ic_klass)){
-      mn = ic->ic_method;
-    }
-    else{
-      mn = rb_method_node(klass, id);
-      ic->ic_klass  = klass;
-      ic->ic_method = mn;
-    }
-  }
-#elif defined(INLINE_METHOD_CACHE)
-  {
-    if(LIKELY(klass == ic->ic_klass) &&
-       LIKELY(GET_VM_STATE_VERSION() == ic->ic_vmstat)){
-      mn = ic->ic_method;
-    }
-    else{
-      mn = rb_method_node(klass, id);
-      ic->ic_klass  = klass;
-      ic->ic_method = mn;
-      ic->ic_vmstat = GET_VM_STATE_VERSION();
-    }
-  }
-
-#elif defined(ONLY_GLOBAL_METHOD_CACHE)
-  {
-    struct cache_entry *ent = cache + EXPR1(klass, id);
-    int noex;
-    
-    if (LIKELY(ent->mid == id) && LIKELY(ent->klass == klass)){
-      if(LIKELY(ent->method != 0)){
-        // klass = ent->origin;
-        // id    = ent->mid0;
-        // noex  = ent->noex;
-        mn    = ent->method;
-      }
-      else{
-        mn = 0;
-      }
-    }
-    else{
-      mn = rb_method_node(klass, id);
-    }
-  }
-#else
-  error!
-  mn = rb_method_node(klass, id);
-#endif
-
   /* from other point */
 #if CURRENT_INSN_send || CURRENT_INSN_send_SC_xx_ax
   if(0){
@@ -1251,7 +1167,6 @@
       struct iseq_object *iseqobj = GET_ISEQ();
       struct iseq_object *ip = iseqobj;
       VALUE *sp;
-      int i;
       
       /* really? */
       while(ip->parent_iseqobj){
@@ -1396,9 +1311,7 @@
     /* yarv method */
     struct iseq_object *niseqobj;
     VALUE  newiseq;
-    VALUE *newlfp;
     VALUE *sp = GET_SP();
-    int   block_words = 0;
     int   opt_pc      = 0;
     int   clear_local_size;
 

Modified: trunk/test/test_bin.rb
===================================================================
--- trunk/test/test_bin.rb	2005-06-27 07:55:26 UTC (rev 173)
+++ trunk/test/test_bin.rb	2005-06-27 11:09:33 UTC (rev 174)
@@ -310,7 +310,7 @@
           1
         end
       end
-      fact(7300)
+      fact(300)
     }
   end
 end

Modified: trunk/vm.c
===================================================================
--- trunk/vm.c	2005-06-27 07:55:26 UTC (rev 173)
+++ trunk/vm.c	2005-06-27 11:09:33 UTC (rev 174)
@@ -1,6 +1,7 @@
 #include <ruby.h>
 #include <node.h>
 #include <env.h>
+#include <st.h>
 
 #include "vm.h"
 #include "insnhelper.h"
@@ -8,8 +9,28 @@
 #include "yarvcore.h"
 
 #define BUFSIZE 0x100
+#define EVALBODY_HELPER_FUNCTION static inline
 
+/*
+ * dump functions
+ */
 
+void stack_dump_thobj(struct thread_object *thobj);
+
+
+#ifdef __GCC__
+
+#define LIKELY(x)   (__builtin_expect(x, 1))
+#define UNLIKELY(x) (__builtin_expect(x, 0))
+
+#else
+
+#define LIKELY(x)   ((x) == 1)
+#define UNLIKELY(x) ((x) == 0)
+
+#endif
+
+
 /* imporeted from eval.c */
 struct cache_entry {		/* method hash table. */
     ID mid;			/* method's id */
@@ -33,425 +54,8 @@
 NODE*
 rb_get_method_body(VALUE *klassp, ID *idp, int *noexp);
 
-
-/*
- * VM state dump
- */
-
-
-static void stack_dump_raw(struct thread_object *th, VALUE *sp, VALUE *lfp, VALUE *dfp, VALUE *cfp){
-  VALUE *p, *st, *t;
-  for(p=st=th->stack; p<sp; p++){
-    printf("%08x(%04d): %08x", p, p-st, *p);
-
-    if(*p == FRAME_MAGIC_METHOD) printf(" # FRAME_MAGIC_METHOD");
-    if(*p == FRAME_MAGIC_BLOCK)  printf(" # FRAME_MAGIC_BLOCK");
-    if(*p == FRAME_MAGIC_CLASS)  printf(" # FRAME_MAGIC_CLASS");
-    if(*p == FRAME_MAGIC_TOP)    printf(" # FRAME_MAGIC_TOP");
-
-    t = (VALUE *)*p;
-    if(th->stack <= t && t < th->sp){
-      printf(" (<- %d)", t - th->stack);
-    }
-    
-    if(p == lfp) printf(" <- lfp");
-    if(p == dfp) printf(" <- dfp");
-    if(p == cfp) printf(" <- cfp");
-    if(p == sp)  printf(" <- sp"); /* should not be */
-    
-    printf("\n");
-  }
-  printf("-- (self, iseq, (magic), pc, cfp, lfp, dfp)\n");
-}
-
-static void stack_dump_thobj(struct thread_object *thobj){
-  stack_dump_raw(thobj, thobj->sp, thobj->lfp, thobj->dfp, thobj->cfp);
-}
-
-static void stack_dump_th(VALUE th){
-  struct thread_object *thobj;
-  GetThreadVal(th, thobj);
-  stack_dump_thobj(thobj);
-}
-
-static void stack_dump_each(struct thread_object *th,
-                            VALUE *lfp, VALUE *dfp, VALUE *cfp,
-                            VALUE *sp, struct iseq_object *iseqobj){
-  
-  int i, j;
-  struct continuation_frame *cf;
-  struct local_frame *lf;
-  struct block_frame *bf;
-  
-  VALUE rstr;
-  VALUE *ptr;
-  
-  int argc, local_size;
-  int rewind = 0;
-  char *name;
-
-  if(CMETHOD_INFO_P(iseqobj)){
-    struct cmethod_info *cmi = (void *)iseqobj;
-    argc       = 0;
-    local_size = 0;
-    name       = rb_id2name(cmi->id);
-  }
-  else{
-    argc       = iseqobj->argc;
-    local_size = iseqobj->local_size;
-    name       = RSTRING(iseqobj->name)->ptr;
-  }
-  
-  // stack_dump_raw(th, sp, lfp, dfp, cfp);
-  
-  cf = (struct continuation_frame*) (cfp + CC_DIFF_WC());
-  
-  /* stack trace header */
-
-  if(cf->magic == FRAME_MAGIC_METHOD ||
-     cf->magic == FRAME_MAGIC_TOP    ||
-     cf->magic == FRAME_MAGIC_BLOCK  ||
-     cf->magic == FRAME_MAGIC_CLASS){
-
-    if(cf->cfp){
-      // there are some previous frames
-      struct control_frame * ncf = (struct control_frame *)cf->cfp;
-      struct iseq_object *niseqobj;
-      
-      if(CMETHOD_INFO_P(iseqobj)){
-        rewind = 2;
-      }
-      else{
-        rewind = iseqobj->rewind_frame_size;
-      }
-      
-      // printf("cfp: %x - ", cfp); dp(ncf->iseq);
-      
-      if(CMETHOD_INFO_P(ncf->iseq)){
-        niseqobj = (struct iseq_object *)ncf->iseq;
-      }
-      else{
-        GetISeqVal(ncf->iseq, niseqobj);
-      }
-      // printf("--> %d\n", rewind);
-      stack_dump_each(/* thread  */ th,
-                      /* regs    */ cf->lfp, cf->dfp, cf->cfp,
-                      /* sp      */ cfp - rewind,
-                      /* iseqobj */ niseqobj);
-    }
-    
-    // printf("raw lfp: %x, dfp: %x\n", lfp, dfp);
-    printf("  == stack dump: SP:%4d CFP:%4d ", sp - th->stack, cfp - th->stack);
-    printf("LFP:%4d DFP:%4d ",
-           FRAME_IS_IN_HEAP(lfp) ? lfp : (void*)(lfp - th->stack),
-           dfp && FRAME_IS_IN_HEAP(dfp) ? dfp : (void*)(dfp - th->stack));
-    printf("# %s\n", name);
-
-    // stack_dump_raw(th, sp, lfp, dfp, cfp);
-
-    if(cf->magic == FRAME_MAGIC_BLOCK){
-      /* show block frame */
-      
-      rstr = rb_inspect(cfp[0]);
-      printf("  self    : %s\n", StringValueCStr(rstr));
-
-      if(dfp == 0 || dfp[0] == 0){
-        printf("  prev    : null\n");
-      }
-      else{
-        printf("  prev    : %d\n",
-               FRAME_IS_IN_HEAP(((VALUE*)dfp[0])) ?
-               ((VALUE*)dfp[0]) : (VALUE*)(((VALUE*)dfp[0]) - th->stack));
-      }
-
-      for(i=0; i<argc; i++){
-        rstr = rb_inspect(*(dfp - (iseqobj->local_size - i)));
-        printf("  darg  %2d: %s\n", i, StringValueCStr(rstr));
-      }
-      for(; i<local_size-1; i++){
-        rstr = rb_inspect(*(dfp - (local_size - i)));
-        printf(" dlocal %2d: %s\n", i, StringValueCStr(rstr));
-      }
-      for(i=0; cfp + i + FRAME_WC() - 1 < sp; i++){
-        //printf("ptr: %d (%x) (cfp: %x, sp: %x)\n", ptr - th->stack, ptr, cfp, sp);
-        rstr = rb_inspect(cfp[i + FRAME_WC() - 1]);
-        printf("  stack %2d: %s\n", i, StringValueCStr(rstr));
-      }
-    }
-    else{
-      /* show other frame */
-      
-      rstr = rb_inspect(cfp[0]);
-      printf("  self    : %s\n", StringValueCStr(rstr));
-
-      if(lfp[0] != 0){
-        struct vm_block_object *bo = (struct vm_block_object *)(lfp[0]);
-        if(BUILTIN_TYPE(bo->iseq) == T_NODE){
-          rstr = rb_str_new2("#<IFUNC>");
-        }
-        else{
-          rstr = rb_inspect(bo->iseq);
-        }
-        printf("  block   : %s \n", StringValueCStr(rstr));
-      }
-      else{
-        printf("  block   : --\n");
-      }
-      
-      for(i=0; i<argc; i++){
-        rstr = rb_inspect(*(lfp - (local_size - i)));
-        printf("  arg   %2d: %s\n", i, StringValueCStr(rstr));
-      }
-
-      for(; i<local_size-1; i++){
-        rstr = rb_inspect(*(lfp -(local_size - i)));
-        printf("  local %2d: %s\n", i, StringValueCStr(rstr));
-      }
-
-      /* stack */
-      ptr = cfp + FRAME_WC() - 1;
-      if(lfp[0] == (VALUE)(ptr - VM_BLOCK_OBJECT_SAHRE_SIZE)){
-        ptr += VM_BLOCK_OBJECT_OVER_SIZE;
-      }
-      
-      for(i=0; ptr < sp; i++, ptr++){
-        //printf("ptr: %d (%x) (cfp: %x, sp: %x)\n", ptr - th->stack, ptr, cfp, sp);
-        // stack_dump_raw(th, sp, lfp, dfp, cfp);
-        rstr = rb_inspect(*ptr);
-        printf("  stack %2d: %s (%x)\n", i, StringValueCStr(rstr), ptr);
-      }
-    }
-  }
-  else{
-    rb_bug("unsupport frame type: %08x", cf->magic);
-  }
-}
-
-
-static void debug_print_register(struct thread_object *th,
-                                 int pc, VALUE *sp, VALUE *lfp, VALUE *dfp, VALUE *cfp){
-  
-  printf("  [PC] %04d, [SP] %04d, [LFP] %04d, [DFP] %04d, [CFP] %04d\n",
-         pc, sp - th->stack, lfp - th->stack,
-         dfp ? dfp - th->stack : 0, cfp - th->stack);
-}
-
-static void thread_dump_regs(VALUE th){
-  struct thread_object *thobj;
-  GetThreadVal(th, thobj);
-
-  debug_print_register(thobj, 0, thobj->sp,
-                       thobj->lfp, thobj->dfp, thobj->cfp);
-}
-
-static void debug_print_pre(struct thread_object *th,
-                            VALUE *iseq, int pc,
-                            struct iseq_object *iseqobj,
-                            VALUE *sp, VALUE *lfp, VALUE *dfp, VALUE *cfp){
-
-  iseq_disasm_insn(0, iseq, pc, iseqobj, 0);
-#if VMDEBUG > 3
-  printf("        (1)");
-  debug_print_register(th, pc, sp, lfp, dfp, cfp);
-#endif
-}
-
-static void debug_print_post(struct thread_object *th, struct iseq_object *iseq,
-                             int pc, VALUE *sp, VALUE *lfp, VALUE *dfp, VALUE *cfp
-#ifdef OPT_STACK_CACHING
-                             , VALUE reg_a, VALUE reg_b
-#endif
-                             ){
-  
-#if VMDEBUG > 3
-  printf("        (2)");
-  debug_print_register(th, pc, sp, lfp, dfp, cfp);
-#endif
-
-#if VMDEBUG > 2
-  // stack_dump_thobj(th);
-  stack_dump_each(th, lfp, dfp, cfp, sp, iseq);
-#ifdef OPT_STACK_CACHING
-  {
-    VALUE rstr;
-    rstr = rb_inspect(reg_a);
-    printf("  sc reg A: %s\n", StringValueCStr(rstr));
-    rstr = rb_inspect(reg_b);
-    printf("  sc reg B: %s\n", StringValueCStr(rstr));
-  }
-#endif
-#endif
-  
-#if VMDEBUG > 9
-  GC_CHECK();
-#endif
-}
-
-#ifdef COLLECT_USAGE_ANALYSIS
-/* uh = {
- *   insn(Fixnum) => ihash(Hash)
- * }
- * ihash = {
- *   -1(Fixnum) => count,      # insn usage
- *    0(Fixnum) => ophash,     # operand usage
- * }
- * ophash = {
- *   val(interned string) => count(Fixnum)
- * }
- */
-void vm_analysis_insn(int insn){
-  static ID usage_hash;
-  static ID bigram_hash;
-  static int prev_insn = -1;
-
-  VALUE uh;
-  VALUE ihash;
-  VALUE cv;
-
-  SET_YARV_STOP();
-  
-  if(usage_hash == 0){
-    usage_hash = rb_intern("USAGE_ANALISYS_INSN");
-    bigram_hash = rb_intern("USAGE_ANALISYS_INSN_BIGRAM");
-  }
-  uh = rb_const_get(mYarvCore, usage_hash);
-  if((ihash = rb_hash_aref(uh, INT2FIX(insn))) == Qnil){
-    ihash = rb_hash_new();
-    rb_hash_aset(uh, INT2FIX(insn), ihash);
-  }
-  if((cv = rb_hash_aref(ihash, INT2FIX(-1))) == Qnil){
-    cv = INT2FIX(0);
-  }
-  rb_hash_aset(ihash, INT2FIX(-1), INT2FIX(FIX2INT(cv)+1));
-
-  /* calc bigram */
-  if(prev_insn != -1){
-    VALUE bi;
-    VALUE ary[2];
-    VALUE cv;
-    
-    ary[0] = INT2FIX(prev_insn);
-    ary[1] = INT2FIX(insn);
-    bi = rb_ary_new4(2, &ary[0]);
-    
-    uh = rb_const_get(mYarvCore, bigram_hash);
-    if((cv = rb_hash_aref(uh, bi)) == Qnil){
-      cv = INT2FIX(0);
-    }
-    rb_hash_aset(uh, bi, INT2FIX(FIX2INT(cv)+1));
-  }
-  prev_insn = insn;
-  
-  SET_YARV_START();
-}
-
-/* from disasm.c */
-VALUE insn_operand_intern(int insn, int op_no, VALUE op,
-                          int len, int pos, VALUE child);
-
-void vm_analysis_operand(int insn, int n, VALUE op){
-  static ID usage_hash;
-  
-  VALUE uh;
-  VALUE ihash;
-  VALUE ophash;
-  VALUE valstr;
-  VALUE cv;
-
-  SET_YARV_STOP();
-  
-  if(usage_hash == 0){
-    usage_hash  = rb_intern("USAGE_ANALISYS_INSN");
-  }
-  
-  uh = rb_const_get(mYarvCore, usage_hash);
-  if((ihash = rb_hash_aref(uh, INT2FIX(insn))) == Qnil){
-    ihash = rb_hash_new();
-    rb_hash_aset(uh, INT2FIX(insn), ihash);
-  }
-  if((ophash = rb_hash_aref(ihash, INT2FIX(n))) == Qnil){
-    ophash = rb_hash_new();
-    rb_hash_aset(ihash, INT2FIX(n), ophash);
-  }
-  /* intern */
-  valstr = insn_operand_intern(insn, n, op, 0,0,0);
-  
-  /* set count */
-  if((cv = rb_hash_aref(ophash, valstr)) == Qnil){
-    cv = INT2FIX(0);
-  }
-  rb_hash_aset(ophash, valstr, INT2FIX(FIX2INT(cv) + 1));
-  
-  SET_YARV_START();
-}
-
-void vm_analysis_register(int reg, int isset){
-  static ID usage_hash;
-  VALUE uh;
-  VALUE rhash;
-  VALUE valstr;
-  char *regstrs[] = {
-    "pc",   // 0
-    "sp",   // 1
-    "cfp",  // 2
-    "lfp",  // 3
-    "dfp",  // 4
-    "self", // 5
-    "iseq", // 6
-  };
-  char *getsetstr[] = {
-    "get",
-    "set",
-  };
-  static VALUE syms[sizeof(regstrs)/sizeof(regstrs[0])][2];
-  
-  VALUE cv;
-
-  SET_YARV_STOP();
-  
-  if(usage_hash == 0){
-    char buff[0x10];
-    int i;
-    
-    usage_hash = rb_intern("USAGE_ANALISYS_REGS");
-
-    for(i=0; i<sizeof(regstrs)/sizeof(regstrs[0]); i++){
-      int j;
-      for(j=0; j<2; j++){
-        snprintf(buff, 0x10, "%d %s %-4s", i, getsetstr[j], regstrs[i]);
-        syms[i][j] = ID2SYM(rb_intern(buff));
-      }
-    }
-  }
-  valstr = syms[reg][isset];
-  
-  uh = rb_const_get(mYarvCore, usage_hash);
-  if((cv = rb_hash_aref(uh, valstr)) == Qnil){
-    cv = INT2FIX(0);
-  }
-  rb_hash_aset(uh, valstr, INT2FIX(FIX2INT(cv) + 1));
-  
-  SET_YARV_START();
-}
-
-
-#endif
-
 #include "call_cfunc.inc"
 
-VALUE thread_dump_state(VALUE self){
-  struct thread_object* thobj;
-  GetThreadVal(self, thobj);
-
-  printf("Thread state dump:\n");
-  printf("pc : %8x, sp : %8x\n", thobj->pc, thobj->sp);
-  printf("cfp: %8x, lfp: %8x, dfp: %8x\n", thobj->cfp, thobj->lfp, thobj->dfp);
-
-  return Qnil;
-}
-
-
-
 /*
  * prepare stack frame
  */
@@ -663,9 +267,9 @@
       id = cmi->id;
     }
     else{
-      VALUE iseq = thobj->cfp[1];
-      struct iseq_object *iseqobj;
-      struct RArray *ary;
+      // VALUE  iseq = thobj->cfp[1];
+      // struct iseq_object *iseqobj;
+      // struct RArray *ary;
 
       rb_bug("thread_call_super: should not be reached");
       /*
@@ -774,7 +378,6 @@
   struct thread_object *thobj;
   struct iseq_object *iseqobj;
   struct vm_block_object *bp;
-  VALUE iseq;
   VALUE *dfp;
   
   GetThreadVal(self, thobj);
@@ -858,8 +461,7 @@
 VALUE thread_invoke_proc_call(VALUE self, VALUE proc, int argc, VALUE *argv){
   struct thread_object *thobj;
   struct vm_proc_object *procobj;
-  VALUE* stack;
-  
+ 
   GetThreadVal(self, thobj);
   GetProcVal(proc, procobj);
 
@@ -984,7 +586,6 @@
 VALUE thread_make_proc_object(VALUE th, VALUE proc_iseq, VALUE self,
                               VALUE *cfp, VALUE *orig_dfp, VALUE *orig_lfp){
   VALUE proc, env = Qnil;
-  VALUE iseq;
   VALUE *dfp;
   VALUE *lfp;
   VALUE block;
@@ -1152,7 +753,7 @@
       }
       else{
         struct iseq_object *iseq;
-        int pos, sendpos, i, line_no;
+        int pos, sendpos, i, line_no = -1;
 
         GetISeqVal(f->iseq, iseq);
         pos = pc - GET_SEQ(iseq);
@@ -1201,9 +802,16 @@
 }
 
 
-/* vm main loop helper functions */
-VALUE thread_get_ev_const(VALUE self, struct thread_object *th,
-                          struct iseq_object *iseq, VALUE klass, ID id){
+/*
+ *
+ * vm main loop helper functions
+ *
+ */
+
+
+EVALBODY_HELPER_FUNCTION
+VALUE eval_get_ev_const(struct thread_object *th,
+                        struct iseq_object *iseq, VALUE klass, ID id){
   VALUE val;
   
   if(klass == Qnil){
@@ -1241,8 +849,9 @@
   return val;
 }
 
-int thread_get_ev_defined(VALUE self, struct thread_object *th,
-                          struct iseq_object *iseq, VALUE klass, ID id){
+EVALBODY_HELPER_FUNCTION
+int eval_get_ev_defined(struct thread_object *th,
+                        struct iseq_object *iseq, VALUE klass, ID id){
   VALUE val;
   if(klass == Qnil){
     VALUE cref;
@@ -1274,7 +883,81 @@
   }
 }
 
+EVALBODY_HELPER_FUNCTION
+NODE* eval_method_search(VALUE id, VALUE klass, IC ic){
+  NODE *mn;
 
+//#undef  INLINE_METHOD_CACHE
+//#define FAKE_INLINE_METHOD_CACHE
+//#define FAKE_INLINE_METHOD_CACHE2
+//#define INLINE_METHOD_CACHE
+//#define ONLY_GLOBAL_METHOD_CACHE
+
+#if 0
+1  error
+#elif defined(FAKE_INLINE_METHOD_CACHE)
+  {
+    /* don't support polymorphic method call */
+    if(LIKELY(ic->ic_method != 0)){
+      mn = ic->ic_method;
+    }
+    else{
+      ic->ic_method = mn = rb_method_node(klass, id);
+    }
+  }
+#elif defined(FAKE_INLINE_METHOD_CACHE2)
+  {
+    if(LIKELY(klass == ic->ic_klass)){
+      mn = ic->ic_method;
+    }
+    else{
+      mn = rb_method_node(klass, id);
+      ic->ic_klass  = klass;
+      ic->ic_method = mn;
+    }
+  }
+#elif defined(INLINE_METHOD_CACHE)
+  {
+    if(LIKELY(klass == ic->ic_klass) &&
+       LIKELY(GET_VM_STATE_VERSION() == ic->ic_vmstat)){
+      mn = ic->ic_method;
+    }
+    else{
+      mn = rb_method_node(klass, id);
+      ic->ic_klass  = klass;
+      ic->ic_method = mn;
+      ic->ic_vmstat = GET_VM_STATE_VERSION();
+    }
+  }
+
+#elif defined(ONLY_GLOBAL_METHOD_CACHE)
+  {
+    struct cache_entry *ent = cache + EXPR1(klass, id);
+    int noex;
+    
+    if (LIKELY(ent->mid == id) && LIKELY(ent->klass == klass)){
+      if(LIKELY(ent->method != 0)){
+        // klass = ent->origin;
+        // id    = ent->mid0;
+        // noex  = ent->noex;
+        mn    = ent->method;
+      }
+      else{
+        mn = 0;
+      }
+    }
+    else{
+      mn = rb_method_node(klass, id);
+    }
+  }
+#else
+  error!
+  mn = rb_method_node(klass, id);
+#endif
+  return mn;
+}
+
+
 /* vm main loop */
 
 #ifndef HAVE_TYPE_ULONG
@@ -1373,7 +1056,7 @@
 
 VALUE yarv_unredefined_flag = 0x01;
 
-#include "vm_evalbody.inc"
+#include "vm_evalbody.h"
 
 #if __GNUC__
 // #define thread_eval_body thread_eval_body_copy

Modified: trunk/vm.h
===================================================================
--- trunk/vm.h	2005-06-27 07:55:26 UTC (rev 173)
+++ trunk/vm.h	2005-06-27 11:09:33 UTC (rev 174)
@@ -39,9 +39,9 @@
 #define USAGE_ANALYSIS_OPERAND(insn, n, op) vm_analysis_operand(insn, n, (VALUE)op)
 #define USAGE_ANALYSIS_REGISTER(reg, s)     vm_analysis_register(reg, s)
 #else
-#define USAGE_ANALYSIS_INSN(insn)            0
-#define USAGE_ANALYSIS_OPERAND(insn, n, op)  0
-#define USAGE_ANALYSIS_REGISTER(reg, s)      0
+#define USAGE_ANALYSIS_INSN(insn)            /* none */
+#define USAGE_ANALYSIS_OPERAND(insn, n, op)  /* none */
+#define USAGE_ANALYSIS_REGISTER(reg, s)      /* none */
 
 #endif
 
@@ -116,7 +116,6 @@
 #define END_INSN(insn)      \
   GC_CHECK();               \
   DEBUG_END_INSN();         \
-  ELABEL(insn):             \
   TC_DISPATCH(insn);        \
 
 #define INSN_DISPATCH()   \

Added: trunk/vm_dump.c
===================================================================
--- trunk/vm_dump.c	2005-06-27 07:55:26 UTC (rev 173)
+++ trunk/vm_dump.c	2005-06-27 11:09:33 UTC (rev 174)
@@ -0,0 +1,416 @@
+#include <ruby.h>
+#include <node.h>
+
+#include "yarvcore.h"
+#include "vm.h"
+
+/*
+ * VM state dump
+ */
+void stack_dump_raw(struct thread_object *th, VALUE *sp, VALUE *lfp, VALUE *dfp, VALUE *cfp){
+  VALUE *p, *st, *t;
+  for(p=st=th->stack; p<sp; p++){
+    printf("%p (%04d): %08x", p, p-st, *p);
+
+    if(*p == FRAME_MAGIC_METHOD) printf(" # FRAME_MAGIC_METHOD");
+    if(*p == FRAME_MAGIC_BLOCK)  printf(" # FRAME_MAGIC_BLOCK");
+    if(*p == FRAME_MAGIC_CLASS)  printf(" # FRAME_MAGIC_CLASS");
+    if(*p == FRAME_MAGIC_TOP)    printf(" # FRAME_MAGIC_TOP");
+
+    t = (VALUE *)*p;
+    if(th->stack <= t && t < th->sp){
+      printf(" (<- %d)", t - th->stack);
+    }
+    
+    if(p == lfp) printf(" <- lfp");
+    if(p == dfp) printf(" <- dfp");
+    if(p == cfp) printf(" <- cfp");
+    if(p == sp)  printf(" <- sp"); /* should not be */
+    
+    printf("\n");
+  }
+  printf("-- (self, iseq, (magic), pc, cfp, lfp, dfp)\n");
+}
+
+void stack_dump_thobj(struct thread_object *thobj){
+  stack_dump_raw(thobj, thobj->sp, thobj->lfp, thobj->dfp, thobj->cfp);
+}
+
+void stack_dump_th(VALUE th){
+  struct thread_object *thobj;
+  GetThreadVal(th, thobj);
+  stack_dump_thobj(thobj);
+}
+
+void stack_dump_each(struct thread_object *th,
+                     VALUE *lfp, VALUE *dfp, VALUE *cfp,
+                     VALUE *sp, struct iseq_object *iseqobj){
+  
+  int i;
+  struct continuation_frame *cf;
+  
+  VALUE rstr;
+  VALUE *ptr;
+  
+  int argc, local_size;
+  int rewind = 0;
+  char *name;
+
+  if(CMETHOD_INFO_P(iseqobj)){
+    struct cmethod_info *cmi = (void *)iseqobj;
+    argc       = 0;
+    local_size = 0;
+    name       = rb_id2name(cmi->id);
+  }
+  else{
+    argc       = iseqobj->argc;
+    local_size = iseqobj->local_size;
+    name       = RSTRING(iseqobj->name)->ptr;
+  }
+  
+  // stack_dump_raw(th, sp, lfp, dfp, cfp);
+  
+  cf = (struct continuation_frame*) (cfp + CC_DIFF_WC());
+  
+  /* stack trace header */
+
+  if(cf->magic == FRAME_MAGIC_METHOD ||
+     cf->magic == FRAME_MAGIC_TOP    ||
+     cf->magic == FRAME_MAGIC_BLOCK  ||
+     cf->magic == FRAME_MAGIC_CLASS){
+
+    if(cf->cfp){
+      // there are some previous frames
+      struct control_frame * ncf = (struct control_frame *)cf->cfp;
+      struct iseq_object *niseqobj;
+      
+      if(CMETHOD_INFO_P(iseqobj)){
+        rewind = 2;
+      }
+      else{
+        rewind = iseqobj->rewind_frame_size;
+      }
+      
+      // printf("cfp: %x - ", cfp); dp(ncf->iseq);
+      
+      if(CMETHOD_INFO_P(ncf->iseq)){
+        niseqobj = (struct iseq_object *)ncf->iseq;
+      }
+      else{
+        GetISeqVal(ncf->iseq, niseqobj);
+      }
+      // printf("--> %d\n", rewind);
+      stack_dump_each(/* thread  */ th,
+                      /* regs    */ cf->lfp, cf->dfp, cf->cfp,
+                      /* sp      */ cfp - rewind,
+                      /* iseqobj */ niseqobj);
+    }
+    
+    // printf("raw lfp: %x, dfp: %x\n", lfp, dfp);
+    printf("  == stack dump: SP:%4d CFP:%4d ", sp - th->stack, cfp - th->stack);
+    printf("LFP:%4p DFP:%4p ",
+           FRAME_IS_IN_HEAP(lfp) ? lfp : (void*)(lfp - th->stack),
+           dfp && FRAME_IS_IN_HEAP(dfp) ? dfp : (void*)(dfp - th->stack));
+    printf("# %s\n", name);
+
+    // stack_dump_raw(th, sp, lfp, dfp, cfp);
+
+    if(cf->magic == FRAME_MAGIC_BLOCK){
+      /* show block frame */
+      
+      rstr = rb_inspect(cfp[0]);
+      printf("  self    : %s\n", StringValueCStr(rstr));
+
+      if(dfp == 0 || dfp[0] == 0){
+        printf("  prev    : null\n");
+      }
+      else{
+        printf("  prev    : %d\n",
+               FRAME_IS_IN_HEAP(((VALUE*)dfp[0])) ?
+               ((VALUE*)dfp[0]) : (VALUE*)(((VALUE*)dfp[0]) - th->stack));
+      }
+
+      for(i=0; i<argc; i++){
+        rstr = rb_inspect(*(dfp - (iseqobj->local_size - i)));
+        printf("  darg  %2d: %s\n", i, StringValueCStr(rstr));
+      }
+      for(; i<local_size-1; i++){
+        rstr = rb_inspect(*(dfp - (local_size - i)));
+        printf(" dlocal %2d: %s\n", i, StringValueCStr(rstr));
+      }
+      for(i=0; cfp + i + FRAME_WC() - 1 < sp; i++){
+        //printf("ptr: %d (%x) (cfp: %x, sp: %x)\n", ptr - th->stack, ptr, cfp, sp);
+        rstr = rb_inspect(cfp[i + FRAME_WC() - 1]);
+        printf("  stack %2d: %s\n", i, StringValueCStr(rstr));
+      }
+    }
+    else{
+      /* show other frame */
+      
+      rstr = rb_inspect(cfp[0]);
+      printf("  self    : %s\n", StringValueCStr(rstr));
+
+      if(lfp[0] != 0){
+        struct vm_block_object *bo = (struct vm_block_object *)(lfp[0]);
+        if(BUILTIN_TYPE(bo->iseq) == T_NODE){
+          rstr = rb_str_new2("#<IFUNC>");
+        }
+        else{
+          rstr = rb_inspect(bo->iseq);
+        }
+        printf("  block   : %s \n", StringValueCStr(rstr));
+      }
+      else{
+        printf("  block   : --\n");
+      }
+      
+      for(i=0; i<argc; i++){
+        rstr = rb_inspect(*(lfp - (local_size - i)));
+        printf("  arg   %2d: %s\n", i, StringValueCStr(rstr));
+      }
+
+      for(; i<local_size-1; i++){
+        rstr = rb_inspect(*(lfp -(local_size - i)));
+        printf("  local %2d: %s\n", i, StringValueCStr(rstr));
+      }
+
+      /* stack */
+      ptr = cfp + FRAME_WC() - 1;
+      if(lfp[0] == (VALUE)(ptr - VM_BLOCK_OBJECT_SAHRE_SIZE)){
+        ptr += VM_BLOCK_OBJECT_OVER_SIZE;
+      }
+      
+      for(i=0; ptr < sp; i++, ptr++){
+        //printf("ptr: %d (%x) (cfp: %x, sp: %x)\n", ptr - th->stack, ptr, cfp, sp);
+        // stack_dump_raw(th, sp, lfp, dfp, cfp);
+        rstr = rb_inspect(*ptr);
+        printf("  stack %2d: %s (%x)\n", i, StringValueCStr(rstr), ptr);
+      }
+    }
+  }
+  else{
+    rb_bug("unsupport frame type: %08x", cf->magic);
+  }
+}
+
+
+void debug_print_register(struct thread_object *th,
+                          int pc, VALUE *sp, VALUE *lfp, VALUE *dfp, VALUE *cfp){
+  
+  printf("  [PC] %04d, [SP] %04d, [LFP] %04d, [DFP] %04d, [CFP] %04d\n",
+         pc, sp - th->stack, lfp - th->stack,
+         dfp ? dfp - th->stack : 0, cfp - th->stack);
+}
+
+void thread_dump_regs(VALUE th){
+  struct thread_object *thobj;
+  GetThreadVal(th, thobj);
+
+  debug_print_register(thobj, 0, thobj->sp,
+                       thobj->lfp, thobj->dfp, thobj->cfp);
+}
+
+void debug_print_pre(struct thread_object *th,
+                            VALUE *iseq, int pc,
+                            struct iseq_object *iseqobj,
+                            VALUE *sp, VALUE *lfp, VALUE *dfp, VALUE *cfp){
+
+  iseq_disasm_insn(0, iseq, pc, iseqobj, 0);
+#if VMDEBUG > 3
+  printf("        (1)");
+  debug_print_register(th, pc, sp, lfp, dfp, cfp);
+#endif
+}
+
+void debug_print_post(struct thread_object *th, struct iseq_object *iseq,
+                             int pc, VALUE *sp, VALUE *lfp, VALUE *dfp, VALUE *cfp
+#ifdef OPT_STACK_CACHING
+                             , VALUE reg_a, VALUE reg_b
+#endif
+                             ){
+  
+#if VMDEBUG > 3
+  printf("        (2)");
+  debug_print_register(th, pc, sp, lfp, dfp, cfp);
+#endif
+
+#if VMDEBUG > 2
+  // stack_dump_thobj(th);
+  stack_dump_each(th, lfp, dfp, cfp, sp, iseq);
+#ifdef OPT_STACK_CACHING
+  {
+    VALUE rstr;
+    rstr = rb_inspect(reg_a);
+    printf("  sc reg A: %s\n", StringValueCStr(rstr));
+    rstr = rb_inspect(reg_b);
+    printf("  sc reg B: %s\n", StringValueCStr(rstr));
+  }
+#endif
+#endif
+  
+#if VMDEBUG > 9
+  GC_CHECK();
+#endif
+}
+
+#ifdef COLLECT_USAGE_ANALYSIS
+/* uh = {
+ *   insn(Fixnum) => ihash(Hash)
+ * }
+ * ihash = {
+ *   -1(Fixnum) => count,      # insn usage
+ *    0(Fixnum) => ophash,     # operand usage
+ * }
+ * ophash = {
+ *   val(interned string) => count(Fixnum)
+ * }
+ */
+void vm_analysis_insn(int insn){
+  static ID usage_hash;
+  static ID bigram_hash;
+  static int prev_insn = -1;
+
+  VALUE uh;
+  VALUE ihash;
+  VALUE cv;
+
+  SET_YARV_STOP();
+  
+  if(usage_hash == 0){
+    usage_hash = rb_intern("USAGE_ANALISYS_INSN");
+    bigram_hash = rb_intern("USAGE_ANALISYS_INSN_BIGRAM");
+  }
+  uh = rb_const_get(mYarvCore, usage_hash);
+  if((ihash = rb_hash_aref(uh, INT2FIX(insn))) == Qnil){
+    ihash = rb_hash_new();
+    rb_hash_aset(uh, INT2FIX(insn), ihash);
+  }
+  if((cv = rb_hash_aref(ihash, INT2FIX(-1))) == Qnil){
+    cv = INT2FIX(0);
+  }
+  rb_hash_aset(ihash, INT2FIX(-1), INT2FIX(FIX2INT(cv)+1));
+
+  /* calc bigram */
+  if(prev_insn != -1){
+    VALUE bi;
+    VALUE ary[2];
+    VALUE cv;
+    
+    ary[0] = INT2FIX(prev_insn);
+    ary[1] = INT2FIX(insn);
+    bi = rb_ary_new4(2, &ary[0]);
+    
+    uh = rb_const_get(mYarvCore, bigram_hash);
+    if((cv = rb_hash_aref(uh, bi)) == Qnil){
+      cv = INT2FIX(0);
+    }
+    rb_hash_aset(uh, bi, INT2FIX(FIX2INT(cv)+1));
+  }
+  prev_insn = insn;
+  
+  SET_YARV_START();
+}
+
+/* from disasm.c */
+VALUE insn_operand_intern(int insn, int op_no, VALUE op,
+                          int len, int pos, VALUE child);
+
+void vm_analysis_operand(int insn, int n, VALUE op){
+  static ID usage_hash;
+  
+  VALUE uh;
+  VALUE ihash;
+  VALUE ophash;
+  VALUE valstr;
+  VALUE cv;
+
+  SET_YARV_STOP();
+  
+  if(usage_hash == 0){
+    usage_hash  = rb_intern("USAGE_ANALISYS_INSN");
+  }
+  
+  uh = rb_const_get(mYarvCore, usage_hash);
+  if((ihash = rb_hash_aref(uh, INT2FIX(insn))) == Qnil){
+    ihash = rb_hash_new();
+    rb_hash_aset(uh, INT2FIX(insn), ihash);
+  }
+  if((ophash = rb_hash_aref(ihash, INT2FIX(n))) == Qnil){
+    ophash = rb_hash_new();
+    rb_hash_aset(ihash, INT2FIX(n), ophash);
+  }
+  /* intern */
+  valstr = insn_operand_intern(insn, n, op, 0,0,0);
+  
+  /* set count */
+  if((cv = rb_hash_aref(ophash, valstr)) == Qnil){
+    cv = INT2FIX(0);
+  }
+  rb_hash_aset(ophash, valstr, INT2FIX(FIX2INT(cv) + 1));
+  
+  SET_YARV_START();
+}
+
+void vm_analysis_register(int reg, int isset){
+  static ID usage_hash;
+  VALUE uh;
+  VALUE rhash;
+  VALUE valstr;
+  char *regstrs[] = {
+    "pc",   // 0
+    "sp",   // 1
+    "cfp",  // 2
+    "lfp",  // 3
+    "dfp",  // 4
+    "self", // 5
+    "iseq", // 6
+  };
+  char *getsetstr[] = {
+    "get",
+    "set",
+  };
+  static VALUE syms[sizeof(regstrs)/sizeof(regstrs[0])][2];
+  
+  VALUE cv;
+
+  SET_YARV_STOP();
+  
+  if(usage_hash == 0){
+    char buff[0x10];
+    int i;
+    
+    usage_hash = rb_intern("USAGE_ANALISYS_REGS");
+
+    for(i=0; i<sizeof(regstrs)/sizeof(regstrs[0]); i++){
+      int j;
+      for(j=0; j<2; j++){
+        snprintf(buff, 0x10, "%d %s %-4s", i, getsetstr[j], regstrs[i]);
+        syms[i][j] = ID2SYM(rb_intern(buff));
+      }
+    }
+  }
+  valstr = syms[reg][isset];
+  
+  uh = rb_const_get(mYarvCore, usage_hash);
+  if((cv = rb_hash_aref(uh, valstr)) == Qnil){
+    cv = INT2FIX(0);
+  }
+  rb_hash_aset(uh, valstr, INT2FIX(FIX2INT(cv) + 1));
+  
+  SET_YARV_START();
+}
+
+
+#endif
+
+VALUE thread_dump_state(VALUE self){
+  struct thread_object* thobj;
+  GetThreadVal(self, thobj);
+
+  printf("Thread state dump:\n");
+  printf("pc : %p, sp : %p\n", thobj->pc, thobj->sp);
+  printf("cfp: %p, lfp: %p, dfp: %p\n", thobj->cfp, thobj->lfp, thobj->dfp);
+
+  return Qnil;
+}
+

Copied: trunk/vm_evalbody.h (from rev 173, trunk/vm_evalbody.inc)
===================================================================
--- trunk/vm_evalbody.inc	2005-06-27 07:55:26 UTC (rev 173)
+++ trunk/vm_evalbody.h	2005-06-27 11:09:33 UTC (rev 174)
@@ -0,0 +1,281 @@
+/* -*-c-*- *********************************************************
+ * this file is included by vm.c
+ */
+
+#if VMDEBUG > 0
+#define DECL_SC_REG(type, r, reg) register type reg_##r
+
+#elif __GNUC__ && __x86_64
+#define DECL_SC_REG(type, r, reg) register type reg_##r asm("r" reg)
+
+#elif __GNUC__ && __i386__
+#define DECL_SC_REG(type, r, reg) register type reg_##r asm("e" reg)
+
+#else
+#define DECL_SC_REG(type, r, reg) register type reg_##r
+#endif
+// #define DECL_SC_REG(r, reg) VALUE reg_##r
+
+VALUE thread_eval_body(VALUE self){
+  struct thread_object *th;
+
+#ifdef OPT_STACK_CACHING
+#if 0
+  DECL_SC_REG(VALUE, a, "di");
+  DECL_SC_REG(VALUE, b, "dx");
+#else
+  register VALUE reg_a;
+  register VALUE reg_b;
+#endif
+#endif
+
+#if 1 && __GNUC__ && __i386__
+  DECL_SC_REG(VALUE *, pc, "si");
+  VALUE * volatile reg_pc_store;
+
+#undef  SET_PC
+#undef  RESTORE_REGS
+
+#define SET_PC(x) (reg_pc_store = REG_PC = (x))
+#define RESTORE_REGS() { \
+  REG_PC = reg_pc_store; \
+}
+#elif 0 /* for debug */
+  DECL_SC_REG(VALUE *, pc, "si");
+#else
+  VALUE *reg_pc;
+#endif
+
+  VALUE *reg_sp;
+  VALUE *reg_lfp;
+  VALUE *reg_dfp;
+  VALUE *reg_cfp;
+
+  ID tmp_id;
+  VALUE throwed;
+  
+  int state;
+  struct tag _tag;
+
+#ifdef DISPATCH_THREADED_CODE
+#include "vmtc.inc"
+#endif
+
+#ifdef DISPATCH_DIRECT_THREADED_CODE
+  if(self == 0){
+    return (VALUE)insns_address_table;
+  }
+#endif
+  
+  GetThreadVal(self , th);
+
+  reg_pc  = th->pc;
+  reg_sp  = th->sp;
+  reg_lfp = th->lfp;
+  reg_dfp = th->dfp;
+  reg_cfp = th->cfp;
+
+#ifdef OPT_STACK_CACHING
+  reg_a = reg_b = 0;
+#endif
+  PUSH_TAG(0);
+  if((state = EXEC_TAG()) == 0){
+
+  first:
+    INSN_DISPATCH();
+    
+    /******************/
+     #include "vm.inc"
+    /******************/
+
+    END_INSNS_DISPATCH();
+
+    /* finish */
+  finish:;
+  }
+  else{
+    RESTORE_REGS();
+    throwed = ruby_errinfo;
+    if(state == TAG_RAISE){
+      rb_ivar_set(throwed, idThrowState, state);
+    }
+    
+  catch_entry:
+    {
+      int i;
+      struct catch_table_entry *entry;
+      VALUE  catch_iseq           = 0;
+      struct iseq_object* iseqobj = 0;
+      ulong  epc, cont = 0, cont_sp = 0;
+      iseqobj = GET_ISEQ();
+      epc     = GET_PC_COUNT();
+      
+      // dp(iseqobj->name);
+      // printf("iseqobj->catch_table_size: %d\n", iseqobj->catch_table_size);
+      
+      for(i=0; i<iseqobj->catch_table_size; i++){
+        entry = &iseqobj->catch_table[i];
+        // printf("%d ? [%d] %d, %d\n", epc, entry->type, entry->start, entry->end);
+        if(entry->start <  epc &&
+           entry->end   >= epc){
+
+          if(state == TAG_RAISE){
+            if(entry->type == CATCH_TYPE_RESCUE){
+              catch_iseq = entry->iseq;
+              cont       = entry->cont;
+              cont_sp    = entry->sp;
+              break;
+            }
+          }
+          else if(state == TAG_RETRY){
+            if(entry->type == CATCH_TYPE_RETRY){
+              VALUE  *escape_dfp;
+              escape_dfp = GET_THROWOBJ_CATCH_POINT(throwed);
+              // printf("[%d, %d]\n", GET_DFP() - th->stack, escape_dfp - th->stack);
+              if(GET_DFP() == escape_dfp){
+                cont       = entry->cont;
+                cont_sp    = entry->sp;
+                SET_PC(GET_SEQ(iseqobj) + cont);
+                SET_SP(GET_CFP() + FRAME_WC() + BLOCK_WC_IF_GIVEN() + cont_sp);
+                goto first;
+              }
+            }
+          }
+
+          /* search ensure */
+          if(entry->type == CATCH_TYPE_ENSURE){
+            catch_iseq = entry->iseq;
+            cont       = entry->cont;
+            cont_sp    = entry->sp;
+            break;
+          }
+        }
+      }
+
+      /* search catch table */
+      if(catch_iseq){
+        struct iseq_object* catch_iseqobj = 0;
+        VALUE *sp;
+        struct block_frame *f;
+
+        /* enter catch scope */
+        GetISeqVal(catch_iseq, catch_iseqobj);
+        sp = GET_CFP() + FRAME_WC() + cont_sp;
+
+        if(GET_LFP()[0] == (VALUE)(GET_CFP() + FRAME_WC() - 1)){
+          SET_SP(GET_CFP() + FRAME_WC() + cont_sp + BLOCK_WC());
+        }
+        else{
+          SET_SP(GET_CFP() + FRAME_WC() + cont_sp);
+        }
+        
+        /* PUSH(throwed) */
+        *sp++ = throwed;
+        
+        /* push method frame */
+        f = (struct block_frame *)sp;
+        f->prev_dfp                               = GET_DFP();
+
+        f->control_frame.self                     = GET_SELF();
+        f->control_frame.iseq                     = catch_iseq;
+
+        f->control_frame.continuation_frame.magic = FRAME_MAGIC_BLOCK;
+        f->control_frame.continuation_frame.pc    = GET_SEQ(iseqobj) + cont;
+        f->control_frame.continuation_frame.lfp   = GET_LFP();
+        f->control_frame.continuation_frame.dfp   = GET_DFP();
+        f->control_frame.continuation_frame.cfp   = GET_CFP();
+        // STACKDUMP();
+
+        SET_PC (GET_SEQ(catch_iseqobj));
+        SET_SP (sp + FRAME_WC());
+        SET_CFP(sp + CF_DIFF_WC());
+        SET_LFP(sp);
+        SET_DFP(sp);
+
+        /* others */
+
+        state = 0;
+        ruby_errinfo = Qnil;
+
+        goto first;
+      }
+      else{
+        /* rewind stack */
+        struct continuation_frame *cf;
+        struct iseq_object        *iseqobj;
+
+
+        if(state == TAG_BREAK || state == TAG_RETURN){
+          static VALUE  *escape_dfp;
+          escape_dfp = GET_THROWOBJ_CATCH_POINT(throwed);
+
+          throwdebug("[[st: %d] dfp: %d, lfp: %d, esc: %d, cfp: %d]\n",
+                     state, GET_DFP() - th->stack,
+                     GET_LFP() - th->stack, escape_dfp - th->stack,
+                     GET_CFP() - th->stack);
+          
+          if(GET_DFP() == escape_dfp){
+            if(state == TAG_RETURN){
+              struct continuation_frame *cf =
+                (struct continuation_frame *)(GET_CFP() + CC_DIFF_WC());
+
+              throwdebug("== %d, %d, %d\n",
+                         cf->cfp - th->stack, cf->lfp - th->stack, cf->dfp - th->stack);
+              
+              SET_THROWOBJ_CATCH_POINT(throwed, (VALUE)cf->dfp);
+              SET_THROWOBJ_STATE      (throwed, state = TAG_BREAK);
+              /* through */
+            }
+            else{
+              /* TAG_BREAK */
+#ifdef OPT_STACK_CACHING
+              reg_a = GET_THROWOBJ_VAL(throwed);
+#else
+              PUSH(GET_THROWOBJ_VAL(throwed));
+#endif
+              ruby_errinfo = Qnil;
+              goto first;
+            }
+          }
+        }
+
+      rewind_stack_point:
+        iseqobj = GET_ISEQ();
+        cf = (struct continuation_frame *)(GET_CFP() + CC_DIFF_WC());
+        CHECK_FRAME_MAGIC(cf->magic);
+        CLEAR_ENV(GET_DFP());
+
+        SET_SP (GET_CFP() - iseqobj->rewind_frame_size);
+        SET_PC (cf->pc);
+        SET_LFP(cf->lfp);
+        SET_DFP(cf->dfp);
+        SET_CFP(cf->cfp);
+
+        if(GET_PC() != 0){
+          goto catch_entry;
+        }
+        else{
+          /* no more VM stack */
+
+          /* need this?
+          if(state != TAG_RAISE){
+            ruby_errinfo = Qnil;
+          }
+           */
+          ruby_errinfo = throwed;
+          POP_TAG();
+          JUMP_TAG(state);
+        }
+      }
+    }
+  }
+  POP_TAG();
+
+  th->sp  = reg_sp;
+  th->pc  = reg_pc;
+  th->lfp = reg_lfp;
+  th->dfp = reg_dfp;
+  th->cfp = reg_cfp;
+
+  return throwed;
+}

Deleted: trunk/vm_evalbody.inc
===================================================================
--- trunk/vm_evalbody.inc	2005-06-27 07:55:26 UTC (rev 173)
+++ trunk/vm_evalbody.inc	2005-06-27 11:09:33 UTC (rev 174)
@@ -1,284 +0,0 @@
-/* -*-c-*- *********************************************************
- * this file is included by vm.c
- */
-
-#if VMDEBUG > 0
-#define DECL_SC_REG(type, r, reg) register type reg_##r
-
-#elif __GNUC__ && __x86_64
-#define DECL_SC_REG(type, r, reg) register type reg_##r asm("r" reg)
-
-#elif __GNUC__ && __i386__
-#define DECL_SC_REG(type, r, reg) register type reg_##r asm("e" reg)
-
-#else
-#define DECL_SC_REG(type, r, reg) register type reg_##r
-#endif
-// #define DECL_SC_REG(r, reg) VALUE reg_##r
-
-VALUE thread_eval_body(VALUE self){
-  struct thread_object *th;
-
-#ifdef OPT_STACK_CACHING
-#if 0
-  DECL_SC_REG(VALUE, a, "di");
-  DECL_SC_REG(VALUE, b, "dx");
-#else
-  register VALUE reg_a;
-  register VALUE reg_b;
-#endif
-#endif
-
-#if 1 && __GNUC__ && __i386__
-  DECL_SC_REG(VALUE *, pc, "si");
-  VALUE * volatile reg_pc_store;
-
-#undef  SET_PC
-#undef  RESTORE_REGS
-
-#define SET_PC(x) (reg_pc_store = REG_PC = (x))
-#define RESTORE_REGS() { \
-  REG_PC = reg_pc_store; \
-}
-#elif 0 /* for debug */
-  DECL_SC_REG(VALUE *, pc, "si");
-#else
-  VALUE *reg_pc;
-#endif
-
-  VALUE *reg_sp;
-  VALUE *reg_lfp;
-  VALUE *reg_dfp;
-  VALUE *reg_cfp;
-
-  ID tmp_id;
-  VALUE throwed;
-  
-  int state;
-  struct tag _tag;
-
-#ifdef DISPATCH_THREADED_CODE
-#include "vmtc.inc"
-#endif
-
-#ifdef DISPATCH_DIRECT_THREADED_CODE
-  if(self == 0){
-    return (VALUE)insns_address_table;
-  }
-#endif
-  
-  GetThreadVal(self , th);
-
-  reg_pc  = th->pc;
-  reg_sp  = th->sp;
-  reg_lfp = th->lfp;
-  reg_dfp = th->dfp;
-  reg_cfp = th->cfp;
-
-#ifdef OPT_STACK_CACHING
-  reg_a = reg_b = 0;
-#endif
-  PUSH_TAG(0);
-  if((state = EXEC_TAG()) == 0){
-
-  first:
-    INSN_DISPATCH();
-    
-    /******************/
-     #include "vm.inc"
-    /******************/
-
-    END_INSNS_DISPATCH();
-
-    /* finish */
-  finish:;
-  }
-  else{
-    RESTORE_REGS();
-    throwed = ruby_errinfo;
-    if(state == TAG_RAISE){
-      rb_ivar_set(throwed, idThrowState, state);
-    }
-    
-  catch_entry:
-    {
-      int i;
-      struct catch_table_entry *entry;
-      VALUE  catch_iseq           = 0;
-      struct iseq_object* iseqobj = 0;
-      ulong  epc, cont, cont_sp;
-      iseqobj = GET_ISEQ();
-      epc     = GET_PC_COUNT();
-      
-      // dp(iseqobj->name);
-      // printf("iseqobj->catch_table_size: %d\n", iseqobj->catch_table_size);
-      
-      for(i=0; i<iseqobj->catch_table_size; i++){
-        entry = &iseqobj->catch_table[i];
-        // printf("%d ? [%d] %d, %d\n", epc, entry->type, entry->start, entry->end);
-        if(entry->start <  epc &&
-           entry->end   >= epc){
-
-          if(state == TAG_RAISE){
-            if(entry->type == CATCH_TYPE_RESCUE){
-              catch_iseq = entry->iseq;
-              cont       = entry->cont;
-              cont_sp    = entry->sp;
-              break;
-            }
-          }
-          else if(state == TAG_RETRY){
-            if(entry->type == CATCH_TYPE_RETRY){
-              VALUE  *escape_dfp;
-              escape_dfp = GET_THROWOBJ_CATCH_POINT(throwed);
-              // printf("[%d, %d]\n", GET_DFP() - th->stack, escape_dfp - th->stack);
-              if(GET_DFP() == escape_dfp){
-                cont       = entry->cont;
-                cont_sp    = entry->sp;
-                SET_PC(GET_SEQ(iseqobj) + cont);
-                SET_SP(GET_CFP() + FRAME_WC() + BLOCK_WC_IF_GIVEN() + cont_sp);
-                goto first;
-              }
-            }
-          }
-
-          /* search ensure */
-          if(entry->type == CATCH_TYPE_ENSURE){
-            catch_iseq = entry->iseq;
-            cont       = entry->cont;
-            cont_sp    = entry->sp;
-            break;
-          }
-        }
-      }
-
-      /* search catch table */
-      if(catch_iseq){
-        struct iseq_object* catch_iseqobj = 0;
-        VALUE *sp;
-        struct block_frame *f;
-        VALUE *prev_env;
-        VALUE  prev_main;
-
-        /* enter catch scope */
-        GetISeqVal(catch_iseq, catch_iseqobj);
-        sp = GET_CFP() + FRAME_WC() + cont_sp;
-
-        if(GET_LFP()[0] == (VALUE)(GET_CFP() + FRAME_WC() - 1)){
-          SET_SP(GET_CFP() + FRAME_WC() + cont_sp + BLOCK_WC());
-        }
-        else{
-          SET_SP(GET_CFP() + FRAME_WC() + cont_sp);
-        }
-        
-        /* PUSH(throwed) */
-        *sp++ = throwed;
-        
-        /* push method frame */
-        f = (struct block_frame *)sp;
-        f->prev_dfp                               = GET_DFP();
-
-        f->control_frame.self                     = GET_SELF();
-        f->control_frame.iseq                     = catch_iseq;
-
-        f->control_frame.continuation_frame.magic = FRAME_MAGIC_BLOCK;
-        f->control_frame.continuation_frame.pc    = GET_SEQ(iseqobj) + cont;
-        f->control_frame.continuation_frame.lfp   = GET_LFP();
-        f->control_frame.continuation_frame.dfp   = GET_DFP();
-        f->control_frame.continuation_frame.cfp   = GET_CFP();
-        // STACKDUMP();
-
-        SET_PC (GET_SEQ(catch_iseqobj));
-        SET_SP (sp + FRAME_WC());
-        SET_CFP(sp + CF_DIFF_WC());
-        SET_LFP(sp);
-        SET_DFP(sp);
-
-        /* others */
-
-        state = 0;
-        ruby_errinfo = Qnil;
-
-        goto first;
-      }
-      else{
-        /* rewind stack */
-        struct continuation_frame *cf;
-        struct iseq_object        *iseqobj;
-
-
-        if(state == TAG_BREAK || state == TAG_RETURN){
-          static VALUE  *escape_dfp;
-          escape_dfp = GET_THROWOBJ_CATCH_POINT(throwed);
-
-          throwdebug("[[st: %d] dfp: %d, lfp: %d, esc: %d, cfp: %d]\n",
-                     state, GET_DFP() - th->stack,
-                     GET_LFP() - th->stack, escape_dfp - th->stack,
-                     GET_CFP() - th->stack);
-          
-          if(GET_DFP() == escape_dfp){
-            if(state == TAG_RETURN){
-              VALUE setdfp;
-              struct continuation_frame *cf =
-                (struct continuation_frame *)(GET_CFP() + CC_DIFF_WC());
-
-              throwdebug("== %d, %d, %d\n",
-                         cf->cfp - th->stack, cf->lfp - th->stack, cf->dfp - th->stack);
-              
-              SET_THROWOBJ_CATCH_POINT(throwed, (VALUE)cf->dfp);
-              SET_THROWOBJ_STATE      (throwed, state = TAG_BREAK);
-              /* through */
-            }
-            else{
-              /* TAG_BREAK */
-#ifdef OPT_STACK_CACHING
-              reg_a = GET_THROWOBJ_VAL(throwed);
-#else
-              PUSH(GET_THROWOBJ_VAL(throwed));
-#endif
-              ruby_errinfo = Qnil;
-              goto first;
-            }
-          }
-        }
-
-      rewind_stack_point:
-        iseqobj = GET_ISEQ();
-        cf = (struct continuation_frame *)(GET_CFP() + CC_DIFF_WC());
-        CHECK_FRAME_MAGIC(cf->magic);
-        CLEAR_ENV(GET_DFP());
-
-        SET_SP (GET_CFP() - iseqobj->rewind_frame_size);
-        SET_PC (cf->pc);
-        SET_LFP(cf->lfp);
-        SET_DFP(cf->dfp);
-        SET_CFP(cf->cfp);
-
-        if(GET_PC() != 0){
-          goto catch_entry;
-        }
-        else{
-          /* no more VM stack */
-
-          /* need this?
-          if(state != TAG_RAISE){
-            ruby_errinfo = Qnil;
-          }
-           */
-          ruby_errinfo = throwed;
-          POP_TAG();
-          JUMP_TAG(state);
-        }
-      }
-    }
-  }
-  POP_TAG();
-
-  th->sp  = reg_sp;
-  th->pc  = reg_pc;
-  th->lfp = reg_lfp;
-  th->dfp = reg_dfp;
-  th->cfp = reg_cfp;
-
-  return throwed;
-}

Modified: trunk/yarvcore.c
===================================================================
--- trunk/yarvcore.c	2005-06-27 07:55:26 UTC (rev 173)
+++ trunk/yarvcore.c	2005-06-27 11:09:33 UTC (rev 174)
@@ -70,7 +70,8 @@
 static VALUE yarvCurrentRunningVM     = Qnil;
 static VALUE yarvCurrentRunningThread = Qnil;
 
-// void yarv_setup(void *p1, void *p2, void *p3);
+void yarv_setup(void *p1, void *p2, void *p3, void *p4,
+                void *p5, void *p6, void *p7, void *p8);
 
 VALUE yarv_get_current_running_vm(){
   return yarvCurrentRunningVM;
@@ -197,7 +198,6 @@
   node = rb_compile_string(StringValueCStr(file), str, NUM2INT(line));
   
   if(ruby_nerrs > 0){
-    VALUE str;
     ruby_nerrs = 0;
     rb_exc_raise(ruby_errinfo);
   }
@@ -220,8 +220,7 @@
 static VALUE yarvcore_eval(VALUE self, VALUE str, VALUE file, VALUE line){
   VALUE node = compile_string(str, file, line);
   VALUE argv[5];
-  volatile VALUE iseq, vm;
-  VALUE ret;
+  volatile VALUE iseq;
   
   argv[0] = node;
   argv[1] = rb_str_new2("main");
@@ -383,7 +382,6 @@
   iseqobj->compile_data = 0;
 
   if(ruby_nerrs > 0){
-    VALUE str;
     ruby_nerrs = 0;
     rb_exc_raise(err);
   }
@@ -440,7 +438,6 @@
 }
 
 static VALUE label_to_s(VALUE self){
-  VALUE str;
   struct label_object *lobj;
   char  buff[0x100];
 
@@ -490,13 +487,12 @@
 }
 
 static VALUE insn_to_s(VALUE self){
-  VALUE str;
   struct insn_object *insnobj;
   char  buff[0x100];
   
   GetInsnVal(self, insnobj);
   snprintf(buff, sizeof(buff),
-           "<Insn:%s (%d)>", insn_name(insnobj->insn_id), insnobj->line_no);
+           "<Insn:%s (%d)>", insn_name(insnobj->insn_id), (int)insnobj->line_no);
   
   return rb_str_new2(buff);
 }
@@ -561,7 +557,6 @@
 
 static VALUE vm_eval(VALUE self, VALUE iseq){
   struct vm_object *vm;
-  VALUE ret;
   GetVMVal(self, vm);
   return thread_eval(vm->main_thread, iseq);
 }
@@ -636,7 +631,6 @@
 }
 
 static VALUE thread_eval(VALUE self, VALUE iseq){
-  int err;
   VALUE ret;
   struct thread_object *thobj;
   GetThreadVal(self, thobj);


--
ML: yarv-diff quickml.atdot.net
Info: http://www.atdot.net/~ko1/quickml

[前][次][番号順一覧][スレッド一覧][生データ]