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

yarv-diff:59

From: ko1 atdot.net
Date: 29 Jul 2005 04:28:53 -0000
Subject: [yarv-diff:59] r214 - trunk

Author: ko1
Date: 2005-07-29 13:28:52 +0900 (Fri, 29 Jul 2005)
New Revision: 214

Modified:
   trunk/ChangeLog
   trunk/Changes
   trunk/compile.c
   trunk/compile.h
   trunk/extconf.rb
   trunk/insnhelper.h
   trunk/insns.def
   trunk/test.rb
   trunk/vm.c
   trunk/vm_dump.c
   trunk/vm_evalbody.h
   trunk/yarv.h
   trunk/yarvcore.c
   trunk/yarvcore.h
   trunk/yarvsubst.c
Log:
	* yarvcore.h : fix yarv_iseq_t to pass VC (cl)

	* vm_dump.c : ditto

	* compile.h : ditto

	* insnhelper.h : ditto

	* vm_evalbody.h : include 'math.h'

	* insns.def, vm.c : raise error when yield without block

	* vm.c : implement thread_backtrace

	* vm.c, yarvsubst.c, yarv.h : implement thread_yield_light_prepare and
	thread_yield_light_invoke

	* yarvcore.c : Integer#times uses yarv specific version



Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2005-07-28 12:38:24 UTC (rev 213)
+++ trunk/ChangeLog	2005-07-29 04:28:52 UTC (rev 214)
@@ -4,6 +4,28 @@
 #  from Mon, 03 May 2004 01:24:19 +0900
 #
 
+2005-07-29(Fri) 13:20:19 +0900  Koichi Sasada  <ko1 atdot.net>
+
+	* yarvcore.h : fix yarv_iseq_t to pass VC (cl)
+
+	* vm_dump.c : ditto
+
+	* compile.h : ditto
+
+	* insnhelper.h : ditto
+
+	* vm_evalbody.h : include 'math.h'
+
+	* insns.def, vm.c : raise error when yield without block
+
+	* vm.c : implement thread_backtrace
+
+	* vm.c, yarvsubst.c, yarv.h : implement thread_yield_light_prepare and
+	thread_yield_light_invoke
+
+	* yarvcore.c : Integer#times uses yarv specific version
+
+
 2005-07-28(Thu) 21:35:09 +0900  Koichi Sasada  <ko1 atdot.net>
 
 	* yarvcore.c : add another mark function for thread/stack

Modified: trunk/Changes
===================================================================
--- trunk/Changes	2005-07-28 12:38:24 UTC (rev 213)
+++ trunk/Changes	2005-07-29 04:28:52 UTC (rev 214)
@@ -4,9 +4,10 @@
 
 * build options
   * rename options and add --disable-opts, --disable-opt-unify
+  * please check options by "ruby extconf.rb --help"
 
 * VM generator (rb/insns2vm.rb)
-  * fix unification algorithm (generate all combination)
+  * fix a unification algorithm (generate all combination)
 
 * compiler
   * re-write and change data structure (GC free) used by compiler
@@ -22,6 +23,7 @@
 * YASM
   * unsupported temporarily
 
+
 = 0.2.0
 
 * some bug fixes

Modified: trunk/compile.c
===================================================================
--- trunk/compile.c	2005-07-28 12:38:24 UTC (rev 213)
+++ trunk/compile.c	2005-07-29 04:28:52 UTC (rev 214)
@@ -98,6 +98,7 @@
 #define REWIND_DSIZE()  1
 #define MREWIND_DSIZE() 2
 
+
 VALUE iseq_compile(VALUE self, VALUE narg){
   DECL_ANCHOR(list_anchor);
   yarv_iseq_t *iseqobj;

Modified: trunk/compile.h
===================================================================
--- trunk/compile.h	2005-07-28 12:38:24 UTC (rev 213)
+++ trunk/compile.h	2005-07-29 04:28:52 UTC (rev 214)
@@ -187,7 +187,7 @@
 
 #define DECL_ANCHOR(name) \
   LINK_ANCHOR  name##_body__ = {{0,}, &name##_body__.anchor}; \
-  LINK_ANCHOR *name = & name##_body__;
+  LINK_ANCHOR *name = & name##_body__
 
 #endif	// _COMPILER_H_INCLUDED_
 

Modified: trunk/extconf.rb
===================================================================
--- trunk/extconf.rb	2005-07-28 12:38:24 UTC (rev 213)
+++ trunk/extconf.rb	2005-07-29 04:28:52 UTC (rev 214)
@@ -2,10 +2,11 @@
 
 if( ARGV.include?("--help") )
   print <<-EOF
-  --help             print this messages
-  --enable-OPTION    enable yarv option
-  --disable-OPTION   disable yarv option
-  --disable-opts     disable all optimization
+  --help              print this messages
+  --enable-OPTION     enable yarv option
+  --disable-OPTION    disable yarv option
+  --disable-opts      disable all optimization
+  --disable-opt-unifs disable unification optimization
   
 OPTION:
   

Modified: trunk/insnhelper.h
===================================================================
--- trunk/insnhelper.h	2005-07-28 12:38:24 UTC (rev 213)
+++ trunk/insnhelper.h	2005-07-29 04:28:52 UTC (rev 214)
@@ -150,7 +150,7 @@
 #define GET_BLOCK_PTR() ((yarv_block_t *)(GET_LFP()[0] & ~0x03))
 
 #define CHECK_STACK_OVERFLOW(th, cfp, margin) \
-  (((void *)(cfp)->sp) + (margin) >= ((void *)cfp))
+  (((VALUE *)(cfp)->sp) + (margin) >= ((VALUE *)cfp))
 
 #define GET_BLOCK_PTR_IN_CFP(cfp) ((yarv_block_t *)(&(cfp)->self))
 #define GET_CFP_FROM_BLOCK_PTR(b) \

Modified: trunk/insns.def
===================================================================
--- trunk/insns.def	2005-07-28 12:38:24 UTC (rev 213)
+++ trunk/insns.def	2005-07-29 04:28:52 UTC (rev 214)
@@ -1196,6 +1196,10 @@
   yarv_iseq_t *iseq;
   int i;
   
+  if(block == 0){
+    localjump_error("no block given", Qnil, 0);
+  }
+
   iseq = block->iseq;
 
   if(BUILTIN_TYPE(iseq) != T_NODE){
@@ -1694,8 +1698,9 @@
       double div, mod;
       
       /* copied from numeric.c#flodivmod */
-#if defined(HAVE_FMOD) && !__x86_64__ /* temporary */
+#if 0 && defined(HAVE_FMOD) && !__x86_64__ /* temporary */
       mod = fmod(x, y);
+      printf("-- %f %% %f = %f\n", x, y, mod);
 #else
       {
         double z;

Modified: trunk/test.rb
===================================================================
--- trunk/test.rb	2005-07-28 12:38:24 UTC (rev 213)
+++ trunk/test.rb	2005-07-29 04:28:52 UTC (rev 214)
@@ -7,15 +7,72 @@
 $line = __LINE__ + 3
 ###########################################################
 $prog =<<'__EOP__'
+
+3.times{|i|
+  p i
+}
+
+__END__
 def m
-  p :m
+3.times{
+  4.times{
+    5.times{
+      return caller 0
+    }
+  }
+}
 end
 
-p 1
 m
-p 2
 
 __END__
+def m
+  1.times{
+    raise
+  }
+end
+
+def iter
+  yield
+end
+
+begin
+  m
+rescue => e
+  p e
+  p e.backtrace
+end
+
+
+
+__END__
+def m
+  begin
+    raise
+  rescue => e
+    p e.backtrace
+  end
+end
+
+def mm
+  caller 0
+end
+
+def iter
+  yield
+end
+
+begin
+  iter{
+    raise
+  }
+rescue => e
+  e.backtrace
+end
+
+
+__END__
+
 3.times{|bl|
   break 10
 }

Modified: trunk/vm.c
===================================================================
--- trunk/vm.c	2005-07-28 12:38:24 UTC (rev 213)
+++ trunk/vm.c	2005-07-29 04:28:52 UTC (rev 214)
@@ -26,7 +26,11 @@
 
 VALUE th_eval_body(yarv_thread_t *th);
 
+#ifdef OPT_STACK_CACHING
+static VALUE yarv_finish_insn_seq[1] = {BIN(finish_SC_ax_ax)};
+#else
 static VALUE yarv_finish_insn_seq[1] = {BIN(finish)};
+#endif
 
 /* imporeted from eval.c */
 struct cache_entry {		/* method hash table. */
@@ -317,10 +321,11 @@
   return th_call0(th, klass, recv, id, id, argc, argv, body, nosuper);
 }
 
+
 VALUE thread_call_super(VALUE self, int argc, const VALUE *argv){
   yarv_thread_t *th;
   GetThreadVal(self, th);
-  th_call_super(th, argc, argv);
+  return th_call_super(th, argc, argv);
 }
 
 
@@ -377,15 +382,62 @@
 
 VALUE thread_yield_light_prepare(VALUE self, int argc, VALUE *argv,
                                  struct yarv_yield_data *data){
-  rb_bug("thread_yield_light_prepare");
-  return Qundef;
+  yarv_thread_t *th;
+  yarv_control_frame_t *cfp;
+  yarv_block_t *block;
+
+  GetThreadVal(self, th);
+  cfp = th->cfp;
+  
+  data->th    = th;
+  data->block = block = GC_GUARDED_PTR_REF(cfp->lfp[0]);
+
+  if(block == 0){
+    rb_bug("block is not given");
+  }
+  else{
+    if(BUILTIN_TYPE(block->iseq) != T_NODE){
+      th_set_finish_env(th);
+      th_set_env(th, block->iseq, FRAME_MAGIC_BLOCK,
+                 block->self, GC_GUARDED_PTR(block->dfp),
+                 block->iseq->ISEQ_MEMBER, block->lfp,
+                 block->iseq->local_size, argc, argv);
+
+      data->local_size = block->iseq->local_size;
+      data->pc = block->iseq->ISEQ_MEMBER;
+      data->sp = th->cfp->sp;
+      th->cfp+=2; // pop, pop
+    }
+    else{
+      //val = thread_invoke_yield_cfunc(th, block, argc, argv);
+    }
+  }
+  return Qtrue;
 }
 
 
-VALUE thread_yield_light_invoke(VALUE self, int argc, VALUE *argv,
+VALUE thread_yield_light_invoke(int argc, VALUE *argv,
                                 struct yarv_yield_data *data){
-  rb_bug("thread_yield_light_invoke");
-  return Qundef;
+  VALUE val;
+  yarv_thread_t *th = data->th;
+  int i;
+  
+  if(BUILTIN_TYPE(data->block->iseq) != T_NODE){
+    th->cfp -= 2;
+    th->cfp->pc = data->pc;
+    // th->cfp->sp = data->sp;
+    
+    for(i=0; i<argc; i++){
+      th->cfp->dfp[i - data->local_size] = argv[i];
+    }
+
+    val = th_eval_body(th);
+    (th->cfp-1)->pc--;
+  }
+  else{
+    val = Qundef;
+  }
+  return val;
 }
 
 
@@ -453,11 +505,81 @@
 }
 
 
-VALUE thread_backtrace(VALUE th, int level){
-  return rb_ary_new();
+static
+VALUE th_backtrace(yarv_thread_t *th, int lev){
+  VALUE ary = rb_ary_new();
+  char buf[BUFSIZE];
+  yarv_control_frame_t *cfp = th->cfp;
+  yarv_control_frame_t *top_of_cfp = (void *)(th->stack + th->stack_size);
+  top_of_cfp--;
+
+  // printf("%d\n", lev);
+
+  if(lev < 0){
+    /* TODO ?? */
+    ary = rb_ary_new();
+  }
+  else{
+    while(lev-->=0){
+      cfp++;
+      if(cfp >= top_of_cfp){
+        return Qnil;
+      }
+    }
+    ary = rb_ary_new();
+  }
+
+  while(cfp < top_of_cfp){
+    if(cfp->iseq != 0){
+      if(cfp->pc != 0){
+        int line_no, i;
+        int pos = cfp->pc - cfp->iseq->ISEQ_MEMBER;
+
+        for(i=0; i<cfp->iseq->insn_info_size; i++){
+          if(cfp->iseq->insn_info_tbl[i].position == pos){
+            line_no = cfp->iseq->insn_info_tbl[i-1].line_no;
+            // sendpos = iseq->insn_info_tbl[i-1].position;
+            goto found;
+          }
+        }
+        rb_bug("thread_backtrace: unkown instruction (%d)", pos);
+      found:
+        if(cfp->magic != FRAME_MAGIC_TOP
+           //&& cfp->magic != FRAME_MAGIC_BLOCK
+           ){
+          snprintf(buf, BUFSIZ, "%s:%d:in `%s'",
+                   RSTRING(cfp->iseq->file_name)->ptr,
+                   line_no, RSTRING(cfp->iseq->name)->ptr);
+        }
+        else{
+          /* top */
+          snprintf(buf, BUFSIZ, "%s:%d",
+                   RSTRING(cfp->iseq->file_name)->ptr, line_no);
+        }
+      }
+      else{
+        /* TODO */
+        struct cmethod_info *cmi = (void *)cfp->iseq;
+        snprintf(buf, BUFSIZE, "::in `%s'", //"%s:%d:in `%s'",
+                 // "(c)", 0,
+                 rb_id2name(cmi->id));
+      }
+      rb_ary_push(ary, rb_str_new2(buf));
+    }
+    cfp++;
+  }
+
+  return ary;
 }
 
+VALUE thread_backtrace(VALUE self, int level){
+  yarv_thread_t *th;
+  GetThreadVal(self, th);
+  return th_backtrace(th, level);
+}
 
+
+
 /*
  *
  * vm main loop helper functions
@@ -701,6 +823,36 @@
 /*********************************************************/
 /*********************************************************/
 
+NORETURN(static void localjump_error(const char*, VALUE, int));
+static void
+localjump_error(mesg, value, reason)
+    const char *mesg;
+    VALUE value;
+    int reason;
+{
+  VALUE exc = rb_exc_new2(rb_const_get(rb_cObject, rb_intern("LocalJumpError")), mesg);
+  ID id;
+
+  rb_iv_set(exc, "@exit_value", value);
+  switch (reason) {
+  case TAG_BREAK:
+    id = rb_intern("break"); break;
+  case TAG_REDO:
+    id = rb_intern("redo"); break;
+  case TAG_RETRY:
+    id = rb_intern("retry"); break;
+  case TAG_NEXT:
+    id = rb_intern("next"); break;
+  case TAG_RETURN:
+    id = rb_intern("return"); break;
+  default:
+    id = rb_intern("noreason"); break;
+  }
+  rb_iv_set(exc, "@reason", ID2SYM(id));
+  rb_exc_raise(exc);
+}
+
+
 VALUE yarv_unredefined_flag = 0x01;
 
 #include "vm_evalbody.h"
@@ -944,7 +1096,6 @@
       }
     }
   }
-  
   POP_TAG();
   return result;
 }

Modified: trunk/vm_dump.c
===================================================================
--- trunk/vm_dump.c	2005-07-28 12:38:24 UTC (rev 213)
+++ trunk/vm_dump.c	2005-07-29 04:28:52 UTC (rev 214)
@@ -211,6 +211,7 @@
   int pc = -1;
   int lfp = cfp->lfp - th->stack;
   int dfp = cfp->dfp - th->stack;
+  int cfpi;
 
   if(cfp->iseq && !CMETHOD_INFO_P(cfp->iseq)){
     pc = cfp->pc - cfp->iseq->ISEQ_MEMBER;
@@ -219,7 +220,7 @@
   if(lfp < 0 || lfp > th->stack_size) lfp = -1;
   if(dfp < 0 || dfp > th->stack_size) dfp = -1;
   
-  int cfpi = ((yarv_control_frame_t *)(th->stack + th->stack_size)) - cfp;
+  cfpi = ((yarv_control_frame_t *)(th->stack + th->stack_size)) - cfp;
   printf("  [PC] %04d, [SP] %04d, [LFP] %04d, [DFP] %04d, [CFP] %04d\n",
          pc, cfp->sp - th->stack, lfp, dfp, cfpi);
 }

Modified: trunk/vm_evalbody.h
===================================================================
--- trunk/vm_evalbody.h	2005-07-28 12:38:24 UTC (rev 213)
+++ trunk/vm_evalbody.h	2005-07-29 04:28:52 UTC (rev 214)
@@ -2,6 +2,8 @@
  * this file is included by vm.c
  */
 
+#include <math.h>
+
 #if VMDEBUG > 0
 #define DECL_SC_REG(type, r, reg) register type reg_##r
 

Modified: trunk/yarv.h
===================================================================
--- trunk/yarv.h	2005-07-28 12:38:24 UTC (rev 213)
+++ trunk/yarv.h	2005-07-29 04:28:52 UTC (rev 214)
@@ -1,5 +1,11 @@
 #include <ruby.h>
+#include <node.h>
+#include "yarvcore.h"
 
+#ifndef _YARV_H_INCLUDED_
+#define _YARV_H_INCLUDED_
+
+
 VALUE yarv_yield _((VALUE val));
 
 /* original API */
@@ -10,16 +16,16 @@
 
 VALUE yarv_get_current_running_thread _(());
 
-
 struct yarv_yield_data{
-  VALUE *lfp;
-  VALUE *dfp;
-  VALUE *cfp;
-  VALUE *sp_start;
+  yarv_thread_t *th;
+  yarv_block_t *block;
+  VALUE *pc;
   VALUE *sp;
-  VALUE *pc;
   int local_size;
 };
 
 VALUE thread_yield_light_prepare _((VALUE self, int argc, VALUE *argv,
                                     struct yarv_yield_data *data));
+
+
+#endif

Modified: trunk/yarvcore.c
===================================================================
--- trunk/yarvcore.c	2005-07-28 12:38:24 UTC (rev 213)
+++ trunk/yarvcore.c	2005-07-29 04:28:52 UTC (rev 214)
@@ -654,7 +654,6 @@
   return Qnil;
 }
 
-
 VALUE constant_pool_pool;
 
 VALUE yarv_Array_each();
@@ -766,7 +765,7 @@
   rb_define_global_function("yarv_caller", yarv_caller, 1);
   
   /* Integer#times */
-  // rb_define_method(rb_cInteger, "times", yarv_Integer_times, 0);
+  rb_define_method(rb_cInteger, "times", yarv_Integer_times, 0);
   
   /* Array#each */
   // rb_define_method(rb_cArray, "each", yarv_Array_each, 0);
@@ -803,7 +802,6 @@
   idThrowState     = rb_intern("#__ThrowState__");
   idThrowBackDFP   = rb_intern("#__ThrowBackDFP__");
   idThrowObject    = rb_intern("#__ThrowObject__");
-
   
   constant_pool_pool = rb_ary_new();
   rb_global_variable(&constant_pool_pool);

Modified: trunk/yarvcore.h
===================================================================
--- trunk/yarvcore.h	2005-07-28 12:38:24 UTC (rev 213)
+++ trunk/yarvcore.h	2005-07-29 04:28:52 UTC (rev 214)
@@ -101,7 +101,8 @@
   Data_Get_Struct(obj, yarv_iseq_t, tobj)
 
 
-typedef struct yarv_iseq_struct yarv_iseq_t;
+struct yarv_iseq_struct;
+
 struct yarv_iseq_struct{
   VALUE  name; /* String: iseq name */
   VALUE *iseq; /* iseq */
@@ -175,13 +176,16 @@
   int                       catch_table_size;
   
   /* for child iseq */
-  yarv_iseq_t *parent_iseqobj;
-  yarv_iseq_t *root_iseqobj;
+  struct yarv_iseq_struct *parent_iseqobj;
+  struct yarv_iseq_struct *root_iseqobj;
   
   struct iseq_compile_data *compile_data;
 };
 
+typedef struct yarv_iseq_struct yarv_iseq_t;
 
+
+
 #define GetVMVal(obj, tobj) \
   Data_Get_Struct(obj, yarv_vm_t, tobj)
 
@@ -314,10 +318,6 @@
 #define GC_GUARDED_PTR_REF(p) ((void *)(((VALUE)p) & ~0x03))
 #define GC_GUARDED_PTR_P(p)   (((VALUE)p) & 0x01)
 
-
-#include "yarv.h"
-
-
 #define YARV_METHOD_NODE NODE_ERRINFO
 
 
@@ -328,6 +328,7 @@
 #define DEFINED_CONST  INT2FIX(4)
 #define DEFINED_METHOD INT2FIX(5)
 
+#include "yarv.h"
 
 #endif	// _YARVCORE_H_INCLUDED_
 

Modified: trunk/yarvsubst.c
===================================================================
--- trunk/yarvsubst.c	2005-07-28 12:38:24 UTC (rev 213)
+++ trunk/yarvsubst.c	2005-07-29 04:28:52 UTC (rev 214)
@@ -28,9 +28,10 @@
       struct yarv_yield_data data;
       
       thread_yield_light_prepare(th, 1, &val, &data);
+      
       for(i=0; i<end; i++){
         val = LONG2FIX(i);
-        thread_yield_light_invoke(th, 1, &val, &data);
+        thread_yield_light_invoke(1, &val, &data);
       }
     }
     else{


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

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