[macruby-changes] [1120] MacRuby/branches/experimental

source_changes at macosforge.org source_changes at macosforge.org
Mon Mar 23 20:57:23 PDT 2009


Revision: 1120
          http://trac.macosforge.org/projects/ruby/changeset/1120
Author:   lsansonetti at apple.com
Date:     2009-03-23 20:57:22 -0700 (Mon, 23 Mar 2009)
Log Message:
-----------
do not print syntax error messages while parsing code within eval

Modified Paths:
--------------
    MacRuby/branches/experimental/error.c
    MacRuby/branches/experimental/roxor.cpp
    MacRuby/branches/experimental/roxor.h
    MacRuby/branches/experimental/vm_eval.c

Modified: MacRuby/branches/experimental/error.c
===================================================================
--- MacRuby/branches/experimental/error.c	2009-03-24 03:14:17 UTC (rev 1119)
+++ MacRuby/branches/experimental/error.c	2009-03-24 03:57:22 UTC (rev 1120)
@@ -1566,33 +1566,27 @@
 static void
 err_append(const char *s)
 {
-    // TODO
-    rb_write_error(s);
-    rb_write_error("\n");
-#if 0
-    rb_thread_t *th = GET_THREAD();
-    VALUE err = th->errinfo;
+    VALUE err = rb_vm_current_exception();
 
-    if (th->parse_in_eval) {
-	if (!RTEST(err)) {
+    if (rb_vm_parse_in_eval()) {
+	if (err == Qnil) {
 	    err = rb_exc_new2(rb_eSyntaxError, s);
-	    GC_WB(&th->errinfo, err);
+	    rb_vm_set_current_exception(err);
 	}
 	else {
 	    VALUE str = rb_obj_as_string(err);
 
 	    rb_str_cat2(str, "\n");
 	    rb_str_cat2(str, s);
-	    GC_WB(&th->errinfo, rb_exc_new3(rb_eSyntaxError, str));
+	    rb_vm_set_current_exception(rb_exc_new3(rb_eSyntaxError, str));
 	}
     }
     else {
-	if (!RTEST(err)) {
+	if (err == Qnil) {
 	    err = rb_exc_new2(rb_eSyntaxError, "compile error");
-	    GC_WB(&th->errinfo, err);
+	    rb_vm_set_current_exception(err);
 	}
 	rb_write_error(s);
 	rb_write_error("\n");
     }
-#endif
 }

Modified: MacRuby/branches/experimental/roxor.cpp
===================================================================
--- MacRuby/branches/experimental/roxor.cpp	2009-03-24 03:14:17 UTC (rev 1119)
+++ MacRuby/branches/experimental/roxor.cpp	2009-03-24 03:57:22 UTC (rev 1120)
@@ -406,6 +406,7 @@
 	rb_vm_block_t *current_block;
 	rb_vm_block_t *previous_block; // only used for non-Ruby created blocks
 	bool block_saved; // used by block_given?
+	bool parse_in_eval;
 
 	RoxorVM(void);
 
@@ -1815,6 +1816,8 @@
     previous_block = NULL;
     block_saved = false;
 
+    parse_in_eval = false;
+
     load_path = rb_ary_new();
     rb_objc_retain((void *)load_path);
     loaded_features = rb_ary_new();
@@ -5548,6 +5551,26 @@
 }
 
 extern "C"
+VALUE
+rb_vm_current_exception(void)
+{
+    return GET_VM()->current_exception;
+}
+
+extern "C"
+void
+rb_vm_set_current_exception(VALUE exception)
+{
+    if (GET_VM()->current_exception != exception) {
+	if (GET_VM()->current_exception != Qnil) {
+	    rb_objc_release((void *)GET_VM()->current_exception);
+	}
+	rb_objc_retain((void *)exception);
+	GET_VM()->current_exception = exception;
+    }
+}
+
+extern "C"
 void 
 rb_vm_debug(void)
 {
@@ -5574,6 +5597,20 @@
 }
 
 extern "C"
+bool
+rb_vm_parse_in_eval(void)
+{
+    return GET_VM()->parse_in_eval;
+}
+
+extern "C"
+void
+rb_vm_set_parse_in_eval(bool flag)
+{
+    GET_VM()->parse_in_eval = flag;
+}
+
+extern "C"
 IMP
 rb_vm_compile(const char *fname, NODE *node)
 {
@@ -5649,7 +5686,6 @@
 
     VALUE old_top_object = GET_VM()->current_top_object;
     GET_VM()->current_top_object = self;
-
     Class old_class = GET_VM()->current_class;
     GET_VM()->current_class = (Class)klass;
 

Modified: MacRuby/branches/experimental/roxor.h
===================================================================
--- MacRuby/branches/experimental/roxor.h	2009-03-24 03:14:17 UTC (rev 1119)
+++ MacRuby/branches/experimental/roxor.h	2009-03-24 03:57:22 UTC (rev 1120)
@@ -11,6 +11,8 @@
 
 bool rb_vm_running(void);
 void rb_vm_set_running(bool flag);
+bool rb_vm_parse_in_eval(void);
+void rb_vm_set_parse_in_eval(bool flag);
 VALUE rb_vm_load_path(void);
 VALUE rb_vm_loaded_features(void);
 int rb_vm_safe_level(void);
@@ -151,6 +153,8 @@
 }
 
 void rb_vm_raise(VALUE exception);
+VALUE rb_vm_current_exception(void);
+void rb_vm_set_current_exception(VALUE exception);
 VALUE rb_vm_backtrace(int level);
 
 VALUE rb_vm_pop_broken_value(void);

Modified: MacRuby/branches/experimental/vm_eval.c
===================================================================
--- MacRuby/branches/experimental/vm_eval.c	2009-03-24 03:14:17 UTC (rev 1119)
+++ MacRuby/branches/experimental/vm_eval.c	2009-03-24 03:57:22 UTC (rev 1120)
@@ -314,9 +314,18 @@
 eval_string(VALUE self, VALUE klass, VALUE src, VALUE scope, const char *file, int line)
 {
     // TODO honor scope
+    bool old_parse_in_eval = rb_vm_parse_in_eval();
+    rb_vm_set_parse_in_eval(true);
     NODE *node = rb_compile_string(file, src, line);
+    rb_vm_set_parse_in_eval(old_parse_in_eval);
     if (node == NULL) {
-	rb_raise(rb_eSyntaxError, "compile error");
+	VALUE exc = rb_vm_current_exception();
+	if (exc != Qnil) {
+	    rb_exc_raise(exc);
+	}
+	else {
+	    rb_raise(rb_eSyntaxError, "compile error");
+	}
     }
     if (klass == 0) {
 	klass = rb_cObject;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090323/a90a4151/attachment-0001.html>


More information about the macruby-changes mailing list