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

source_changes at macosforge.org source_changes at macosforge.org
Tue Jul 28 18:21:24 PDT 2009


Revision: 2106
          http://trac.macosforge.org/projects/ruby/changeset/2106
Author:   lsansonetti at apple.com
Date:     2009-07-28 18:21:23 -0700 (Tue, 28 Jul 2009)
Log Message:
-----------
added support for creation of Binding local variables

Modified Paths:
--------------
    MacRuby/branches/experimental/compiler.cpp
    MacRuby/branches/experimental/parse.y
    MacRuby/branches/experimental/vm.cpp
    MacRuby/branches/experimental/vm.h

Modified: MacRuby/branches/experimental/compiler.cpp
===================================================================
--- MacRuby/branches/experimental/compiler.cpp	2009-07-28 07:33:55 UTC (rev 2105)
+++ MacRuby/branches/experimental/compiler.cpp	2009-07-29 01:21:23 UTC (rev 2106)
@@ -6081,7 +6081,7 @@
 #endif
 	return iter->second;
     }
-    VALUE *var = GET_VM()->get_binding_lvar(name);
+    VALUE *var = GET_VM()->get_binding_lvar(name, false);
     if (var != NULL) {
 #if ROXOR_COMPILER_DEBUG
 	printf("get_binding_lvar %s (%p)\n", rb_id2name(name), *(void **)var);

Modified: MacRuby/branches/experimental/parse.y
===================================================================
--- MacRuby/branches/experimental/parse.y	2009-07-28 07:33:55 UTC (rev 2105)
+++ MacRuby/branches/experimental/parse.y	2009-07-29 01:21:23 UTC (rev 2106)
@@ -8094,6 +8094,8 @@
     return 0;
 }
 
+int rb_local_define(ID id);
+
 static NODE*
 assignable_gen(struct parser_params *parser, ID id, NODE *val)
 {
@@ -8136,14 +8138,18 @@
 	    else if (local_id(id)) {
 		return NEW_LASGN(id, val);
 	    }
-	    else{
-		dyna_var(id);
+	    else {
+		if (!rb_local_define(id)) {
+		    dyna_var(id);
+		}
 		return NEW_DASGN_CURR(id, val);
 	    }
 	}
 	else {
 	    if (!local_id(id)) {
-		local_var(id);
+		if (!rb_local_define(id)) {
+		    local_var(id);
+		}
 	    }
 	    return NEW_LASGN(id, val);
 	}

Modified: MacRuby/branches/experimental/vm.cpp
===================================================================
--- MacRuby/branches/experimental/vm.cpp	2009-07-28 07:33:55 UTC (rev 2105)
+++ MacRuby/branches/experimental/vm.cpp	2009-07-29 01:21:23 UTC (rev 2106)
@@ -4045,11 +4045,41 @@
     return rb_vm_parse_in_eval() ? 1 : 0;
 }
 
+VALUE *
+RoxorVM::get_binding_lvar(ID name, bool create)
+{
+    if (!bindings.empty()) {
+	rb_vm_binding_t *b = bindings.back();
+	rb_vm_local_t **l = &b->locals;
+	while (*l != NULL) {
+	    if ((*l)->name == name) {
+		return (*l)->value;
+	    }
+	    l = &(*l)->next;
+	}
+	if (create) {
+	    GC_WB(l, xmalloc(sizeof(rb_vm_local_t)));
+	    (*l)->name = name;
+	    GC_WB(&(*l)->value, xmalloc(sizeof(VALUE)));
+	    (*l)->next = NULL;
+	    return (*l)->value;
+	}
+    }
+    return NULL;
+}
+
 extern "C"
 int
+rb_local_define(ID id)
+{
+    return GET_VM()->get_binding_lvar(id, true) != NULL ? 1 : 0;
+}
+
+extern "C"
+int
 rb_local_defined(ID id)
 {
-    return GET_VM()->get_binding_lvar(id) != NULL ? 1 : 0;
+    return GET_VM()->get_binding_lvar(id, false) != NULL ? 1 : 0;
 }
 
 extern "C"

Modified: MacRuby/branches/experimental/vm.h
===================================================================
--- MacRuby/branches/experimental/vm.h	2009-07-28 07:33:55 UTC (rev 2105)
+++ MacRuby/branches/experimental/vm.h	2009-07-29 01:21:23 UTC (rev 2106)
@@ -861,17 +861,7 @@
 	    return exc;
 	}
 
-	VALUE *get_binding_lvar(ID name) {
-	    if (!bindings.empty()) {
-		rb_vm_binding_t *b = bindings.back();
-		for (rb_vm_local_t *l = b->locals; l != NULL; l = l->next) {
-		    if (l->name == name) {
-			return l->value;
-		    }
-		}
-	    }
-	    return NULL;
-	}
+	VALUE *get_binding_lvar(ID name, bool create);
 
 	VALUE pop_broken_with(void) {
 	    VALUE v = broken_with;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090728/bda2228a/attachment.html>


More information about the macruby-changes mailing list