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

yarv-diff:131

From: ko1 atdot.net
Date: 14 Nov 2005 15:49:30 -0000
Subject: [yarv-diff:131] r288 - in trunk: . yarvtest

Author: ko1
Date: 2005-11-15 00:49:30 +0900 (Tue, 15 Nov 2005)
New Revision: 288

Modified:
   trunk/ChangeLog
   trunk/compile.c
   trunk/error.c
   trunk/eval.c
   trunk/eval_intern.h
   trunk/eval_load.c
   trunk/eval_thread.c
   trunk/gc.c
   trunk/insns.def
   trunk/test.rb
   trunk/vm.c
   trunk/vm.h
   trunk/vm_dump.c
   trunk/vm_macro.def
   trunk/yarvcore.c
   trunk/yarvcore.h
   trunk/yarvtest/test_block.rb
   trunk/yarvtest/test_syn.rb
Log:
2005-11-15(Tue) 00:42:49 +0900  Koichi Sasada  <ko1 atdot.net>

	* eval.c : support rb_frame_pop() and rb_frame_callee(),
	add rb_sourcefile(), rb_souceline(),
	

	* compile.c : support postposition while/until,
	fix block parameter index

	* yarvtest/test_syn.rb : add tests for above

	* yarvcore.c : fix env_mark

	* vm.h, yarvcore.h : move vm.h#cmethod_info to
	 yarvcore.h#yarv_cmethod_info

	* vm.c : add th_get_sourceline()

	* eval_intern.h : fix PASS_PASSED_BLOCK()

	* eval_load.c : fix re-enter require (temporalily)

	* insns.def : permit re-open class when superclass is same



Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2005-11-10 16:29:24 UTC (rev 287)
+++ trunk/ChangeLog	2005-11-14 15:49:30 UTC (rev 288)
@@ -4,6 +4,31 @@
 #  from Mon, 03 May 2004 01:24:19 +0900
 #
 
+2005-11-15(Tue) 00:42:49 +0900  Koichi Sasada  <ko1 atdot.net>
+
+	* eval.c : support rb_frame_pop() and rb_frame_callee(),
+	add rb_sourcefile(), rb_souceline(),
+	
+
+	* compile.c : support postposition while/until,
+	fix block parameter index
+
+	* yarvtest/test_syn.rb : add tests for above
+
+	* yarvcore.c : fix env_mark
+
+	* vm.h, yarvcore.h : move vm.h#cmethod_info to
+	 yarvcore.h#yarv_cmethod_info
+
+	* vm.c : add th_get_sourceline()
+
+	* eval_intern.h : fix PASS_PASSED_BLOCK()
+
+	* eval_load.c : fix re-enter require (temporalily)
+
+	* insns.def : permit re-open class when superclass is same
+
+
 2005-11-11(Fri) 01:20:15 +0900  Koichi Sasada  <ko1 atdot.net>
 
 	* common.mk : add "allload" rule

Modified: trunk/compile.c
===================================================================
--- trunk/compile.c	2005-11-10 16:29:24 UTC (rev 287)
+++ trunk/compile.c	2005-11-14 15:49:30 UTC (rev 288)
@@ -880,7 +880,6 @@
     default:
       rb_ary_push(vars, ID2SYM(rb_intern("#blp")));
       debugi("block 1arg (auto)", rb_intern("#blp"));
-
       iseqobj->argc = 1;
       break;
     }
@@ -988,7 +987,8 @@
 
     /* for 1.x compatibility */
     default:{
-      ADD_INSN2(anchor, nd_line(node), getdynamic, I2F(1), I2F(0)); /* first param, current level*/
+      /* first param, current level*/
+      ADD_INSN2(anchor, nd_line(node), getdynamic, I2F(iseqobj->local_size), I2F(0));
       set_block_initializer(self, iseqobj, nargs, anchor);
       break;
     }
@@ -2487,7 +2487,8 @@
     LABEL *prev_end_label     = iseqobj->compile_data->end_label;
     LABEL *prev_redo_label    = iseqobj->compile_data->redo_label;
     VALUE prev_loopval_popped = iseqobj->compile_data->loopval_popped;
-    struct iseq_compile_data_ensure_node_stack *enlp = iseqobj->compile_data->ensure_node_stack;
+    struct iseq_compile_data_ensure_node_stack *enlp =
+      iseqobj->compile_data->ensure_node_stack;
 
     LABEL * next_label  = iseqobj->compile_data->start_label =
       NEW_LABEL(nd_line(node)); /* next  */
@@ -2500,7 +2501,9 @@
     iseqobj->compile_data->loopval_popped = poped;
     iseqobj->compile_data->ensure_node_stack = 0;
 
-    ADD_INSNL(ret, nd_line(node), jump, next_label);
+    if(node->nd_state){
+      ADD_INSNL(ret, nd_line(node), jump, next_label);
+    }
 
     ADD_LABEL(ret, redo_label);
     COMPILE_ (ret, "while body", node->nd_body, 1);
@@ -2526,7 +2529,6 @@
     ADD_CATCH_ENTRY(CATCH_TYPE_NEXT, redo_label, break_label,  0, 0, next_label);
     ADD_CATCH_ENTRY(CATCH_TYPE_REDO, redo_label, break_label,  0, 0, redo_label);
     
-    
     iseqobj->compile_data->start_label = prev_start_label;
     iseqobj->compile_data->end_label   = prev_end_label;
     iseqobj->compile_data->redo_label  = prev_redo_label;

Modified: trunk/error.c
===================================================================
--- trunk/error.c	2005-11-10 16:29:24 UTC (rev 287)
+++ trunk/error.c	2005-11-14 15:49:30 UTC (rev 288)
@@ -27,18 +27,21 @@
 
 int ruby_nerrs;
 
+const char *rb_sourcefile();
+int rb_sourceline();
+
 static int
 err_position(char *buf, long len)
 {
     ruby_set_current_source();
-    if (!ruby_sourcefile) {
+    if (!rb_sourcefile()) {
 	return 0;
     }
-    else if (ruby_sourceline == 0) {
-	return snprintf(buf, len, "%s: ", ruby_sourcefile);
+    else if (rb_sourceline() == 0) {
+	return snprintf(buf, len, "%s: ", rb_sourcefile());
     }
     else {
-	return snprintf(buf, len, "%s:%d: ", ruby_sourcefile, ruby_sourceline);
+	return snprintf(buf, len, "%s:%d: ", rb_sourcefile(), rb_sourceline());
     }
 }
 

Modified: trunk/eval.c
===================================================================
--- trunk/eval.c	2005-11-10 16:29:24 UTC (rev 287)
+++ trunk/eval.c	2005-11-14 15:49:30 UTC (rev 288)
@@ -1826,14 +1826,24 @@
 ID
 rb_frame_callee()
 {
-  UNSUPPORTED(rb_frame_callee);
-  return 0;
+  yarv_iseq_t *iseq = GET_THREAD()->cfp->iseq;
+  if(!iseq){
+    return 0;
+  }
+  if(CMETHOD_INFO_P(iseq)){
+    struct yarv_cmethod_info *cmi = (void *)iseq;
+    return cmi->id;
+  }
+  else{
+    return rb_intern(RSTRING(iseq->name)->ptr);
+  }
 }
 
 void
 rb_frame_pop()
 {
-  UNSUPPORTED(rb_frame_pop);
+  yarv_thread_t *th = GET_THREAD();
+  th->cfp = YARV_PREVIOUS_CONTROL_FRAME(th->cfp);
 }
 
 static VALUE
@@ -1843,6 +1853,28 @@
   return Qnil;
 }
 
+const char *
+rb_sourcefile(){
+  yarv_iseq_t *iseq = GET_THREAD()->cfp->iseq;
+  if(iseq &&
+     !CMETHOD_INFO_P(iseq)){
+    return RSTRING(iseq->file_name)->ptr;
+  }
+  return 0;
+}
+
+int
+rb_sourceline(){
+  yarv_thread_t *th = GET_THREAD();
+  yarv_iseq_t *iseq = th->cfp->iseq;
+  
+  if(iseq &&
+     !CMETHOD_INFO_P(iseq)){
+    return th_get_sourceline(th->cfp);
+  }
+  return 0;
+}
+
 static VALUE
 eval(VALUE self, VALUE src, VALUE scope, char *file, int line)
 {

Modified: trunk/eval_intern.h
===================================================================
--- trunk/eval_intern.h	2005-11-10 16:29:24 UTC (rev 287)
+++ trunk/eval_intern.h	2005-11-14 15:49:30 UTC (rev 288)
@@ -3,7 +3,8 @@
 #define EVAL_INTERN_H_INCLUDED
 
 #define PASS_PASSED_BLOCK() \
-  (GET_THREAD()->passed_block = (yarv_block_t *)GET_THREAD()->cfp->lfp[0])
+  (GET_THREAD()->passed_block = \
+   GC_GUARDED_PTR_REF((yarv_block_t *)GET_THREAD()->cfp->lfp[0]))
 
 
 #define UNSUPPORTED(func) \

Modified: trunk/eval_load.c
===================================================================
--- trunk/eval_load.c	2005-11-10 16:29:24 UTC (rev 287)
+++ trunk/eval_load.c	2005-11-14 15:49:30 UTC (rev 288)
@@ -20,39 +20,37 @@
 #endif
 
 static int
-rb_feature_p(feature, ext, rb)
-    const char *feature, *ext;
-    int rb;
+rb_feature_p(const char *feature, const char *ext, int rb)
 {
-    VALUE v;
-    char *f, *e;
-    long i, len, elen;
+  VALUE v;
+  char *f, *e;
+  long i, len, elen;
 
-    if (ext) {
-	len = ext - feature;
-	elen = strlen(ext);
+  if (ext) {
+    len = ext - feature;
+    elen = strlen(ext);
+  }
+  else {
+    len = strlen(feature);
+    elen = 0;
+  }
+  for (i = 0; i < RARRAY(rb_features)->len; ++i) {
+    v = RARRAY(rb_features)->ptr[i];
+    f = StringValuePtr(v);
+    if (strncmp(f, feature, len) != 0) continue;
+    if (!*(e = f + len)) {
+      if (ext) continue;
+      return 'u';
     }
-    else {
-	len = strlen(feature);
-	elen = 0;
+    if (*e != '.') continue;
+    if ((!rb || !ext) && (IS_SOEXT(e) || IS_DLEXT(e))) {
+      return 's';
     }
-    for (i = 0; i < RARRAY(rb_features)->len; ++i) {
-	v = RARRAY(rb_features)->ptr[i];
-	f = StringValuePtr(v);
-	if (strncmp(f, feature, len) != 0) continue;
-	if (!*(e = f + len)) {
-	    if (ext) continue;
-	    return 'u';
-	}
-	if (*e != '.') continue;
-	if ((!rb || !ext) && (IS_SOEXT(e) || IS_DLEXT(e))) {
-	    return 's';
-	}
-	if ((rb || !ext) && (strcmp(e, ".rb") == 0)) {
-	    return 'r';
-	}
+    if ((rb || !ext) && (strcmp(e, ".rb") == 0)) {
+      return 'r';
     }
-    return 0;
+  }
+  return 0;
 }
 
 static const char *const loadable_ext[] = {
@@ -66,46 +64,43 @@
 static int search_required _((VALUE, VALUE *));
 
 int
-rb_provided(feature)
-    const char *feature;
+rb_provided(const char *feature)
 {
-    int i;
-    char *buf;
-    VALUE fname;
+  int i;
+  char *buf;
+  VALUE fname;
 
-    if (rb_feature_p(feature, 0, Qfalse))
-	return Qtrue;
-    if (loading_tbl) {
-	if (st_lookup(loading_tbl, (st_data_t)feature, 0)) return Qtrue;
-	buf = ALLOCA_N(char, strlen(feature)+8);
-	strcpy(buf, feature);
-	for (i=0; loadable_ext[i]; i++) {
-	    strcpy(buf+strlen(feature), loadable_ext[i]);
-	    if (st_lookup(loading_tbl, (st_data_t)buf, 0)) return Qtrue;
-	}
+  if (rb_feature_p(feature, 0, Qfalse))
+    return Qtrue;
+  if (loading_tbl) {
+    if (st_lookup(loading_tbl, (st_data_t)feature, 0)) return Qtrue;
+    buf = ALLOCA_N(char, strlen(feature)+8);
+    strcpy(buf, feature);
+    for (i=0; loadable_ext[i]; i++) {
+      strcpy(buf+strlen(feature), loadable_ext[i]);
+      if (st_lookup(loading_tbl, (st_data_t)buf, 0)) return Qtrue;
     }
-    if (search_required(rb_str_new2(feature), &fname)) {
-	feature = RSTRING(fname)->ptr;
-	if (rb_feature_p(feature, 0, Qfalse))
-	    return Qtrue;
-	if (loading_tbl && st_lookup(loading_tbl, (st_data_t)feature, 0))
-	    return Qtrue;
-    }
-    return Qfalse;
+  }
+  if (search_required(rb_str_new2(feature), &fname)) {
+    feature = RSTRING(fname)->ptr;
+    if (rb_feature_p(feature, 0, Qfalse))
+      return Qtrue;
+    if (loading_tbl && st_lookup(loading_tbl, (st_data_t)feature, 0))
+      return Qtrue;
+  }
+  return Qfalse;
 }
 
 static void
-rb_provide_feature(feature)
-    VALUE feature;
+rb_provide_feature(VALUE feature)
 {
-    rb_ary_push(rb_features, feature);
+  rb_ary_push(rb_features, feature);
 }
 
 void
-rb_provide(feature)
-    const char *feature;
+rb_provide(const char *feature)
 {
-    rb_provide_feature(rb_str_new2(feature));
+  rb_provide_feature(rb_str_new2(feature));
 }
 
 VALUE rb_load_path;
@@ -162,22 +157,19 @@
 }
 
 void
-rb_load_protect(fname, wrap, state)
-    VALUE fname;
-    int wrap;
-    int *state;
+rb_load_protect(VALUE fname, int wrap, int *state)
 {
-    int status;
+  int status;
 
-    PUSH_THREAD_TAG();
-    if ((status = EXEC_TAG()) == 0) {
-	rb_load(fname, wrap);
-    }
-    else if (status == TAG_THREAD) {
-	rb_thread_start_1();
-    }
-    POP_THREAD_TAG();
-    if (state) *state = status;
+  PUSH_THREAD_TAG();
+  if ((status = EXEC_TAG()) == 0) {
+    rb_load(fname, wrap);
+  }
+  else if (status == TAG_THREAD) {
+    rb_thread_start_1();
+  }
+  POP_THREAD_TAG();
+  if (state) *state = status;
 }
 
 /*
@@ -210,20 +202,25 @@
 static int
 load_wait(char *ftptr)
 {
-  // TODO: fix me
-  return Qfalse;
-  /*
   st_data_t th;
+  if(!loading_tbl){
+    return Qfalse;
+  }
+  if(!st_lookup(loading_tbl, (st_data_t)ftptr, &th)){
+    return Qfalse;
+  }
 
-  if (!loading_tbl) return Qfalse;
-  if (!st_lookup(loading_tbl, (st_data_t)ftptr, &th)) return Qfalse;
-  if ((rb_thread_t)th == curr_thread) return Qtrue;
-  do {
+  /*
+  if((rb_thread_t)th == curr_thread){
+    return Qtrue;
+  }
+  
+  do{
     CHECK_INTS;
     rb_thread_schedule();
-  } while (st_lookup(loading_tbl, (st_data_t)ftptr, &th));
+  }while (st_lookup(loading_tbl, (st_data_t)ftptr, &th));
+  */
   return Qtrue;
-   */
 }
 
 /*
@@ -249,94 +246,91 @@
  */
 
 VALUE
-rb_f_require(obj, fname)
-    VALUE obj, fname;
+rb_f_require(VALUE obj, VALUE fname)
 {
     return rb_require_safe(fname, ruby_safe_level);
 }
 
 static int
-search_required(fname, path)
-    VALUE fname, *path;
+search_required(VALUE fname, VALUE *path)
 {
-    VALUE tmp;
-    char *ext, *ftptr;
-    int type, ft = 0;
+  VALUE tmp;
+  char *ext, *ftptr;
+  int type, ft = 0;
 
-    *path = 0;
-    ext = strrchr(ftptr = RSTRING(fname)->ptr, '.');
-    if (ext && !strchr(ext, '/')) {
-	if (strcmp(".rb", ext) == 0) {
-	    if (rb_feature_p(ftptr, ext, Qtrue)) return 'r';
-	    if (tmp = rb_find_file(fname)) {
-		tmp = rb_file_expand_path(tmp, Qnil);
-		ext = strrchr(ftptr = RSTRING(tmp)->ptr, '.');
-		if (!rb_feature_p(ftptr, ext, Qtrue))
-		    *path = tmp;
-		return 'r';
-	    }
-	    return 0;
-	}
-	else if (IS_SOEXT(ext)) {
-	    if (rb_feature_p(ftptr, ext, Qfalse)) return 's';
-	    tmp = rb_str_new(RSTRING(fname)->ptr, ext-RSTRING(fname)->ptr);
+  *path = 0;
+  ext = strrchr(ftptr = RSTRING(fname)->ptr, '.');
+  if (ext && !strchr(ext, '/')) {
+    if (strcmp(".rb", ext) == 0) {
+      if (rb_feature_p(ftptr, ext, Qtrue)) return 'r';
+      if (tmp = rb_find_file(fname)) {
+        tmp = rb_file_expand_path(tmp, Qnil);
+        ext = strrchr(ftptr = RSTRING(tmp)->ptr, '.');
+        if (!rb_feature_p(ftptr, ext, Qtrue))
+          *path = tmp;
+        return 'r';
+      }
+      return 0;
+    }
+    else if (IS_SOEXT(ext)) {
+      if (rb_feature_p(ftptr, ext, Qfalse)) return 's';
+      tmp = rb_str_new(RSTRING(fname)->ptr, ext-RSTRING(fname)->ptr);
 #ifdef DLEXT2
-	    OBJ_FREEZE(tmp);
-	    if (rb_find_file_ext(&tmp, loadable_ext+1)) {
-		tmp = rb_file_expand_path(tmp, Qnil);
-		ext = strrchr(ftptr = RSTRING(tmp)->ptr, '.');
-		if (!rb_feature_p(ftptr, ext, Qfalse))
-		    *path = tmp;
-		return 's';
-	    }
+      OBJ_FREEZE(tmp);
+      if (rb_find_file_ext(&tmp, loadable_ext+1)) {
+        tmp = rb_file_expand_path(tmp, Qnil);
+        ext = strrchr(ftptr = RSTRING(tmp)->ptr, '.');
+        if (!rb_feature_p(ftptr, ext, Qfalse))
+          *path = tmp;
+        return 's';
+      }
 #else
-	    rb_str_cat2(tmp, DLEXT);
-	    OBJ_FREEZE(tmp);
-	    if (tmp = rb_find_file(tmp)) {
-		tmp = rb_file_expand_path(tmp, Qnil);
-		ext = strrchr(ftptr = RSTRING(tmp)->ptr, '.');
-		if (!rb_feature_p(ftptr, ext, Qfalse))
-		    *path = tmp;
-		return 's';
-	    }
+      rb_str_cat2(tmp, DLEXT);
+      OBJ_FREEZE(tmp);
+      if (tmp = rb_find_file(tmp)) {
+        tmp = rb_file_expand_path(tmp, Qnil);
+        ext = strrchr(ftptr = RSTRING(tmp)->ptr, '.');
+        if (!rb_feature_p(ftptr, ext, Qfalse))
+          *path = tmp;
+        return 's';
+      }
 #endif
-	}
-	else if (IS_DLEXT(ext)) {
-	    if (rb_feature_p(ftptr, ext, Qfalse)) return 's';
-	    if (tmp = rb_find_file(fname)) {
-		tmp = rb_file_expand_path(tmp, Qnil);
-		ext = strrchr(ftptr = RSTRING(tmp)->ptr, '.');
-		if (!rb_feature_p(ftptr, ext, Qfalse))
-		    *path = tmp;
-		return 's';
-	    }
-	}
     }
-    else if ((ft = rb_feature_p(ftptr, 0, Qfalse)) == 'r') {
-	return 'r';
+    else if (IS_DLEXT(ext)) {
+      if (rb_feature_p(ftptr, ext, Qfalse)) return 's';
+      if (tmp = rb_find_file(fname)) {
+        tmp = rb_file_expand_path(tmp, Qnil);
+        ext = strrchr(ftptr = RSTRING(tmp)->ptr, '.');
+        if (!rb_feature_p(ftptr, ext, Qfalse))
+          *path = tmp;
+        return 's';
+      }
     }
-    tmp = fname;
-    type = rb_find_file_ext(&tmp, loadable_ext);
-    tmp = rb_file_expand_path(tmp, Qnil);
-    switch (type) {
-      case 0:
-	ftptr = RSTRING(tmp)->ptr;
-	if (ft) break;
-	return rb_feature_p(ftptr, 0, Qfalse);
+  }
+  else if ((ft = rb_feature_p(ftptr, 0, Qfalse)) == 'r') {
+    return 'r';
+  }
+  tmp = fname;
+  type = rb_find_file_ext(&tmp, loadable_ext);
+  tmp = rb_file_expand_path(tmp, Qnil);
+  switch (type) {
+  case 0:
+    ftptr = RSTRING(tmp)->ptr;
+    if (ft) break;
+    return rb_feature_p(ftptr, 0, Qfalse);
 
-      default:
-	if (ft) break;
-      case 1:
-	ext = strrchr(ftptr = RSTRING(tmp)->ptr, '.');
-	if (rb_feature_p(ftptr, ext, !--type)) break;
-	*path = tmp;
-    }
-    return type ? 's' : 'r';
+  default:
+    if (ft) break;
+  case 1:
+    ext = strrchr(ftptr = RSTRING(tmp)->ptr, '.');
+    if (rb_feature_p(ftptr, ext, !--type)) break;
+    *path = tmp;
+  }
+  return type ? 's' : 'r';
 }
 
 static void
-load_failed(fname)
-    VALUE fname;
+load_failed(VALUE fname)
 {
     rb_raise(rb_eLoadError, "no such file to load -- %s", RSTRING(fname)->ptr);
 }
@@ -437,12 +431,11 @@
 }
 
 VALUE
-rb_require(fname)
-    const char *fname;
+rb_require(const char *fname)
 {
-    VALUE fn = rb_str_new2(fname);
-    OBJ_FREEZE(fn);
-    return rb_require_safe(fn, ruby_safe_level);
+  VALUE fn = rb_str_new2(fname);
+  OBJ_FREEZE(fn);
+  return rb_require_safe(fn, ruby_safe_level);
 }
 
 /*
@@ -460,16 +453,13 @@
  */
 
 static VALUE
-rb_mod_autoload(mod, sym, file)
-    VALUE mod;
-    VALUE sym;
-    VALUE file;
+rb_mod_autoload(VALUE mod, VALUE sym, VALUE file)
 {
-    ID id = rb_to_id(sym);
+  ID id = rb_to_id(sym);
 
-    Check_SafeStr(file);
-    rb_autoload(mod, id, RSTRING(file)->ptr);
-    return Qnil;
+  Check_SafeStr(file);
+  rb_autoload(mod, id, RSTRING(file)->ptr);
+  return Qnil;
 }
 
 /*
@@ -477,10 +467,9 @@
  */
 
 static VALUE
-rb_mod_autoload_p(mod, sym)
-    VALUE mod, sym;
+rb_mod_autoload_p(VALUE mod, VALUE sym)
 {
-    return rb_autoload_p(mod, rb_to_id(sym));
+  return rb_autoload_p(mod, rb_to_id(sym));
 }
 
 /*
@@ -495,10 +484,7 @@
  */
 
 static VALUE
-rb_f_autoload(obj, sym, file)
-    VALUE obj;
-    VALUE sym;
-    VALUE file;
+rb_f_autoload(VALUE obj, VALUE sym, VALUE file)
 {
   // TODO: fix me
   return rb_mod_autoload(rb_cObject, sym, file);
@@ -510,9 +496,7 @@
  */
 
 static VALUE
-rb_f_autoload_p(obj, sym)
-    VALUE obj;
-    VALUE sym;
+rb_f_autoload_p(VALUE obj, VALUE sym)
 {
   /* use ruby_cbase() as same as rb_f_autoload. */
   // TODO: fix me
@@ -522,23 +506,23 @@
 void
 Init_load()
 {
-    rb_load_path = rb_ary_new();
-    rb_define_readonly_variable("$:", &rb_load_path);
-    rb_define_readonly_variable("$-I", &rb_load_path);
-    rb_define_readonly_variable("$LOAD_PATH", &rb_load_path);
+  rb_load_path = rb_ary_new();
+  rb_define_readonly_variable("$:", &rb_load_path);
+  rb_define_readonly_variable("$-I", &rb_load_path);
+  rb_define_readonly_variable("$LOAD_PATH", &rb_load_path);
 
-    rb_features = rb_ary_new();
-    rb_define_readonly_variable("$\"", &rb_features);
-    rb_define_readonly_variable("$LOADED_FEATURES", &rb_features);
+  rb_features = rb_ary_new();
+  rb_define_readonly_variable("$\"", &rb_features);
+  rb_define_readonly_variable("$LOADED_FEATURES", &rb_features);
 
-    rb_define_global_function("load", rb_f_load, -1);
-    rb_define_global_function("require", rb_f_require, 1);
-    rb_define_method(rb_cModule, "autoload",  rb_mod_autoload,   2);
-    rb_define_method(rb_cModule, "autoload?", rb_mod_autoload_p, 1);
-    rb_define_global_function("autoload",  rb_f_autoload,   2);
-    rb_define_global_function("autoload?", rb_f_autoload_p, 1);
+  rb_define_global_function("load", rb_f_load, -1);
+  rb_define_global_function("require", rb_f_require, 1);
+  rb_define_method(rb_cModule, "autoload",  rb_mod_autoload,   2);
+  rb_define_method(rb_cModule, "autoload?", rb_mod_autoload_p, 1);
+  rb_define_global_function("autoload",  rb_f_autoload,   2);
+  rb_define_global_function("autoload?", rb_f_autoload_p, 1);
 
-    ruby_dln_librefs = rb_ary_new();
-    rb_global_variable(&ruby_dln_librefs);
+  ruby_dln_librefs = rb_ary_new();
+  rb_global_variable(&ruby_dln_librefs);
 }
 

Modified: trunk/eval_thread.c
===================================================================
--- trunk/eval_thread.c	2005-11-10 16:29:24 UTC (rev 287)
+++ trunk/eval_thread.c	2005-11-14 15:49:30 UTC (rev 288)
@@ -2300,11 +2300,11 @@
 Init_Thread()
 {
   recursive_key = rb_intern("__recursive_key__");
+  rb_eThreadError = rb_define_class("ThreadError", rb_eStandardError);
   return;
+
   /*
-    VALUE cThGroup;
-
-    rb_eThreadError = rb_define_class("ThreadError", rb_eStandardError);
+  VALUE cThGroup;
     rb_cThread = rb_define_class("Thread", rb_cObject);
     rb_undef_alloc_func(rb_cThread);
 

Modified: trunk/gc.c
===================================================================
--- trunk/gc.c	2005-11-10 16:29:24 UTC (rev 287)
+++ trunk/gc.c	2005-11-14 15:49:30 UTC (rev 288)
@@ -98,7 +98,6 @@
 rb_memerror(void)
 {
     static int recurse = 0;
-
     if (!nomem_error || (recurse > 0 && rb_safe_level() < 4)) {
 	fprintf(stderr, "[FATAL] failed to allocate memory\n");
 	exit(1);

Modified: trunk/insns.def
===================================================================
--- trunk/insns.def	2005-11-10 16:29:24 UTC (rev 287)
+++ trunk/insns.def	2005-11-14 15:49:30 UTC (rev 288)
@@ -1064,14 +1064,18 @@
   }
 
   /* find klass */
-  if((super == rb_cObject) &&
-     rb_const_defined_at(cbase, id)){
-    
+  if(rb_const_defined_at(cbase, id)){
     klass = rb_const_get_at(cbase, id);
-    /* already exist */
-    
-    /* TODO: type check */
-    
+    if(super != rb_cObject){
+      /* type check */
+      VALUE tmp;
+      tmp = rb_class_real(RCLASS(klass)->super);
+
+      if(tmp != super){
+        rb_raise(rb_eTypeError, "superclass mismatch for class %s",
+                 rb_id2name(id));
+      }
+    }
   }
   else{
     /* new class declaration */
@@ -1521,7 +1525,8 @@
       else if(state == TAG_RETURN){
         yarv_control_frame_t *cfp = GET_CFP();
         int is_orphan = 1;
-        
+
+        /* check orphan */
         while((VALUE*)cfp < th->stack + th->stack_size){
           cfp++;
           if(GET_LFP() == cfp->lfp){
@@ -1532,7 +1537,7 @@
         if(is_orphan){
           localjump_error("unexpected return", throwobj, TAG_RETURN);
         }
-  
+
         /* set current lfp */
         pt = GET_LFP();
       }

Modified: trunk/test.rb
===================================================================
--- trunk/test.rb	2005-11-10 16:29:24 UTC (rev 287)
+++ trunk/test.rb	2005-11-14 15:49:30 UTC (rev 288)
@@ -1,47 +1,140 @@
 
-def iter
-  yield 1, 2
+begin
+  p 1
+end while p(2)
+
+while p(3)
+  p 4
 end
 
-iter{|a, *|
-  p [a, ]
-}
-iter{|a|
-  p [a, ]
-}
+begin
+  p 1
+end until (p(2); true)
 
+until (p(3); true)
+  p 4
+end
 
 __END__
+def m
+  {}.fetch(:a){
+    return nil
+  }
+end
 
-ary = [1]
+__send__ :m
 
-ary.each{|*i|
-  p i
-}
-ary.each{|a, *i|
-  p [a, i]
-}
-ary.each{|a, b, *i|
-  p [a, b, i]
-}
-ary.each{|i|
-  p i
-}
+p :foo
 
 __END__
-def iter
-  yield 1, 2, 3
-end
 
-iter{|a, b, c, d, *y|
-  p [ y]
-}
+require 'optparse'
+require 'optparse/time'
+require 'ostruct'
+require 'pp'
 
-__END__
-iter{|x, *y| p [x, y]}
-iter{|x, y| p [x, y]}
-iter{|x, | p [x, ]}
-iter{|*x| p [x, ]}
-iter{|*| p []}
 
-lambda{|*| p :ok}.call(0)
+
+class OptparseExample
+
+  CODES = %w[iso-2022-jp shift_jis euc-jp utf8 binary]
+  CODE_ALIASES = {"jis" => "iso-2022-jp", "sjis" => "shift_jis"}
+
+  #
+  # Return a structure describing the options.
+  #
+  def self.parse(args)
+    # The options specified on the command line will be collected in *options*.
+    # We set default values here.
+    options = OpenStruct.new
+    options.library = []
+    options.inplace = false
+    options.encoding = "utf8"
+    options.transfer_type = :auto
+    options.verbose = false
+
+    opts = OptionParser.new do |opts|
+      opts.banner = "Usage: example.rb [options]"
+      opts.separator ""
+      opts.separator "Specific options:"
+
+      # Mandatory argument.
+      opts.on("-r", "--require LIBRARY",
+              "Require the LIBRARY before executing your script") do |lib|
+        options.library << lib
+      end
+
+      # Optional argument; multi-line description.
+      opts.on("-i", "--inplace [EXTENSION]",
+              "Edit ARGV files in place",
+              "  (make backup if EXTENSION supplied)") do |ext|
+        options.inplace = true
+        options.extension = ext || ''
+        options.extension.sub!(/\A\.?(?=.)/, ".")  # Ensure extension begins with dot.
+      end
+
+      # Cast 'delay' argument to a Float.
+      opts.on("--delay N", Float, "Delay N seconds before executing") do |n|
+        options.delay = n
+      end
+
+      # Cast 'time' argument to a Time object.
+      opts.on("-t", "--time [TIME]", Time, "Begin execution at given time") do |time|
+        options.time = time
+      end
+
+      # Cast to octal integer.
+      opts.on("-F", "--irs [OCTAL]", OptionParser::OctalInteger,
+              "Specify record separator (default \\0)") do |rs|
+        options.record_separator = rs
+      end
+
+      # List of arguments.
+      opts.on("--list x,y,z", Array, "Example 'list' of arguments") do |list|
+        options.list = list
+      end
+
+      # Keyword completion.  We are specifying a specific set of arguments (CODES
+      # and CODE_ALIASES - notice the latter is a Hash), and the user may provide
+      # the shortest unambiguous text.
+      code_list = (CODE_ALIASES.keys + CODES).join(',')
+      opts.on("--code CODE", CODES, CODE_ALIASES, "Select encoding",
+              "  (#{code_list})") do |encoding|
+        options.encoding = encoding
+      end
+
+      # Optional argument with keyword completion.
+      opts.on("--type [TYPE]", [:text, :binary, :auto], "Select transfer type (text, binary, auto)") do |t|
+        options.transfer_type = t
+      end
+
+      # Boolean switch.
+      opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
+        options.verbose = v
+      end
+
+      opts.separator ""
+      opts.separator "Common options:"
+
+      # No argument, shows at tail.  This will print an options summary.
+      # Try it and see!
+      opts.on_tail("-h", "--help", "Show this message") do
+        puts opts
+        exit
+      end
+
+      # Another typical switch to print the version.
+      opts.on_tail("--version", "Show version") do
+        puts OptionParser::Version.join('.')
+        exit
+      end
+    end
+
+    opts.parse!(args)
+    options
+  end  # parse()
+
+end  # class OptparseExample
+
+options = OptparseExample.parse(ARGV)
+pp options

Modified: trunk/vm.c
===================================================================
--- trunk/vm.c	2005-11-10 16:29:24 UTC (rev 287)
+++ trunk/vm.c	2005-11-14 15:49:30 UTC (rev 288)
@@ -327,7 +327,7 @@
   procval = rb_obj_alloc(cYarvProc);
   GetProcVal(procval, proc);
 
-  if(GC_GUARDED_PTR_REF(*cfp->lfp) != 0 &&
+  if(GC_GUARDED_PTR_REF(cfp->lfp[0]) != 0 &&
      cfp->iseq->type != ISEQ_TYPE_CLASS){
     yarv_proc_t *p;
     proc->blockprocval =
@@ -343,6 +343,13 @@
   proc->block.proc = procval;
   proc->envval     = envval;
 
+  /* set cref */
+  if(cfp->iseq && cfp->iseq->klass_nest_stack){
+    block->iseq->klass_nest_stack = cfp->iseq->klass_nest_stack;
+  }
+  else{
+    block->iseq->klass_nest_stack = rb_ary_dup(th->klass_nest_stack);
+  }
   return procval;
 }
 
@@ -382,7 +389,7 @@
   }
   case NODE_CFUNC:{
     yarv_control_frame_t *reg_cfp = th->cfp;
-    struct cmethod_info cmi = {0, id, klass};
+    struct yarv_cmethod_info cmi = {0, id, klass};
 
     th_set_env(th, (yarv_iseq_t *)&cmi,
                FRAME_MAGIC_CFUNC, recv, (VALUE)blockptr,
@@ -430,7 +437,7 @@
   NODE *body;
   int nosuper = 0;
   {
-    struct cmethod_info *cmi = (void *)th->cfp->iseq;
+    struct yarv_cmethod_info *cmi = (void *)th->cfp->iseq;
     if(cmi->sig == 0){
       klass = RCLASS(cmi->klass)->super;
       id = cmi->id;
@@ -696,6 +703,26 @@
   return th_svar(th, cnt);
 }
 
+int
+th_get_sourceline(yarv_control_frame_t *cfp)
+{
+  int i;
+  int pos = cfp->pc - cfp->iseq->iseq_encoded;
+  yarv_iseq_t *iseq = cfp->iseq;
+  int line_no;
+
+  for(i=0; i<iseq->insn_info_size; i++){
+    if(iseq->insn_info_tbl[i].position == pos){
+      line_no = iseq->insn_info_tbl[i-1].line_no;
+      goto found;
+    }
+  }
+  line_no = iseq->insn_info_tbl[i-1].line_no;
+
+found:
+  return line_no;
+}
+
 static VALUE
 th_backtrace_each(yarv_thread_t *th,
                         yarv_control_frame_t *limit_cfp,
@@ -707,25 +734,13 @@
 
   if(cfp->iseq != 0){
     if(cfp->pc != 0){
-      int i;
-      int pos = cfp->pc - cfp->iseq->iseq_encoded;
-      yarv_iseq_t *iseq = cfp->iseq;
-
-      for(i=0; i<iseq->insn_info_size; i++){
-        if(iseq->insn_info_tbl[i].position == pos){
-          line_no = iseq->insn_info_tbl[i-1].line_no;
-          goto found;
-        }
-      }
-      line_no = iseq->insn_info_tbl[i-1].line_no;
-      
-    found:
+      line_no = th_get_sourceline(cfp);
       snprintf(buf, BUFSIZ, "%s:%d:in `%s'",
                file = RSTRING(cfp->iseq->file_name)->ptr,
                line_no, RSTRING(cfp->iseq->name)->ptr);
     }
     else{
-      struct cmethod_info *cmi = (void *)cfp->iseq;
+      struct yarv_cmethod_info *cmi = (void *)cfp->iseq;
       snprintf(buf, BUFSIZE, "%s:%d:in `%s'",
                file, line_no, rb_id2name(cmi->id));
     }

Modified: trunk/vm.h
===================================================================
--- trunk/vm.h	2005-11-10 16:29:24 UTC (rev 287)
+++ trunk/vm.h	2005-11-14 15:49:30 UTC (rev 288)
@@ -243,12 +243,6 @@
   }                                                \
 }
 
-struct cmethod_info{
-  VALUE sig; /* must be null */
-  ID id;
-  VALUE klass;
-};
-
 /*
  * Excception
  */

Modified: trunk/vm_dump.c
===================================================================
--- trunk/vm_dump.c	2005-11-10 16:29:24 UTC (rev 287)
+++ trunk/vm_dump.c	2005-11-14 15:49:30 UTC (rev 288)
@@ -47,7 +47,7 @@
   }
 
   if(cfp->iseq != 0){
-    struct cmethod_info *cmi = (void *)cfp->iseq;
+    struct yarv_cmethod_info *cmi = (void *)cfp->iseq;
     if(CMETHOD_INFO_P(cfp->iseq)){
       iseq_name = rb_id2name(cmi->id);
     }
@@ -169,7 +169,7 @@
     local_size = 0;
   }
   else if(CMETHOD_INFO_P(iseq)){
-    struct cmethod_info *cmi = (void *)iseq;
+    struct yarv_cmethod_info *cmi = (void *)iseq;
     argc       = 0;
     local_size = 0;
     name       = rb_id2name(cmi->id);

Modified: trunk/vm_macro.def
===================================================================
--- trunk/vm_macro.def	2005-11-10 16:29:24 UTC (rev 287)
+++ trunk/vm_macro.def	2005-11-14 15:49:30 UTC (rev 288)
@@ -60,7 +60,7 @@
 
 MACRO macro_eval_invoke_cfunc(num, id, recv, klass, mn, blockptr)
 {
-  struct cmethod_info cmi = {0, id, klass};
+  struct yarv_cmethod_info cmi = {0, id, klass};
   
   th_set_env(th, (yarv_iseq_t *)&cmi,
              FRAME_MAGIC_CFUNC, recv, (VALUE)blockptr,

Modified: trunk/yarvcore.c
===================================================================
--- trunk/yarvcore.c	2005-11-10 16:29:24 UTC (rev 287)
+++ trunk/yarvcore.c	2005-11-14 15:49:30 UTC (rev 288)
@@ -62,6 +62,7 @@
 #endif
 
 #define MARK_FREE_DEBUG 0
+
 #if MARK_FREE_DEBUG
 static int g_indent = 0;
 static void gc_debug_indent(){
@@ -736,7 +737,9 @@
       rb_gc_mark_locations(env->env, env->env + env->env_size);
     }
     MARK_UNLESS_NULL(env->prev_envval);
-    MARK_UNLESS_NULL(env->block.iseq->self);
+    if(env->block.iseq){
+      MARK_UNLESS_NULL(env->block.iseq->self);
+    }
   }
   MARK_REPORT("<- env", 0);
 }

Modified: trunk/yarvcore.h
===================================================================
--- trunk/yarvcore.h	2005-11-10 16:29:24 UTC (rev 287)
+++ trunk/yarvcore.h	2005-11-14 15:49:30 UTC (rev 288)
@@ -463,6 +463,12 @@
 
 #define CMETHOD_INFO_P(ptr) (*((VALUE*)(ptr)) == 0)
 
+struct yarv_cmethod_info{
+  VALUE sig; /* must be null */
+  ID id;
+  VALUE klass;
+};
+
 #define GET_BLOCK_PTR_IN_CFP(cfp) ((yarv_block_t *)(&(cfp)->self))
 #define GET_CFP_FROM_BLOCK_PTR(b) \
   ((yarv_control_frame_t *)((VALUE *)(b) - 5))

Modified: trunk/yarvtest/test_block.rb
===================================================================
--- trunk/yarvtest/test_block.rb	2005-11-10 16:29:24 UTC (rev 287)
+++ trunk/yarvtest/test_block.rb	2005-11-14 15:49:30 UTC (rev 288)
@@ -361,4 +361,23 @@
       }
     }
   end
+
+  def test_param_and_locals
+    ae %q{
+      $a = []
+      
+      def iter
+        yield 1
+      end
+      
+      def m
+        x = iter{|x|
+          $a << x
+          y = 0
+        }
+      end
+      m
+      $a
+    }
+  end
 end

Modified: trunk/yarvtest/test_syn.rb
===================================================================
--- trunk/yarvtest/test_syn.rb	2005-11-10 16:29:24 UTC (rev 287)
+++ trunk/yarvtest/test_syn.rb	2005-11-14 15:49:30 UTC (rev 288)
@@ -49,7 +49,21 @@
       until i > 10
         i+=1
       end; i)
-
+    # 
+    ae %q{
+      i = 0
+      begin
+        i+=1
+      end while false
+      i
+    }
+    ae %q{
+      i = 0
+      begin
+        i+=1
+      end until true
+      i
+    }
   end
 
   def test_and


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

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