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

yarv-diff:105

From: ko1 atdot.net
Date: 26 Sep 2005 09:55:56 -0000
Subject: [yarv-diff:105] r261 - in trunk: . yarvtest

Author: ko1
Date: 2005-09-26 18:55:54 +0900 (Mon, 26 Sep 2005)
New Revision: 261

Modified:
   trunk/ChangeLog
   trunk/compile.c
   trunk/eval.c
   trunk/eval_intern.h
   trunk/eval_proc.c
   trunk/insns.def
   trunk/parse.y
   trunk/test.rb
   trunk/vm.c
   trunk/yarv.h
   trunk/yarvcore.c
   trunk/yarvcore.h
   trunk/yarvtest/test_syn.rb
Log:
	* eval.c, compile.c, parse.y, vm.c, yarvcore.h :
	 eval() works with binding (Env)

	* vm.c : add th_set_eval_stack

	* yarvtest/test_syn.rb : remove an assert "defined?(local_var)"



Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2005-09-25 10:36:25 UTC (rev 260)
+++ trunk/ChangeLog	2005-09-26 09:55:54 UTC (rev 261)
@@ -4,6 +4,16 @@
 #  from Mon, 03 May 2004 01:24:19 +0900
 #
 
+2005-09-26(Mon) 18:51:29 +0900  Koichi Sasada  <ko1 atdot.net>
+
+	* eval.c, compile.c, parse.y, vm.c, yarvcore.h :
+	 eval() works with binding (Env)
+
+	* vm.c : add th_set_eval_stack
+
+	* yarvtest/test_syn.rb : remove an assert "defined?(local_var)"
+
+
 2005-09-25(Sun) 19:30:59 +0900  Koichi Sasada  <ko1 atdot.net>
 
 	* benchmark/bm_vm2_send.rb : added

Modified: trunk/compile.c
===================================================================
--- trunk/compile.c	2005-09-25 10:36:25 UTC (rev 260)
+++ trunk/compile.c	2005-09-26 09:55:54 UTC (rev 261)
@@ -87,6 +87,7 @@
 
 static int set_exception_table(yarv_iseq_t *iseqobj);
 static int set_localtbl(yarv_iseq_t *iseqobj, ID* tbl);
+static int set_localtbl_eval(yarv_iseq_t *iseqobj, ID* tbl);
 static int set_arguments(VALUE self, yarv_iseq_t *iseqobj, LINK_ANCHOR *anchor, NODE *node);
 static NODE* set_block_local_tbl(VALUE self, yarv_iseq_t *iseqobj, NODE *node, LINK_ANCHOR *anchor);
 static int set_exception_tbl(yarv_iseq_t *iseqobj);
@@ -114,10 +115,7 @@
   if(iseqobj->type == ISEQ_TYPE_BLOCK){
     node = set_block_local_tbl(self, iseqobj, node, list_anchor);
   }
-  /*
-    compile_each return nested array.
-    ex) [insnA, [insnB, ope1], "label", ...]
-   */
+
   if(node && nd_type(node) == NODE_SCOPE){
     /* with node scope */
     NODE *sn_body = node->nd_next; /* sn: scope node */
@@ -210,6 +208,11 @@
       iseqobj->rewind_frame_size = iseqobj->local_size + REWIND_DSIZE();
       COMPILE(list_anchor, "top level node", node);
     }
+    else if(iseqobj->type == ISEQ_TYPE_EVAL){
+      iseqobj->rewind_frame_size = iseqobj->local_size + REWIND_DSIZE();
+      set_localtbl_eval(iseqobj, GET_THREAD()->top_local_tbl);
+      COMPILE(list_anchor, "eval node", node);
+    }
     else if(iseqobj->type == ISEQ_TYPE_RESCUE){
       set_exception_tbl(iseqobj);
       iseqobj->rewind_frame_size = iseqobj->local_size + REWIND_DSIZE();
@@ -971,7 +974,7 @@
       *ls    = iseqobj->local_size;
       return idx;
     }
-    iseqobj = iseqobj->parent_iseqobj;
+    iseqobj = iseqobj->parent_iseq;
     lv++;
   }
   return -1;
@@ -1048,11 +1051,9 @@
   return COMPILE_OK;
 }
 
-
-/**
-
- */
-int set_localtbl(yarv_iseq_t *iseqobj, ID* tbl){
+static int
+set_localtbl(yarv_iseq_t *iseqobj, ID* tbl)
+{
   int size;
   if(tbl){
     size = *tbl - 2 /* $~, $_ */ + 1 /* svar location */;
@@ -1068,10 +1069,30 @@
   return COMPILE_OK;
 }
 
+static int
+set_localtbl_eval(yarv_iseq_t *iseqobj, ID* tbl)
+{
+  int size;
+  if(tbl){
+    size = *tbl;
+  }
+  else{
+    size = 0;
+  }
+  if(tbl){
+    iseqobj->local_tbl = (ID*)ALLOC_N(ID*, size);
+    MEMCPY(iseqobj->local_tbl, tbl + 1, ID*, size);
+  }
+  iseqobj->local_size = size;
+  return COMPILE_OK;
+}
+
 /**
   ruby insn object array -> raw instruction sequence
  */
-static int set_sequence(yarv_iseq_t *iseqobj, LINK_ANCHOR *anchor){
+static int
+set_sequence(yarv_iseq_t *iseqobj, LINK_ANCHOR *anchor)
+{
   LABEL *lobj;
   INSN  *iobj;
   struct insn_info_struct *insn_info_tbl;
@@ -1233,12 +1254,16 @@
   return COMPILE_OK;
 }
 
-static int label_get_position(VALUE self){
+static int
+label_get_position(VALUE self)
+{
   LABEL *lobj = (LABEL *) self;
   return lobj->position;
 }
 
-int set_exception_table(yarv_iseq_t *iseqobj){
+static int
+set_exception_table(yarv_iseq_t *iseqobj)
+{
   VALUE *tptr, *ptr;
   int tlen, i;
   struct catch_table_entry *entry;
@@ -1279,7 +1304,9 @@
  *   def foo(a, b=expr1, c=expr2)
  *   => 
  */
-int set_optargs_table(yarv_iseq_t *iseqobj){
+static int
+set_optargs_table(yarv_iseq_t *iseqobj)
+{
   int i;
 
   if(iseqobj->arg_opts != 0){
@@ -1293,7 +1320,8 @@
 }
 
 static LINK_ELEMENT *
-get_destination_insn(INSN *iobj){
+get_destination_insn(INSN *iobj)
+{
   LABEL *lobj = (LABEL *)OPERAND_AT(iobj, 0);
   LINK_ELEMENT *list;
   
@@ -1308,7 +1336,8 @@
 }
 
 static LINK_ELEMENT *
-get_next_insn(INSN *iobj){
+get_next_insn(INSN *iobj)
+{
   LINK_ELEMENT *list = iobj->link.next;
   
   while(list){
@@ -1321,7 +1350,8 @@
 }
 
 static LINK_ELEMENT *
-get_prev_insn(INSN *iobj){
+get_prev_insn(INSN *iobj)
+{
   LINK_ELEMENT *list = iobj->link.prev;
   
   while(list){
@@ -1333,7 +1363,9 @@
   return 0;
 }
 
-static int iseq_optimize(yarv_iseq_t *iseqobj, LINK_ANCHOR *anchor){
+static int
+iseq_optimize(yarv_iseq_t *iseqobj, LINK_ANCHOR *anchor)
+{
   LINK_ELEMENT *list;
   /*
    *  useless jump elimination:
@@ -1408,8 +1440,10 @@
   return COMPILE_OK;
 }
 
-static INSN* new_unified_insn(yarv_iseq_t *iseqobj,
-                                     int insn_id, int size, LINK_ELEMENT *seq_list){
+static INSN*
+new_unified_insn(yarv_iseq_t *iseqobj,
+                 int insn_id, int size, LINK_ELEMENT *seq_list)
+{
   INSN *iobj = 0;
   LINK_ELEMENT *list = seq_list;
   int i, argc = 0;
@@ -1445,7 +1479,9 @@
  * label address resolving.
  * It's future work (if compile time was bottle neck).
  */
-static int iseq_insns_unification(yarv_iseq_t *iseqobj, LINK_ANCHOR *anchor){
+static int
+iseq_insns_unification(yarv_iseq_t *iseqobj, LINK_ANCHOR *anchor)
+{
 #if OPT_INSTRUCTIONS_UNIFICATION
   LINK_ELEMENT *list;
   INSN *iobj, *niobj;
@@ -1498,7 +1534,9 @@
 
 #include "opt_sc.inc"
 
-int insn_set_sc_state(INSN *iobj, int state){
+static int
+insn_set_sc_state(INSN *iobj, int state)
+{
   int nstate;
   int insn_id;
 
@@ -1533,7 +1571,9 @@
   return nstate;
 }
 
-int label_set_sc_state(LABEL *lobj, int state){
+static int
+label_set_sc_state(LABEL *lobj, int state)
+{
   if(lobj->sc_state != 0){
     if(lobj->sc_state != state){
       state = lobj->sc_state;
@@ -1549,7 +1589,9 @@
 
 #endif
 
-static int set_sequence_stackcaching(yarv_iseq_t *iseqobj, LINK_ANCHOR *anchor){
+static int
+set_sequence_stackcaching(yarv_iseq_t *iseqobj, LINK_ANCHOR *anchor)
+{
 #if OPT_STACK_CACHING
   LINK_ELEMENT *list;
   int state, insn_id;
@@ -1637,7 +1679,9 @@
 
 
 
-int compile_dstr(VALUE self, yarv_iseq_t *iseqobj, LINK_ANCHOR *ret, NODE *node){
+static int
+compile_dstr(VALUE self, yarv_iseq_t *iseqobj, LINK_ANCHOR *ret, NODE *node)
+{
   NODE *list = node->nd_next;
   VALUE lit  = node->nd_lit;
   int cnt = 0;
@@ -1663,11 +1707,13 @@
   return COMPILE_OK;
 }
 
-static yarv_iseq_t *get_root_iseq_object(yarv_iseq_t *iop){
+static yarv_iseq_t *
+get_root_iseq_object(yarv_iseq_t *iop)
+{
   yarv_iseq_t *iseqobj = iop;
   while(iseqobj){
-    if(iseqobj->parent_iseqobj){
-      iseqobj = iseqobj->parent_iseqobj;
+    if(iseqobj->parent_iseq){
+      iseqobj = iseqobj->parent_iseq;
     }
     else{
       return iseqobj;
@@ -1678,15 +1724,18 @@
   return 0;
 }
 
-static int get_root_iseq_localsize(yarv_iseq_t *iseqobj){
+static int
+get_root_iseq_localsize(yarv_iseq_t *iseqobj)
+{
   iseqobj = get_root_iseq_object(iseqobj);
   return iseqobj->local_size;
 }
 
-static int compile_branch_condition(VALUE self, yarv_iseq_t *iseqobj,
-                                    LINK_ANCHOR *ret, NODE *cond,
-                                    LABEL *then_label, LABEL *else_label){
-  
+static int
+compile_branch_condition(VALUE self, yarv_iseq_t *iseqobj,
+                         LINK_ANCHOR *ret, NODE *cond,
+                         LABEL *then_label, LABEL *else_label)
+{
   switch(nd_type(cond)){
   case NODE_NOT:
     compile_branch_condition(self, iseqobj, ret, cond->nd_body, else_label, then_label);
@@ -1715,8 +1764,10 @@
   return COMPILE_OK;
 }
 
-static int compile_array(VALUE self, yarv_iseq_t *iseqobj,
-                         LINK_ANCHOR *ret, NODE *node_root, VALUE opt_p){
+static int
+compile_array(VALUE self, yarv_iseq_t *iseqobj,
+              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);
@@ -1748,7 +1799,9 @@
   return COMPILE_OK;
 }
 
-static VALUE case_when_optimizable_literal(NODE *node){
+static VALUE
+case_when_optimizable_literal(NODE *node)
+{
   if(nd_type(node) == NODE_LIT){
     VALUE v     = node->nd_lit;
     VALUE klass = CLASS_OF(v);
@@ -1804,7 +1857,8 @@
 
 static int
 compile_massign(VALUE self, yarv_iseq_t *iseqobj, LINK_ANCHOR *ret,
-                NODE *rhsn, NODE *splatn, NODE *lhsn, int llen){
+                NODE *rhsn, NODE *splatn, NODE *lhsn, int llen)
+{
   if(lhsn != 0){
     compile_massign(self, iseqobj, ret, rhsn, splatn, lhsn->nd_next, llen + 1);
     make_masgn_lhs(self, iseqobj, ret, lhsn->nd_head);
@@ -1908,8 +1962,10 @@
   return COMPILE_OK;
 }
 
-static int defined_expr(VALUE self, yarv_iseq_t *iseqobj,
-                        LINK_ANCHOR *ret, NODE *node, LABEL *lfinish, VALUE needstr){
+static int
+defined_expr(VALUE self, yarv_iseq_t *iseqobj,
+             LINK_ANCHOR *ret, NODE *node, LABEL *lfinish, VALUE needstr)
+{
   char *estr = 0;
   
   switch(nd_type(node)){
@@ -2030,18 +2086,19 @@
 
 #define BUFSIZE 0x100
 
-static
-VALUE make_name_for_block(yarv_iseq_t *iseq){
+static VALUE
+make_name_for_block(yarv_iseq_t *iseq)
+{
   char buf[BUFSIZE];
-  if(iseq->parent_iseqobj == 0){
+  if(iseq->parent_iseq == 0){
     snprintf(buf, BUFSIZE, "block in %s", RSTRING(iseq->name)->ptr);
   }
   else{
     int level = 1;
     yarv_iseq_t *ip = iseq;
     while(1){
-      if(ip->parent_iseqobj){
-        ip = ip->parent_iseqobj;
+      if(ip->parent_iseq){
+        ip = ip->parent_iseq;
       }
       else{
         break;
@@ -2054,16 +2111,18 @@
   return rb_str_new2(buf);
 }
 
-static
-VALUE make_name_with_str(char *fmt, char *str){
+static VALUE
+make_name_with_str(char *fmt, char *str)
+{
   char buf[BUFSIZE];
   snprintf(buf, BUFSIZE, fmt, str);
   return rb_str_new2(buf);
 }
 
 
-static
-void add_ensure_iseq(LINK_ANCHOR *ret, yarv_iseq_t *iseq, VALUE self){
+static void
+add_ensure_iseq(LINK_ANCHOR *ret, yarv_iseq_t *iseq, VALUE self)
+{
   struct iseq_compile_data_ensure_node_stack *enlp = iseq->compile_data->ensure_node_stack;
   DECL_ANCHOR(ensure);
 
@@ -2085,7 +2144,9 @@
   node:  Ruby compiled node
   poped: This node will be poped
  */
-static int iseq_compile_each(VALUE self, 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;
@@ -2411,7 +2472,7 @@
       ADD_INSN1(ret, nd_line(node), throw, I2F(level | 0x02) /* TAG_BREAK */);
     }
     else{
-      yarv_iseq_t *ip = iseqobj->parent_iseqobj;
+      yarv_iseq_t *ip = iseqobj->parent_iseq;
       
       while(ip){
         level++;
@@ -2426,7 +2487,7 @@
           }
           goto break_by_jump;
         }
-        ip = ip->parent_iseqobj;
+        ip = ip->parent_iseq;
       }
       COMPILE_ERROR(("can't put break"));
     }
@@ -2446,7 +2507,7 @@
       ADD_INSNL(ret, nd_line(node), jump, iseqobj->compile_data->end_label);
     }
     else{
-      yarv_iseq_t *ip = iseqobj->parent_iseqobj;
+      yarv_iseq_t *ip = iseqobj->parent_iseq;
       while(ip){
         level = 0x8000;
         if(ip->type == ISEQ_TYPE_BLOCK){
@@ -2458,7 +2519,7 @@
           }
           break;
         }
-        ip = ip->parent_iseqobj;
+        ip = ip->parent_iseq;
       }
       if(ip != 0){
         COMPILE(ret, "next val", node->nd_stts);
@@ -2480,7 +2541,7 @@
       ADD_INSNL(ret, nd_line(node), jump, iseqobj->compile_data->start_label);
     }
     else{
-      yarv_iseq_t *ip = iseqobj->parent_iseqobj;
+      yarv_iseq_t *ip = iseqobj->parent_iseq;
       unsigned long level = 0x8000 | 0x4000;
       while(ip){
         if(ip->type == ISEQ_TYPE_BLOCK){
@@ -2489,7 +2550,7 @@
         else if(ip->compile_data->redo_label != 0){
           break;
         }
-        ip = ip->parent_iseqobj;
+        ip = ip->parent_iseq;
       }
       if(ip != 0){
         add_ensure_iseq(ret, iseqobj, self);
@@ -2653,7 +2714,6 @@
     
   case NODE_LASGN:{
     int idx = get_root_iseq_localsize(iseqobj) + 2 - node->nd_cnt;
-    
     debugs("lvar: %d\n", idx);
     COMPILE(ret, "lvalue", node->nd_value);
     
@@ -3125,7 +3185,7 @@
       }
       else if(is->type == ISEQ_TYPE_RESCUE ||
               is->type == ISEQ_TYPE_ENSURE){
-        is = is->parent_iseqobj;
+        is = is->parent_iseq;
       }
       else{
         COMPILE(ret, "return nd_stts(return val)", node->nd_stts);

Modified: trunk/eval.c
===================================================================
--- trunk/eval.c	2005-09-25 10:36:25 UTC (rev 260)
+++ trunk/eval.c	2005-09-26 09:55:54 UTC (rev 261)
@@ -278,6 +278,7 @@
   VALUE val;
   PUSH_TAG(0);
   if((state = EXEC_TAG()) == 0) {
+    GET_THREAD()->base_block = 0;
     val = yarvcore_eval_parsed((VALUE)ruby_eval_tree, rb_str_new2(ruby_sourcefile));
   }
   POP_TAG();
@@ -483,23 +484,6 @@
     }
 }
 
-static NODE*
-copy_node_scope(node, rval)
-    NODE *node;
-    NODE *rval;
-{
-    NODE *copy = NEW_NODE(NODE_SCOPE,0,rval,node->nd_next);
-
-    if (node->nd_tbl) {
-	copy->nd_tbl = ALLOC_N(ID, node->nd_tbl[0]+1);
-	MEMCPY(copy->nd_tbl, node->nd_tbl, ID, node->nd_tbl[0]+1);
-    }
-    else {
-	copy->nd_tbl = 0;
-    }
-    return copy;
-}
-
 #ifdef C_ALLOCA
 # define TMP_PROTECT NODE * volatile tmp__protect_tmp=0
 # define TMP_ALLOC(n)							\
@@ -1867,15 +1851,12 @@
 }
 
 static VALUE
-eval(self, src, scope, file, line)
-    VALUE self, src, scope;
-    char *file;
-    int line;
+eval(VALUE self, VALUE src, VALUE scope, char *file, int line)
 {
   volatile int safe = ruby_safe_level;
   int state;
   VALUE result;
-  
+
   if (file == 0) {
     ruby_set_current_source();
     file = ruby_sourcefile;
@@ -1884,7 +1865,37 @@
 
   PUSH_TAG(PROT_NONE);
   if ((state = EXEC_TAG()) == 0) {
-    NODE *node;
+    yarv_thread_t *th = GET_THREAD();
+    yarv_iseq_t *iseq;
+    
+    if(scope != Qnil){
+      yarv_env_t *env;
+      if(CLASS_OF(scope) == cYarvEnv){
+        /* do nothing */
+      }
+      else if(CLASS_OF(scope) == cYarvProc){
+        yarv_proc_t *proc;
+        GetProcVal(scope, proc);
+        scope = proc->envval;
+      }
+      else{
+        rb_raise(rb_eTypeError, "wrong argument type %s (expected Proc/Binding)",
+                 rb_obj_classname(scope));
+      }
+      GetEnvVal(scope, env);
+      th->base_block = &env->block;
+    }
+    else{
+      yarv_control_frame_t *cfp = YARV_PERVIOUS_CONTROL_FRAME(th->cfp);
+      th->base_block = GET_BLOCK_PTR_IN_CFP(cfp);
+      th->base_block->iseq = cfp->iseq;
+    }
+    
+    if((iseq = th->base_block->iseq->root_iseq) == 0){
+      iseq = th->base_block->iseq;
+    }
+    th->base_local_tbl  = iseq->local_tbl;
+    th->base_local_size = iseq->local_size;
     result = yarvcore_eval(0, src, rb_str_new2(file), INT2FIX(line));
   }
   POP_TAG();
@@ -3242,53 +3253,83 @@
 VALUE
 rb_dvar_defined(ID id)
 {
-  // TODO: fix me
+  yarv_thread_t *th = GET_THREAD();
+  yarv_iseq_t *iseq;
+
+  if(th->base_block &&
+     (iseq = th->base_block->iseq)){
+    while(iseq->type == ISEQ_TYPE_BLOCK ||
+          iseq->type == ISEQ_TYPE_RESCUE||
+          iseq->type == ISEQ_TYPE_ENSURE){
+      int i;
+      for(i=0; iseq->local_size; i++){
+        if(iseq->local_tbl[i] == id){
+          return Qtrue;
+        }
+      }
+      iseq = iseq->parent_iseq;
+    }
+  }
   return Qfalse;
 }
 
-int
-rb_scope_setup(len)
-  int len;
-{
-  // TODO: fix me (or remove me?)
-  return len > 0;
-}
-
 void
-rb_scope_setup_local_tbl(ID *tbl)
+rb_scope_setup_top_local_tbl(ID *tbl)
 {
+  yarv_thread_t *th = GET_THREAD();
   if(tbl){
-    if(GET_THREAD()->top_local_tbl){
-      xfree(GET_THREAD()->top_local_tbl);
+    if(th->top_local_tbl){
+      xfree(th->top_local_tbl);
+      th->top_local_tbl = 0;
     }
-    GET_THREAD()->top_local_tbl = tbl;
+    th->top_local_tbl = tbl;
   }
+  
+  /* clear dynamic parsing information */
+  th->base_local_tbl = 0;
+  th->base_local_size = 0;
 }
 
 int
-rb_scope_local_tbl_size(){
-  ID *tbl = GET_THREAD()->top_local_tbl;
-  return tbl ? tbl[0] : 0;
+rb_scope_base_local_tbl_size(){
+  yarv_thread_t *th = GET_THREAD();
+  
+  if(th->base_local_tbl){
+    return th->base_local_size + 2 /* $_, $~ */ - 1 /* svar */;
+  }
+  else{
+    return 0;
+  }
 }
 
 ID
-rb_scope_local_tbl_id(int i)
+rb_scope_base_local_tbl_id(int i)
 {
-  ID *tbl;
-  if(tbl = GET_THREAD()->top_local_tbl){
-    return tbl[i+1];
+  yarv_thread_t *th = GET_THREAD();
+
+  switch(i){
+  case 0: return rb_intern("$_");
+  case 1: return rb_intern("$~");
+  default:
+    return th->base_local_tbl[i-1 /* tbl[0] is reserved by svar */];
   }
-  return 0;
 }
 
 void
 rb_scope_set(int i, VALUE val)
 {
+  /* needed? */
   UNSUPPORTED(rb_scope_set);
 }
 
 int
 rb_dvar_current(){
-  return 0;
+  yarv_thread_t *th = GET_THREAD();
+  if(th->base_block){
+    return 1;
+  }
+  else{
+    return 0;
+  }
 }
 

Modified: trunk/eval_intern.h
===================================================================
--- trunk/eval_intern.h	2005-09-25 10:36:25 UTC (rev 260)
+++ trunk/eval_intern.h	2005-09-26 09:55:54 UTC (rev 261)
@@ -2,9 +2,6 @@
 #ifndef EVAL_INTERN_H_INCLUDED
 #define EVAL_INTERN_H_INCLUDED
 
-#define SDR2(cfp) vm_stack_dump_raw(GET_THREAD(), (cfp))
-#define SDR3() vm_stack_dump_raw(GET_THREAD(), GET_THREAD()->cfp)
-
 #define PASS_PASSED_BLOCK() \
   (GET_THREAD()->passed_block = (yarv_block_t *)GET_THREAD()->cfp->lfp[0])
 

Modified: trunk/eval_proc.c
===================================================================
--- trunk/eval_proc.c	2005-09-25 10:36:25 UTC (rev 260)
+++ trunk/eval_proc.c	2005-09-26 09:55:54 UTC (rev 261)
@@ -61,7 +61,8 @@
 rb_f_binding(self)
     VALUE self;
 {
-  return th_make_current_env_object(GET_THREAD());
+  return th_make_env_object(GET_THREAD(),
+                            YARV_PERVIOUS_CONTROL_FRAME(GET_THREAD()->cfp));
 }
 
 /*
@@ -135,7 +136,7 @@
   
   if((block = GC_GUARDED_PTR_REF(th->cfp->lfp[0])) != 0){
     cfp = th->cfp;
-    block = GC_GUARDED_PTR_REF(th->cfp->lfp[0]);
+    block = GC_GUARDED_PTR_REF(cfp->lfp[0]);
   }
   else{
     cfp = YARV_PERVIOUS_CONTROL_FRAME(th->cfp);
@@ -148,6 +149,7 @@
       rb_raise(rb_eArgError, "tried to create Proc object without a block");
     }
   }
+  cfp = YARV_PERVIOUS_CONTROL_FRAME(cfp);
   procval = th_make_proc(th, cfp, block);
 
   if(is_lambda){
@@ -195,7 +197,7 @@
 VALUE
 rb_block_proc()
 {
-    return proc_alloc(rb_cProc, Qfalse);
+  return proc_alloc(rb_cProc, Qfalse);
 }
 
 VALUE

Modified: trunk/insns.def
===================================================================
--- trunk/insns.def	2005-09-25 10:36:25 UTC (rev 260)
+++ trunk/insns.def	2005-09-26 09:55:54 UTC (rev 261)
@@ -1171,8 +1171,8 @@
       VALUE *sp;
       
       /* really? */
-      while(ip->parent_iseqobj){
-        ip = ip->parent_iseqobj;
+      while(ip->parent_iseq){
+        ip = ip->parent_iseq;
       }
 
       id    = rb_to_id(ip->name);
@@ -1192,8 +1192,8 @@
       VALUE *sp, *lp;
       int i;
 
-      while(ip->parent_iseqobj){
-        ip = ip->parent_iseqobj;
+      while(ip->parent_iseq){
+        ip = ip->parent_iseq;
       }
 
       id = rb_to_id(ip->name);

Modified: trunk/parse.y
===================================================================
--- trunk/parse.y	2005-09-25 10:36:25 UTC (rev 260)
+++ trunk/parse.y	2005-09-26 09:55:54 UTC (rev 261)
@@ -114,8 +114,7 @@
 };
 
 static int
-vtable_size(tbl)
-     struct vtable *tbl;
+vtable_size(struct vtable *tbl)
 {
   if((VALUE)tbl & ~3){
     return tbl->pos;
@@ -125,22 +124,24 @@
   }
 }
 
+#define VTBL_DEBUG 0
+
 static struct vtable *
-vtable_alloc(prev)
-     struct vtable *prev;
+vtable_alloc(struct vtable *prev)
 {
   struct vtable *tbl = ALLOC(struct vtable);
   tbl->pos = 0;
-  tbl->capa = 16;
+  tbl->capa = 8;
   tbl->tbl = ALLOC_N(ID, tbl->capa);
   tbl->prev = prev;
+  if(VTBL_DEBUG)printf("vtable_alloc: %p\n", tbl);
   return tbl;
 }
 
 static void
-vtable_free(tbl)
-     struct vtable * tbl;
+vtable_free(struct vtable * tbl)
 {
+  if(VTBL_DEBUG)printf("vtable_free: %p\n", tbl);
   if((VALUE)tbl & ~3){
     if(tbl->tbl){
       xfree(tbl->tbl);
@@ -152,13 +153,13 @@
 }
 
 static void
-vtable_add(tbl, id)
-  struct vtable *tbl;
-  ID id;
+vtable_add(struct vtable * tbl, ID id)
 {
   if(!((VALUE)tbl & ~3)){
     rb_bug("vtable_add: vtable is not allocated (%p)", tbl);
   }
+  if(VTBL_DEBUG)printf("vtable_add: %p, %s\n", tbl, rb_id2name(id));
+  
   if(tbl->pos == tbl->capa){
     tbl->capa = tbl->capa * 2;
     REALLOC_N(tbl->tbl, ID, tbl->capa);
@@ -167,13 +168,12 @@
 }
 
 static int
-vtable_included(tbl, id)
-  struct vtable *tbl;
-  ID id;
+vtable_included(struct vtable * tbl, ID id)
 {
   int i;
   if((VALUE)tbl & ~3){
     for(i=0; i<tbl->pos; i++){
+      
       if(tbl->tbl[i] == id){
         return 1;
       }
@@ -367,6 +367,8 @@
 #define local_id(id) local_id_gen(parser, id)
 static ID  *local_tbl_gen(struct parser_params*);
 #define local_tbl() local_tbl_gen(parser)
+static ID  *dyna_tbl_gen(struct parser_params*);
+#define dyna_tbl() dyna_tbl_gen(parser)
 static ID   internal_id(void);
 
 static int dyna_push_gen(struct parser_params*);
@@ -8177,25 +8179,33 @@
 }
 
 static ID*
-local_tbl_gen(parser)
-    struct parser_params *parser;
-{
-    int i, cnt = vtable_size(lvtbl->tbl);
-    if(cnt > 0){
-        ID *tbl = ALLOC_N(ID, cnt + 1);
-        tbl[0] = cnt;
-        for(i=0; i<cnt; i++){
-            tbl[i+1] = lvtbl->tbl->tbl[i];
-        }
-        return tbl;
+vtable_to_tbl(struct vtable *src){
+  int i, cnt = vtable_size(src);
+  if(cnt > 0){
+    ID *tbl = ALLOC_N(ID, cnt + 1);
+    tbl[0] = cnt;
+    for(i=0; i<cnt; i++){
+      tbl[i+1] = src->tbl[i];
     }
-    return 0;
+    return tbl;
+  }
+  return 0;
 }
 
+static ID*
+local_tbl_gen(struct parser_params *parser)
+{
+  return vtable_to_tbl(lvtbl->tbl);
+}
+
+static ID*
+dyna_tbl_gen(struct parser_params *parser)
+{
+  return vtable_to_tbl(lvtbl->dvars);
+}
+
 static int
-local_append_gen(parser, id)
-    struct parser_params *parser;
-    ID id;
+local_append_gen(struct parser_params *parser, ID id)
 {
     if (lvtbl->tbl == 0) {
 	lvtbl->tbl = vtable_alloc(0);
@@ -8209,24 +8219,21 @@
 }
 
 static int
-local_cnt_gen(parser, id)
-    struct parser_params *parser;
-    ID id;
+local_cnt_gen(struct parser_params *parser, ID id)
 {
-    int cnt, max;
+  int cnt, max;
+  if (id == 0) return vtable_size(lvtbl->tbl);
 
-    if (id == 0) return vtable_size(lvtbl->tbl);
-
-    for (cnt=0, max=vtable_size(lvtbl->tbl); cnt<max;cnt++) {
-	if (lvtbl->tbl->tbl[cnt] == id) return cnt;
+  for (cnt=0, max=vtable_size(lvtbl->tbl); cnt<max;cnt++) {
+    if (lvtbl->tbl->tbl[cnt] == id) {
+      return cnt;
     }
-    return local_append(id);
+  }
+  return local_append(id);
 }
 
 static int
-local_id_gen(parser, id)
-    struct parser_params *parser;
-    ID id;
+local_id_gen(struct parser_params *parser, ID id)
 {
     int i, max;
 
@@ -8236,35 +8243,36 @@
 
 
 extern int rb_dvar_current();
-extern int rb_scope_local_tbl_size _(());
-extern ID rb_scope_local_tbl_id _((int i));
-extern int rb_scope_setup _((int len));
-extern void rb_scope_setup_local_tbl _((ID *tbl));
+extern int rb_scope_base_local_tbl_size();
+extern ID  rb_scope_base_local_tbl_id(int i);
+extern void rb_scope_setup_top_local_tbl(ID *tbl);
 
 static void
-top_local_init_gen(parser)
-    struct parser_params *parser;
+top_local_init_gen(struct parser_params *parser)
 {
-    int i, cnt;
-    local_push(rb_dvar_current());
-    if(cnt = rb_scope_local_tbl_size()){
-        if(lvtbl->tbl == 0){
-            lvtbl->tbl = vtable_alloc(0);
-        }
-        for(i=0; i<cnt; i++){
-            vtable_add(lvtbl->tbl, rb_scope_local_tbl_id(i));
-        }
+  int i, cnt;
+  local_push(rb_dvar_current());
+  if(cnt = rb_scope_base_local_tbl_size()){
+    if(lvtbl->tbl == 0){
+      lvtbl->tbl = vtable_alloc(0);
     }
+    for(i=0; i<cnt; i++){
+      vtable_add(lvtbl->tbl, rb_scope_base_local_tbl_id(i));
+    }
+  }
 }
 
 static void
-top_local_setup_gen(parser)
-    struct parser_params *parser;
+top_local_setup_gen(struct parser_params *parser)
 {
-    if(rb_scope_setup(vtable_size(lvtbl->tbl))){
-        rb_scope_setup_local_tbl(local_tbl());
-    }
-    local_pop();
+  if(((VALUE)lvtbl->dvars & ~3)){
+    /* eval */
+    rb_scope_setup_top_local_tbl(dyna_tbl());
+  }
+  else{
+    rb_scope_setup_top_local_tbl(local_tbl());
+  }
+  local_pop();
 }
 
 static void

Modified: trunk/test.rb
===================================================================
--- trunk/test.rb	2005-09-25 10:36:25 UTC (rev 260)
+++ trunk/test.rb	2005-09-26 09:55:54 UTC (rev 261)
@@ -1,8 +1,18 @@
 
 def m
-  i = 1
+  a = 1
+  proc
+end
+a = 2
+eval 'p a', m{}
+
+__END__
+def m a
   binding
 end
 
-eval('p i', m)
+bind = m(1)
+3.times{
+  eval('p a+=1', bind)
+}
 

Modified: trunk/vm.c
===================================================================
--- trunk/vm.c	2005-09-25 10:36:25 UTC (rev 260)
+++ trunk/vm.c	2005-09-26 09:55:54 UTC (rev 261)
@@ -113,36 +113,47 @@
   return Qtrue;
 }
 
-
 VALUE
-thread_set_top_stack(VALUE self, VALUE iseqval)
+th_set_top_stack(yarv_thread_t *th, VALUE iseqval)
 {
   yarv_iseq_t *iseq;
-  yarv_thread_t *th;
+  GetISeqVal(iseqval, iseq);
 
-  GetThreadVal(self, th);
-  GetISeqVal(iseqval, iseq);
-  
   iseq->klass_nest_stack = rb_ary_push(rb_ary_new(), rb_cObject);
 
   /* for return */
   th_set_finish_env(th);
-  
-  return th_set_env(th, iseq, 
+
+  return th_set_env(th, iseq,
                     FRAME_MAGIC_TOP, ruby_top_self, 0,
                     iseq->iseq_encoded, th->cfp->sp, 0,
                     iseq->local_size, 0, 0);
 }
 
+VALUE
+th_set_eval_stack(yarv_thread_t *th, VALUE iseqval){
+  yarv_iseq_t *iseq;
+  yarv_block_t *block = th->base_block;
+  GetISeqVal(iseqval, iseq);
+
+  /* for return */
+  th_set_finish_env(th);
+  th_set_env(th, iseq,
+             FRAME_MAGIC_BLOCK, block->self, GC_GUARDED_PTR(block->dfp),
+             iseq->iseq_encoded, th->cfp->sp, block->lfp,
+             iseq->local_size, 0, 0);
+  return 0;
+}
+
 static VALUE
-th_make_env_object(yarv_thread_t *th, yarv_control_frame_t *cfp,
-                   VALUE *envptr, VALUE *endptr)
+th_make_env_each(yarv_thread_t *th, yarv_control_frame_t *cfp,
+                 VALUE *envptr, VALUE *endptr)
 {
   VALUE envval, penvval = 0;
   yarv_env_t *env;
   VALUE *nenvptr;
   int i, local_size;
-  
+
   if(ENV_IN_HEAP_P(envptr)){
     return ENV_VAL(envptr);
   }
@@ -153,11 +164,11 @@
     while(pcfp->dfp != penvptr){
       pcfp++;
     }
-    penvval = th_make_env_object(th, pcfp, penvptr, endptr);
+    penvval = th_make_env_each(th, pcfp, penvptr, endptr);
     cfp->lfp = pcfp->lfp;
     *envptr = GC_GUARDED_PTR(pcfp->dfp);
   }
-  
+
   /* allocate env */
   envval = rb_obj_alloc(cYarvEnv);
   GetEnvVal(envval, env);
@@ -173,32 +184,37 @@
   env->local_size = local_size;
   env->env = ALLOC_N(VALUE, env->env_size);
   env->prev_envval = penvval;
-
+  
   for(i=0; i<=local_size; i++){
     env->env[i] = envptr[-local_size + i];
     envptr[-local_size + i] = 0;
   }
   *envptr = envval; /* GC mark */
-  
+
   nenvptr = &env->env[i-1];
   nenvptr[1] = Qfalse; /* frame is not orphan */
   nenvptr[2] = Qundef; /* frame is in heap    */
   nenvptr[3] = envval; /* frame self */
   nenvptr[4] = penvval;/* frame prev env object */
-  
+
   /* reset lfp/dfp in cfp */
   cfp->dfp = nenvptr;
   if(envptr == endptr){
     cfp->lfp = nenvptr;
   }
+
+  /* as Binding */
+  env->block.self = cfp->self;
+  env->block.lfp  = cfp->lfp;
+  env->block.dfp  = cfp->dfp;
+  env->block.iseq = cfp->iseq;
   return envval;
 }
 
 VALUE
-th_make_current_env_object(yarv_thread_t *th)
+th_make_env_object(yarv_thread_t *th, yarv_control_frame_t *cfp)
 {
-  yarv_control_frame_t *cfp = th->cfp;
-  return th_make_env_object(th, cfp, cfp->dfp, cfp->lfp);
+  return th_make_env_each(th, cfp, cfp->dfp, cfp->lfp);
 }
 
 static VALUE
@@ -231,12 +247,13 @@
 
   if(GC_GUARDED_PTR_REF(*cfp->lfp) != 0){
     yarv_proc_t *p;
-    proc->blockprocval = th_make_proc_from_block(th, cfp, (yarv_block_t *)GC_GUARDED_PTR_REF(*cfp->lfp));
+    proc->blockprocval =
+      th_make_proc_from_block(th, cfp, (yarv_block_t *)GC_GUARDED_PTR_REF(*cfp->lfp));
     GetProcVal(proc->blockprocval, p);
     *cfp->lfp = GC_GUARDED_PTR(&p->block);
   }
 
-  envval = th_make_current_env_object(th);
+  envval = th_make_env_object(th, cfp);
 
   proc->block.self = block->self;
   proc->block.lfp  = block->lfp;
@@ -419,7 +436,6 @@
                  block->self, GC_GUARDED_PTR(block->dfp),
                  block->iseq->iseq_encoded, th->cfp->sp, block->lfp,
                  block->iseq->local_size, argc, argv);
-      //SDR2(th->cfp);
       val = th_eval_body(th);
     }
     else{
@@ -518,7 +534,6 @@
                proc->block.iseq->local_size, argc, argv);
   }
   //proc_dump_raw(proc);
-  //SDR2(th->cfp);
   
   return th_eval_body(th);
 }

Modified: trunk/yarv.h
===================================================================
--- trunk/yarv.h	2005-09-25 10:36:25 UTC (rev 260)
+++ trunk/yarv.h	2005-09-26 09:55:54 UTC (rev 261)
@@ -57,7 +57,8 @@
 
 VALUE th_invoke_proc(yarv_thread_t *th, yarv_proc_t *proc, int argc, VALUE *argv);
 VALUE th_make_proc(yarv_thread_t *th, yarv_control_frame_t *cfp, yarv_block_t *block);
-VALUE th_make_current_env_object(yarv_thread_t *th);
+VALUE th_make_env_object(yarv_thread_t *th, yarv_control_frame_t *cfp);
+VALUE yarvcore_eval(VALUE self, VALUE str, VALUE file, VALUE line);
 
 int yarv_block_given_p();
 

Modified: trunk/yarvcore.c
===================================================================
--- trunk/yarvcore.c	2005-09-25 10:36:25 UTC (rev 260)
+++ trunk/yarvcore.c	2005-09-26 09:55:54 UTC (rev 261)
@@ -85,30 +85,43 @@
 static yarv_thread_t *yarvCurrentRunningThread = 0;
 static VALUE yarvVM = Qnil;
 
-VALUE yarv_get_current_running_vm_value(){
+VALUE
+yarv_get_current_running_vm_value()
+{
   return yarvCurrentRunningThread->vm_value;
 }
 
-VALUE yarv_get_current_running_thread_value(){
+VALUE
+yarv_get_current_running_thread_value()
+{
   return yarvCurrentRunningThread->self;
 }
 
-yarv_vm_t *yarv_get_current_running_vm(){
+yarv_vm_t *
+yarv_get_current_running_vm()
+{
   return yarvCurrentRunningThread->vm;
 }
 
-yarv_thread_t *yarv_get_current_running_thread(){
+yarv_thread_t *
+yarv_get_current_running_thread()
+{
   return yarvCurrentRunningThread;
 }
 
-void yarv_set_current_running_thread(yarv_thread_t *th){
+void
+yarv_set_current_running_thread(yarv_thread_t *th)
+{
   yarvCurrentRunningThread = th;
 }
 
-VALUE th_invoke_yield(yarv_thread_t *th, int argc, VALUE *argv);
+VALUE
+th_invoke_yield(yarv_thread_t *th, int argc, VALUE *argv);
 
 /* rb_yield_values */
-VALUE yarv_yield_values(int argc, VALUE *argv){
+VALUE
+yarv_yield_values(int argc, VALUE *argv)
+{
   yarv_thread_t *th = GET_THREAD();
 
   if(argc == 1 && CLASS_OF(argv[0]) == rb_cValues){
@@ -123,25 +136,33 @@
                    int argc, VALUE *argv, NODE *body, int nosuper);
 
 /* rb_call0 continued for yarv function */
-VALUE yarv_call0(VALUE klass, VALUE recv, VALUE id, ID oid,
-                 int argc, VALUE *argv, NODE *body, int nosuper){
+VALUE
+yarv_call0(VALUE klass, VALUE recv, VALUE id, ID oid,
+           int argc, VALUE *argv, NODE *body, int nosuper)
+{
   return th_call0(GET_THREAD(), klass, recv, id, oid, argc, argv, body, nosuper);
 }
 
 
 VALUE th_call_super(yarv_thread_t *th, int argc, const VALUE *argv);
 
-VALUE yarv_call_super(int argc, const VALUE *argv){
+VALUE
+yarv_call_super(int argc, const VALUE *argv)
+{
   return th_call_super(GET_THREAD(), argc, argv);
 }
 
 VALUE th_backtrace(yarv_thread_t *th, int level);
 
-VALUE yarv_backtrace(int level){
+VALUE
+yarv_backtrace(int level)
+{
   return th_backtrace(GET_THREAD(), level);
 }
 
-VALUE yarv_caller(VALUE self, VALUE level){
+VALUE
+yarv_caller(VALUE self, VALUE level)
+{
   if(!IS_YARV_WORKING()){
     return rb_funcall(Qnil, rb_intern("caller"), 1, level);
   }
@@ -157,7 +178,9 @@
 
 static VALUE vm_eval(VALUE self, VALUE iseq);
 
-VALUE yarv_load(char *file){
+VALUE
+yarv_load(char *file)
+{
   NODE *node;
   VALUE argv[5];
   volatile VALUE iseq;
@@ -191,11 +214,15 @@
 
 VALUE *th_svar(yarv_thread_t *self, int cnt);
 
-VALUE *rb_svar(int cnt){
+VALUE *
+rb_svar(int cnt)
+{
   return th_svar(GET_THREAD(), cnt);
 }
 
-static VALUE compile_string(VALUE str, VALUE file, VALUE line){
+static VALUE
+compile_string(VALUE str, VALUE file, VALUE line)
+{
   NODE *node;
   node = rb_compile_string(StringValueCStr(file), str, NUM2INT(line));
 
@@ -208,7 +235,9 @@
 }
 
 
-static VALUE yarvcore_eval_iseq(VALUE iseq){
+static VALUE
+yarvcore_eval_iseq(VALUE iseq)
+{
   volatile VALUE vm;
   VALUE ret;
   vm = yarv_get_current_running_vm_value();
@@ -219,21 +248,36 @@
   return ret;
 }
 
-VALUE yarvcore_eval_parsed(VALUE node, VALUE file){
+VALUE
+yarvcore_eval_parsed(VALUE node, VALUE file)
+{
   VALUE argv[5];
   VALUE iseq;
   
   argv[0] = node;
-  argv[1] = rb_str_new2("<main>");
   argv[2] = file;
-  argv[3] = Qfalse;
-  argv[4] = ISEQ_TYPE_TOP;
+  
+  if(GET_THREAD()->base_block){
+    /* eval */
+    argv[1] = GET_THREAD()->base_block->iseq->name;
+    argv[3] = GET_THREAD()->base_block->iseq->self;
+    argv[4] = ISEQ_TYPE_EVAL;
+  }
+  else{
+    /* top */
+    argv[1] = rb_str_new2("<main>");
+    argv[3] = Qfalse;
+    argv[4] = ISEQ_TYPE_TOP;
+  }
   iseq = rb_class_new_instance(5, argv, cYarvISeq);
   return yarvcore_eval_iseq(iseq);
 }
 
-VALUE yarvcore_eval(VALUE self, VALUE str, VALUE file, VALUE line){
-  VALUE node = compile_string(str, file, line);
+VALUE
+yarvcore_eval(VALUE self, VALUE str, VALUE file, VALUE line)
+{
+  VALUE node;
+  node = compile_string(str, file, line);
   return yarvcore_eval_parsed(node, file);
 }
 
@@ -258,7 +302,9 @@
 /* InstructionSequence */
 /***********************/
 
-static void compile_data_free(struct iseq_compile_data *compile_data){
+static void
+compile_data_free(struct iseq_compile_data *compile_data)
+{
   if(compile_data){
     struct iseq_compile_data_storage *cur, *next;
     cur = compile_data->storage_head;
@@ -271,7 +317,9 @@
   }
 }
 
-static void iseq_free(void *ptr){
+static void
+iseq_free(void *ptr)
+{
   yarv_iseq_t *iseq;
   FREE_REPORT("-> iseq");
   
@@ -294,7 +342,9 @@
   FREE_REPORT("<- iseq");
 }
 
-static void iseq_mark(void *ptr){
+static void
+iseq_mark(void *ptr)
+{
   yarv_iseq_t *iseq;
   MARK_REPORT("-> iseq");
   if(ptr){
@@ -315,7 +365,9 @@
   MARK_REPORT("<- iseq");
 }
 
-static VALUE iseq_alloc(VALUE klass){
+static VALUE
+iseq_alloc(VALUE klass)
+{
   VALUE volatile obj;
   yarv_iseq_t *iseq;
 
@@ -324,10 +376,11 @@
   return obj;
 }
 
-static VALUE prepare_iseq_build(yarv_iseq_t *iseq,
-                                VALUE name, VALUE file_name,
-                                VALUE parent, VALUE type){
-  
+static VALUE
+prepare_iseq_build(yarv_iseq_t *iseq,
+                   VALUE name, VALUE file_name,
+                   VALUE parent, VALUE type)
+{
   iseq->name            = name;
   iseq->file_name       = file_name;
   iseq->iseq_mark_ary   = rb_ary_new();
@@ -369,11 +422,19 @@
   if(parent && CLASS_OF(parent) == cYarvISeq){
     yarv_iseq_t *piseq;
     GetISeqVal(parent, piseq);
-    iseq->parent_iseqobj = piseq;
+    iseq->parent_iseq = piseq;
+
+    while(piseq->parent_iseq){
+      piseq = piseq->parent_iseq;
+    }
+    iseq->root_iseq = piseq;
   }
   return Qtrue;
 }
-static VALUE cleanup_iseq_build(yarv_iseq_t *iseqobj){
+
+static VALUE
+cleanup_iseq_build(yarv_iseq_t *iseqobj)
+{
   VALUE err;
   err = iseqobj->compile_data->err_info;
   compile_data_free(iseqobj->compile_data);
@@ -386,26 +447,32 @@
   return Qtrue;
 }
 
-static VALUE iseq_init(VALUE self, VALUE node, VALUE name, VALUE file_name,
-                       VALUE parent, VALUE type){
-  yarv_iseq_t *iseqobj;
+static VALUE
+iseq_init(VALUE self, VALUE node, VALUE name, VALUE file_name,
+          VALUE parent, VALUE type)
+{
+  yarv_iseq_t *iseq;
   
-  GetISeqVal(self, iseqobj);
+  GetISeqVal(self, iseq);
 
-  prepare_iseq_build(iseqobj, name, file_name, parent, type);
+  iseq->self = self;
+  prepare_iseq_build(iseq, name, file_name, parent, type);
   iseq_compile(self, node);
-  cleanup_iseq_build(iseqobj);
-  
+  cleanup_iseq_build(iseq);
   return self;
 }
 
 VALUE iseq_assemble_setup(VALUE self, VALUE args, VALUE locals, VALUE ary);
 
-static VALUE iseq_assemble(VALUE self, VALUE args, VALUE locals, VALUE insn_ary){
+static VALUE
+iseq_assemble(VALUE self, VALUE args, VALUE locals, VALUE insn_ary)
+{
   return iseq_assemble_setup(self, args, locals, insn_ary);
 }
 
-VALUE iseq_inspect(VALUE self){
+VALUE
+iseq_inspect(VALUE self)
+{
   char   buff[0x100];
   yarv_iseq_t *iseqobj;
   
@@ -560,17 +627,23 @@
 }
 
 VALUE th_eval_body(yarv_thread_t *th);
-extern VALUE thread_set_top_stack(VALUE self, VALUE iseq);
+VALUE th_set_top_stack(yarv_thread_t *, VALUE iseq);
+VALUE th_set_eval_stack(yarv_thread_t *, VALUE iseq);
 
 static VALUE thread_eval(VALUE self, VALUE iseq){
   VALUE val;
   yarv_thread_t *th;
   GetThreadVal(self, th);
 
-  // TODO
-  thread_set_top_stack(self, iseq);
+  if(th->base_block){
+    th_set_eval_stack(th, iseq);
+    th->base_block = 0;
+  }
+  else{
+    th_set_top_stack(th, iseq);
+  }
   val = th_eval_body(th);
-
+  
   return val;
 }
 
@@ -579,7 +652,9 @@
 /* YarvEnv     */
 /***************/
 
-static void env_free(void *ptr){
+static void
+env_free(void *ptr)
+{
   yarv_env_t *env;
   FREE_REPORT("-> env");
   if(ptr){
@@ -590,7 +665,9 @@
   FREE_REPORT("<- env");
 }
 
-static void env_mark(void *ptr){
+static void
+env_mark(void *ptr)
+{
   yarv_env_t *env;
   MARK_REPORT("-> env");
   if(ptr){
@@ -600,11 +677,14 @@
       rb_gc_mark_locations(env->env, env->env + env->env_size);
     }
     MARK_UNLESS_NULL(env->prev_envval);
+    MARK_UNLESS_NULL(env->block.iseq->self);
   }
   MARK_REPORT("<- env");
 }
 
-static VALUE env_alloc(VALUE klass){
+static VALUE
+env_alloc(VALUE klass)
+{
   VALUE obj;
   yarv_env_t *env;
   obj = Data_Make_Struct(klass, yarv_env_t,
@@ -612,16 +692,14 @@
   return obj;
 }
 
-static VALUE env_eval(VALUE self, VALUE str){
-  
-  return ;
-}
 
 /***************/
 /* YarvProc    */
 /***************/
 
-static void proc_free(void *ptr){
+static void
+proc_free(void *ptr)
+{
   FREE_REPORT("-> proc");
   if(ptr){
     ruby_xfree(ptr);
@@ -629,7 +707,9 @@
   FREE_REPORT("<- proc");
 }
 
-static void proc_mark(void *ptr){
+static void
+proc_mark(void *ptr)
+{
   yarv_proc_t *proc;
   MARK_REPORT("-> proc");
   if(ptr){
@@ -640,7 +720,9 @@
   MARK_REPORT("<- proc");
 }
 
-static VALUE proc_alloc(VALUE klass){
+static VALUE
+proc_alloc(VALUE klass)
+{
   VALUE obj;
   yarv_proc_t *proc;
   obj = Data_Make_Struct(klass, yarv_proc_t,
@@ -650,10 +732,11 @@
 
 VALUE th_invoke_proc(yarv_thread_t *th, yarv_proc_t *proc, int argc, VALUE *argv);
 
-static VALUE proc_call(int argc, VALUE *argv, VALUE procval){
+static VALUE
+proc_call(int argc, VALUE *argv, VALUE procval)
+{
   yarv_proc_t *proc;
   GetProcVal(procval, proc);
-
   return th_invoke_proc(GET_THREAD(), proc, argc, argv);
 }
 

Modified: trunk/yarvcore.h
===================================================================
--- trunk/yarvcore.h	2005-09-25 10:36:25 UTC (rev 260)
+++ trunk/yarvcore.h	2005-09-26 09:55:54 UTC (rev 261)
@@ -108,6 +108,7 @@
 #define ISEQ_TYPE_CLASS  INT2FIX(4)
 #define ISEQ_TYPE_RESCUE INT2FIX(5)
 #define ISEQ_TYPE_ENSURE INT2FIX(6)
+#define ISEQ_TYPE_EVAL   INT2FIX(7)
 
 #define CATCH_TYPE_RESCUE INT2FIX(1)
 #define CATCH_TYPE_ENSURE INT2FIX(2)
@@ -167,6 +168,7 @@
 struct yarv_iseq_struct;
 
 struct yarv_iseq_struct{
+  VALUE  self;
   VALUE  name; /* String: iseq name */
   VALUE *iseq; /* iseq */
   VALUE *iseq_encoded;
@@ -237,8 +239,8 @@
   int                       catch_table_size;
   
   /* for child iseq */
-  struct yarv_iseq_struct *parent_iseqobj;
-  struct yarv_iseq_struct *root_iseqobj;
+  struct yarv_iseq_struct *parent_iseq;
+  struct yarv_iseq_struct *root_iseq;
   
   struct iseq_compile_data *compile_data;
 };
@@ -306,7 +308,11 @@
 
   /* passed via parse.y, eval.c (rb_scope_setup_local_tbl) */
   ID *top_local_tbl;
-  
+
+  /* eval env */
+  ID *base_local_tbl;
+  int base_local_size;
+  yarv_block_t *base_block;
 } yarv_thread_t;
 
 /** node -> yarv instruction sequence object */
@@ -314,8 +320,8 @@
 
 /** disassemble instruction sequence */
 VALUE iseq_disasm(VALUE self);
-VALUE iseq_disasm_insn(VALUE str, VALUE *iseq, int pos,
-                       yarv_iseq_t *iseqobj, VALUE child);
+VALUE iseq_disasm_insn(VALUE str, VALUE *iseqval, int pos,
+                       yarv_iseq_t *iseq, VALUE child);
 char* node_name(int node);
 
 
@@ -355,6 +361,7 @@
   int    env_size;
   int    local_size;
   VALUE  prev_envval; /* for GC mark */
+  yarv_block_t block;
 } yarv_env_t;
 
 
@@ -404,10 +411,10 @@
 #define DEFINED_METHOD INT2FIX(5)
 #define DEFINED_YIELD  INT2FIX(6)
 
-
 /* for debug */
 extern void vm_stack_dump_raw(yarv_thread_t *, yarv_control_frame_t *);
-#define SDR() vm_stack_dump_raw(GET_THREAD(), GET_THREAD()->cfp)
+#define SDR()     vm_stack_dump_raw(GET_THREAD(), GET_THREAD()->cfp)
+#define SDR2(cfp) vm_stack_dump_raw(GET_THREAD(), (cfp))
 
 #include "yarv.h"
 

Modified: trunk/yarvtest/test_syn.rb
===================================================================
--- trunk/yarvtest/test_syn.rb	2005-09-25 10:36:25 UTC (rev 260)
+++ trunk/yarvtest/test_syn.rb	2005-09-26 09:55:54 UTC (rev 261)
@@ -259,11 +259,11 @@
       defined?(nil) + defined?(self) +
         defined?(true) + defined?(false)
     }
+    #ae %q{
+    #  a = 1
+    #  defined?(a) # yarv returns "in block" in eval context
+    #}
     ae %q{
-      a = 1
-      defined?(a)
-    }
-    ae %q{
       defined?(@a)
     }
     ae %q{


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

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