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

yarv-diff:187

From: ko1 atdot.net
Date: 30 Dec 2005 18:19:45 -0000
Subject: [yarv-diff:187] r345 - in trunk: . rb yarvtest

Author: ko1
Date: 2005-12-31 03:19:44 +0900 (Sat, 31 Dec 2005)
New Revision: 345

Modified:
   trunk/ChangeLog
   trunk/eval.c
   trunk/eval_intern.h
   trunk/eval_proc.c
   trunk/rb/mklog.rb
   trunk/test.rb
   trunk/vm.c
   trunk/yarvcore.c
   trunk/yarvcore.h
   trunk/yarvtest/test_bin.rb
   trunk/yarvtest/test_eval.rb
Log:
	* eval.c (eval), eval_proc.c (rb_f_binding) : save klass, etc to
	binding and use it at eval

	* eval_intern.h : ditto

	* yarvtest/test_eval.rb : add tests for above

	* yarvcore.c (th_get_special_cref) : added

	* yarvcore.h : add a prototype of above

	* vm.c (th_get_cref) : refactoring

	* vm.c (eval_get_ev_const) : fix SEGV at A::B (A is not class/module)
	([yarv-dev:758])

	* yarvtest/test_bin.rb : add a test for above

	* rb/mklog.rb : use external diff command and show function name



Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2005-12-30 10:19:18 UTC (rev 344)
+++ trunk/ChangeLog	2005-12-30 18:19:44 UTC (rev 345)
@@ -4,6 +4,29 @@
 #  from Mon, 03 May 2004 01:24:19 +0900
 #
 
+2005-12-31(Sat) 03:11:14 +0900  Koichi Sasada  <ko1 atdot.net>
+
+	* eval.c (eval), eval_proc.c (rb_f_binding) : save klass, etc to
+	binding and use it at eval
+
+	* eval_intern.h : ditto
+
+	* yarvtest/test_eval.rb : add tests for above
+
+	* yarvcore.c (th_get_special_cref) : added
+
+	* yarvcore.h : add a prototype of above
+
+	* vm.c (th_get_cref) : refactoring
+
+	* vm.c (eval_get_ev_const) : fix SEGV at A::B (A is not class/module)
+	([yarv-dev:758])
+
+	* yarvtest/test_bin.rb : add a test for above
+
+	* rb/mklog.rb : use external diff command and show function name
+
+
 2005-12-30(Fri) 19:07:51 +0900  Koichi Sasada  <ko1 atdot.net>
 
 	* yarvcore.c, yarvcore.h, eval.c, eval_proc.c : support

Modified: trunk/eval.c
===================================================================
--- trunk/eval.c	2005-12-30 10:19:18 UTC (rev 344)
+++ trunk/eval.c	2005-12-30 18:19:44 UTC (rev 345)
@@ -1903,6 +1903,7 @@
   int state;
   VALUE result;
   yarv_binding_t *bind = 0;
+  yarv_thread_t *th = GET_THREAD();
 
   if (file == 0) {
     ruby_set_current_source();
@@ -1912,7 +1913,6 @@
 
   PUSH_TAG(PROT_NONE);
   if((state = EXEC_TAG()) == 0){
-    yarv_thread_t *th = GET_THREAD();
     yarv_iseq_t *iseq;
     VALUE iseqval;
 
@@ -1955,11 +1955,25 @@
       bind->env = th_make_env_object(th, th->cfp);
     }
 
+    if(bind){
+      rb_thread_push_klass(th, bind->klass, 0, bind->visibility);
+      if(bind->cref_stack){
+        /* TODO: */
+      }
+    }
+    
     /* kick */
     result = th_eval_body(th);
   }
   POP_TAG();
-
+  
+  if(bind){
+    rb_thread_pop_klass(th);
+    if(bind->cref_stack){
+      /* TODO: */
+    }
+  }
+  
   if(state){
     if(state == TAG_RAISE){
       if(strcmp(file, "(eval)") == 0){

Modified: trunk/eval_intern.h
===================================================================
--- trunk/eval_intern.h	2005-12-30 10:19:18 UTC (rev 344)
+++ trunk/eval_intern.h	2005-12-30 18:19:44 UTC (rev 345)
@@ -288,6 +288,7 @@
 rb_thread_t rb_vm_curr_thread();
 VALUE th_compile(yarv_thread_t *th, VALUE str, VALUE file, VALUE line);
 
+VALUE th_get_special_cref(yarv_thread_t *th, yarv_control_frame_t *cfp);
 VALUE th_get_cref(yarv_thread_t *th, yarv_iseq_t *iseq, yarv_control_frame_t *cfp);
 
 static yarv_control_frame_t *

Modified: trunk/eval_proc.c
===================================================================
--- trunk/eval_proc.c	2005-12-30 10:19:18 UTC (rev 344)
+++ trunk/eval_proc.c	2005-12-30 18:19:44 UTC (rev 345)
@@ -69,6 +69,10 @@
   
   GetBindingVal(bindval, bind);
   bind->env = th_make_env_object(th, cfp);
+
+  bind->klass = rb_ary_entry(th->klass_stack, -1);
+  bind->visibility = rb_ary_entry(th->visibility_stack, -1);
+  bind->cref_stack = th_get_special_cref(th, cfp);
   return bindval;
 }
 

Modified: trunk/rb/mklog.rb
===================================================================
--- trunk/rb/mklog.rb	2005-12-30 10:19:18 UTC (rev 344)
+++ trunk/rb/mklog.rb	2005-12-30 18:19:44 UTC (rev 345)
@@ -1,6 +1,12 @@
 files = []
-`svn diff`.each{|line|
-  if /\+\+\+ (.+)\t\(.+\)/ =~ line
+file = nil
+`svn diff --diff-cmd 'diff' -x '-u6 -p'`.each{|line|
+  case line
+  when /  .+  \s+((\w+)|(?:\w+\s+(\w+)))\(/
+    func = $2 || $3
+    files << "#{file} (#{func})"
+  when /\+\+\+ (.+)\t\(.+\)/
+    file = $1
     files << $1
   end
   puts line

Modified: trunk/test.rb
===================================================================
--- trunk/test.rb	2005-12-30 10:19:18 UTC (rev 344)
+++ trunk/test.rb	2005-12-30 18:19:44 UTC (rev 345)
@@ -1,14 +1,7 @@
-class C
-  def m
-    self.class.class_eval %q{
-      module M
-        a = 1
-        $b = binding
-      end
-    }
-  end
-end
-C.new.m
+C = 1; C::D
+
+__END__
+
 p eval('a', $b)
 
 

Modified: trunk/vm.c
===================================================================
--- trunk/vm.c	2005-12-30 10:19:18 UTC (rev 344)
+++ trunk/vm.c	2005-12-30 18:19:44 UTC (rev 345)
@@ -764,15 +764,28 @@
  * vm main loop helper functions
  */
 
+
 VALUE
+th_get_special_cref(yarv_thread_t *th, yarv_control_frame_t *cfp)
+{
+  NODE *node;
+  if(((VALUE)(node = (NODE*)cfp->lfp[-1])) != Qnil &&
+     node->nd_file){
+    return (VALUE)node->nd_file;
+  }
+  else{
+    return 0;
+  }
+}
+
+VALUE
 th_get_cref(yarv_thread_t *th, yarv_iseq_t *iseq, yarv_control_frame_t *cfp)
 {
   VALUE cref;
   NODE *node;
 
-  if(((VALUE)(node = (NODE*)cfp->lfp[-1])) != Qnil &&
-     node->nd_file){
-    cref = (VALUE)node->nd_file;
+  if((cref = th_get_special_cref(th, cfp))){
+    /* */
   }
   else if(iseq->cref_stack){
     cref = iseq->cref_stack;
@@ -856,6 +869,14 @@
     }
   }
   else{
+    switch (TYPE(klass)) {
+    case T_CLASS:
+    case T_MODULE:
+      break;
+    default:
+      rb_raise(rb_eTypeError, "%s is not a class/module",
+               RSTRING(rb_obj_as_string(klass))->ptr);
+    }
     if(is_defined){
       return rb_const_defined(klass, id);
     }

Modified: trunk/yarvcore.c
===================================================================
--- trunk/yarvcore.c	2005-12-30 10:19:18 UTC (rev 344)
+++ trunk/yarvcore.c	2005-12-30 18:19:44 UTC (rev 345)
@@ -960,6 +960,7 @@
   yarv_binding_t *bind;
   obj = Data_Make_Struct(klass, yarv_binding_t,
                          binding_mark, binding_free, bind);
+  bind->cref_stack = 0;
   return obj;
 }
 
@@ -1021,9 +1022,13 @@
 #if OPT_INLINE_METHOD_CACHE
     "[inline method cache] "
 #endif
-      ;
 
+#if OPT_BLOCKINLINING
+    "[block inlining] "
+#endif
+;
 
+
 void Init_yarvcore(){
 
 #include "rev.inc"

Modified: trunk/yarvcore.h
===================================================================
--- trunk/yarvcore.h	2005-12-30 10:19:18 UTC (rev 344)
+++ trunk/yarvcore.h	2005-12-30 18:19:44 UTC (rev 345)
@@ -444,7 +444,10 @@
 
 typedef struct{
   VALUE env;
+  
+  VALUE klass;
   VALUE cref_stack;
+  int visibility;
 } yarv_binding_t;
 
 

Modified: trunk/yarvtest/test_bin.rb
===================================================================
--- trunk/yarvtest/test_bin.rb	2005-12-30 10:19:18 UTC (rev 344)
+++ trunk/yarvtest/test_bin.rb	2005-12-30 18:19:44 UTC (rev 345)
@@ -180,6 +180,17 @@
       remove_const :A
       remove_const :Const
     end
+
+    ae %q{
+      C = 1
+      begin
+        C::D
+      rescue TypeError
+        :ok
+      else
+        :ng
+      end
+    }
   end
 
   def test_constant2

Modified: trunk/yarvtest/test_eval.rb
===================================================================
--- trunk/yarvtest/test_eval.rb	2005-12-30 10:19:18 UTC (rev 344)
+++ trunk/yarvtest/test_eval.rb	2005-12-30 18:19:44 UTC (rev 345)
@@ -189,6 +189,17 @@
       end
       C.new.m
     }
+    ae %q{
+      class C
+        $b = binding
+      end
+      eval %q{
+        def m
+          :ok
+        end
+      }, $b
+      p C.new.m
+    }
   end
 end
 


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

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