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

yarv-diff:211

From: ko1 atdot.net
Date: 7 Feb 2006 09:07:04 -0000
Subject: [yarv-diff:211] r369 - in trunk: . test/ruby

Author: ko1
Date: 2006-02-07 18:07:04 +0900 (Tue, 07 Feb 2006)
New Revision: 369

Modified:
   trunk/ChangeLog
   trunk/compile.c
   trunk/insns.def
   trunk/test.rb
   trunk/test/ruby/test_system.rb
   trunk/thread.c
   trunk/vm.c
   trunk/vm_dump.c
   trunk/yarv.h
   trunk/yarvcore.c
Log:
	* compile.c, insns.def : support BEGIN{} and add preexe instruction

	* insns.def : fix getspecial/setspecial instructions
	to catch up svar change

	* test/ruby/test_system.rb : remove stopper

	* thread.c (rb_thread_fd_writable) : add a debug output

	* thread.c (rb_thread_wait_fd) : add a debug output

	* vm.c (lfp_svar) : refactoring and fix some problems

	* vm_dump.c (yarv_bug) : add branch

	* yarv.h : remove unused declarations

	* yarvcore.c (vm_free) : VM object should not free by GC



Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2006-02-07 05:44:51 UTC (rev 368)
+++ trunk/ChangeLog	2006-02-07 09:07:04 UTC (rev 369)
@@ -4,6 +4,28 @@
 #  from Mon, 03 May 2004 01:24:19 +0900
 #
 
+2006-02-07(Tue) 17:58:18 +0900  Koichi Sasada  <ko1 atdot.net>
+
+	* compile.c, insns.def : support BEGIN{} and add preexe instruction
+
+	* insns.def : fix getspecial/setspecial instructions
+	to catch up svar change
+
+	* test/ruby/test_system.rb : remove stopper
+
+	* thread.c (rb_thread_fd_writable) : add a debug output
+
+	* thread.c (rb_thread_wait_fd) : add a debug output
+
+	* vm.c (lfp_svar) : refactoring and fix some problems
+
+	* vm_dump.c (yarv_bug) : add branch
+
+	* yarv.h : remove unused declarations
+
+	* yarvcore.c (vm_free) : VM object should not free by GC
+
+
 2006-02-07(Tue) 14:42:25 +0900  Koichi Sasada  <ko1 atdot.net>
 
 	* eval.c, eval_load.c : remove rb_thread_start_1()

Modified: trunk/compile.c
===================================================================
--- trunk/compile.c	2006-02-07 05:44:51 UTC (rev 368)
+++ trunk/compile.c	2006-02-07 09:07:04 UTC (rev 369)
@@ -4249,8 +4249,17 @@
     ADD_INSN (ret, 0, opt_checkenv);
     break;
   }
+  case NODE_PRELUDE:{
+    VALUE iseqval = NEW_ISEQVAL(node->nd_head,
+                                rb_str_new2("BEGIN{}"),
+                                ISEQ_TYPE_TOP);
+    ADD_INSN1(ret, nd_line(node), preexe, iseqval);
+    ADD_INSN (ret, nd_line(node), pop);
+    COMPILE_(ret, "prelude body", node->nd_body, poped);
+    break;
+  }
   default:
-    COMPILE_ERROR(("BUG: unknown node: %s", node_name(type)));
+    COMPILE_ERROR(("BUG: unknown node (default): %s", node_name(type)));
     return Qnil;
   }
 

Modified: trunk/insns.def
===================================================================
--- trunk/insns.def	2006-02-07 05:44:51 UTC (rev 368)
+++ trunk/insns.def	2006-02-07 09:07:04 UTC (rev 369)
@@ -82,30 +82,13 @@
 ()
 (VALUE val)
 {
-  NODE *node = (NODE*) *(GET_LFP() - 1);
 
-  if((VALUE)node == Qnil){
-    val = Qnil;
+  if(type == 0){
+    VALUE *pv = lfp_svar(GET_LFP(), idx);
+    val = *pv;
   }
-  else if(type == 0){
-    if(idx == 0){
-      val = node->u1.value;
-    }
-    else if(idx == 1){
-      val = node->u2.value;
-    }
-    else{
-      VALUE ary = node->u3.value;
-      if(ary){
-        val = rb_ary_entry(ary, idx);
-      }
-      else{
-        val = Qnil;
-      }
-    }
-  }
   else{
-    VALUE backref = node->u2.value;
+    VALUE backref = *lfp_svar(GET_LFP(), 1);
     if(type & 0x01){
       switch (type >> 1){
       case '&':
@@ -141,23 +124,8 @@
 (VALUE obj)
 ()
 {
-  NODE *node = (NODE*) *(GET_LFP() - 1);
-  if((VALUE)node == Qnil){
-    *(GET_LFP() - 1) = (VALUE)(node = NEW_IF(0, 0, 0));
-  }
-  if(idx == 0){
-    node->u1.value = obj;
-  }
-  else if(idx == 1){
-    node->u2.value = obj;
-  }
-  else{
-    VALUE ary = node->u3.value;
-    if(ary == 0){
-      ary = node->u3.value = rb_ary_new();
-    }
-    rb_ary_store(ary, idx, obj);
-  }
+  VALUE *pv = lfp_svar(GET_LFP(), idx);
+  *pv = obj;
 }
 
 /**
@@ -1022,6 +990,25 @@
 
 /**
   @c setting
+  @e BEGIN{}
+  @j BEGIN{}
+ */
+DEFINE_INSN
+preexe
+(BLOCKISEQ blockiseq)
+()
+(VALUE dummy)
+{
+  /* invoke block */
+  th_set_env(th, blockiseq, FRAME_MAGIC_TOP, GET_SELF(),
+             0, blockiseq->iseq_encoded, GET_SP(), 0,
+             blockiseq->local_size, 0, 0);
+  RESTORE_REGS();
+  NEXT_INSN();
+}
+
+/**
+  @c setting
   @e END{}
   @j END{}
  */

Modified: trunk/test/ruby/test_system.rb
===================================================================
--- trunk/test/ruby/test_system.rb	2006-02-07 05:44:51 UTC (rev 368)
+++ trunk/test/ruby/test_system.rb	2006-02-07 09:07:04 UTC (rev 369)
@@ -1,11 +1,4 @@
 require 'test/unit'
-class TestSystem < Test::Unit::TestCase
-  def test_0
-    assert false, "BEGIN{} syntax not supported yet"
-  end
-end
-=begin
-require 'test/unit'
 require 'envutil'
 
 class TestSystem < Test::Unit::TestCase
@@ -72,4 +65,3 @@
     assert_equal("", eval('"#{}"', nil, __FILE__, __LINE__))
   end
 end
-=end

Modified: trunk/test.rb
===================================================================
--- trunk/test.rb	2006-02-07 05:44:51 UTC (rev 368)
+++ trunk/test.rb	2006-02-07 09:07:04 UTC (rev 369)
@@ -1,4 +1,67 @@
+print "!!!"
 
+__END__
+def m
+  eval('BEGIN{return true}')
+end
+m
+
+__END__
+
+
+BEGIN{
+  BEGIN{
+  }
+}
+
+__END__
+p :a
+
+class C
+x = 10
+BEGIN{
+  p :y
+}
+p x
+end
+
+__END__
+eval %q{
+  BEGIN{
+    p 1
+  }
+}
+__END__
+
+1.times{
+  /a(b)(c)d/ =~ 'xyzabcdefgabcdefg'
+  p [$1, $2, $3, $~.class, $&, $`, $', $+]
+}
+__END__
+
+/(a)/ =~ 'a'
+p $1
+__END__
+t = nil
+      "this must not print
+      Type: NUM
+      123
+      456
+      Type: ARP
+      aaa
+      bbb
+      \f
+      this must not print
+      hoge
+      Type: ARP
+      aaa
+      bbb
+      ".each{|l|
+        if (t = l[/^Type: (.*)/, 1])..(/^\f/ =~ l)
+          p [t, l]
+        end
+      }
+__END__
       /a(b)(c)d/ =~ 'xyzabcdefgabcdefg'
       [$1, $2, $3, $~.class, $&, $`, $', $+]
 

Modified: trunk/thread.c
===================================================================
--- trunk/thread.c	2006-02-07 05:44:51 UTC (rev 368)
+++ trunk/thread.c	2006-02-07 09:07:04 UTC (rev 369)
@@ -1277,7 +1277,7 @@
 
   FD_ZERO(&set);
   FD_SET (fd, &set);
-  
+  thread_debug("rb_thread_wait_fd (%d)\n", fd);
   while(result <= 0){
     GVL_UNLOCK_RANGE(result = select(fd+1, &set, 0, 0, 0));
   }
@@ -1291,7 +1291,8 @@
 
   FD_ZERO(&set);
   FD_SET (fd, &set);
-  
+
+  thread_debug("rb_thread_fd_writable (%d)\n", fd);
   while(result <= 0){
     GVL_UNLOCK_RANGE(result = select(fd+1, 0, &set, 0, 0));
   }

Modified: trunk/vm.c
===================================================================
--- trunk/vm.c	2006-02-07 05:44:51 UTC (rev 368)
+++ trunk/vm.c	2006-02-07 09:07:04 UTC (rev 369)
@@ -651,19 +651,14 @@
     val->v1 = val->v2 = val->v3 = Qnil;
     lfp[-1] = (VALUE)val;
   }
-  
-  if(cnt == 0){
-    return &val->v1;
-  }
-  else if(cnt == 1){
-    return &val->v2;
-  }
-  else if(cnt == -1){
-    return &val->basic.klass;
-  }
-  else{
+
+  switch(cnt){
+  case -1: return &val->basic.klass;
+  case  0: return &val->v1;
+  case  1: return &val->v2;
+  default:{
     VALUE ary;
-    if((ary = val->v3) == 0){
+    if((ary = val->v3) == Qnil){
       ary = val->v3 = rb_ary_new();
     }
     if(RARRAY(ary)->len <= cnt){
@@ -671,8 +666,10 @@
     }
     return &RARRAY(ary)->ptr[cnt];
   }
+  }
 }
 
+
 VALUE *
 th_cfp_svar(yarv_control_frame_t *cfp, int cnt)
 {

Modified: trunk/vm_dump.c
===================================================================
--- trunk/vm_dump.c	2006-02-07 05:44:51 UTC (rev 368)
+++ trunk/vm_dump.c	2006-02-07 09:07:04 UTC (rev 369)
@@ -494,13 +494,19 @@
   return Qnil;
 }
 
+
+
 void
 yarv_bug(){
   yarv_thread_t *th = GET_THREAD();
-  VALUE bt = th_backtrace(th, 0);
-  int i;
-  for(i=0; i<RARRAY(bt)->len; i++){
-    dp(RARRAY(bt)->ptr[i]);
+  VALUE bt;
+
+  if(GET_VM()){
+    int i;
+    bt = th_backtrace(th, 0);
+    for(i=0; i<RARRAY(bt)->len; i++){
+      dp(RARRAY(bt)->ptr[i]);
+    }
+    SDR();
   }
-  SDR();
 }

Modified: trunk/yarv.h
===================================================================
--- trunk/yarv.h	2006-02-07 05:44:51 UTC (rev 368)
+++ trunk/yarv.h	2006-02-07 09:07:04 UTC (rev 369)
@@ -72,19 +72,6 @@
 
 void rb_vm_change_state();
 
-struct yarv_yield_data{
-  yarv_thread_t *th;
-  yarv_block_t *block;
-  VALUE *pc;
-  VALUE *sp;
-  VALUE spbuff;
-  int argc;
-  int local_size;
-};
-
-VALUE thread_yield_light_prepare(VALUE self, int argc, VALUE *argv,
-                                 struct yarv_yield_data *data);
-
 VALUE th_invoke_yield(yarv_thread_t *th, int argc, VALUE *argv);
 
 VALUE th_call0(yarv_thread_t *th, VALUE klass, VALUE recv,

Modified: trunk/yarvcore.c
===================================================================
--- trunk/yarvcore.c	2006-02-07 05:44:51 UTC (rev 368)
+++ trunk/yarvcore.c	2006-02-07 09:07:04 UTC (rev 369)
@@ -554,7 +554,10 @@
     native_thread_cleanup(ptr);
 
     st_free_table(vmobj->living_threads);
-    ruby_xfree(ptr);
+    // TODO: MultiVM Instance
+    // VM object should not be cleaned by GC
+    // ruby_xfree(ptr);
+    // theYarvVM = 0;
   }
   FREE_REPORT("<- vm");
 }


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

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