[macruby-changes] [2895] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Sat Oct 24 20:06:24 PDT 2009


Revision: 2895
          http://trac.macosforge.org/projects/ruby/changeset/2895
Author:   lsansonetti at apple.com
Date:     2009-10-24 20:06:21 -0700 (Sat, 24 Oct 2009)
Log Message:
-----------
added support for defined? on any unhandled expression

Modified Paths:
--------------
    MacRuby/trunk/compiler.cpp
    MacRuby/trunk/test_vm/defined.rb

Modified: MacRuby/trunk/compiler.cpp
===================================================================
--- MacRuby/trunk/compiler.cpp	2009-10-25 01:40:53 UTC (rev 2894)
+++ MacRuby/trunk/compiler.cpp	2009-10-25 03:06:21 UTC (rev 2895)
@@ -1438,6 +1438,7 @@
     Value *what1 = NULL;
     Value *what2 = NULL;
     int type = 0;
+    bool expression = false;
 
     switch (nd_type(node)) {
 	case NODE_IVAR:
@@ -1495,10 +1496,13 @@
 	    type = DEFINED_METHOD;
 	    what1 = compile_id(node->nd_mid);
 	    break;
-    }
 
-    if (type == 0) {
-	compile_node_error("unrecognized defined? arg", node);
+	default:
+	    // Unhandled node type, probably an expression. Let's compile
+	    // it and it case everything goes okay we just return 'expression'.
+	    compile_node(node);
+	    expression = true;
+	    break;
     }
 
     if (definedFunc == NULL) {
@@ -1509,15 +1513,21 @@
 		    NULL));
     }
 
-    std::vector<Value *> params;
+    Value *val = NULL;
+    if (!expression) {
+	std::vector<Value *> params;
 
-    params.push_back(self);
-    params.push_back(ConstantInt::get(Int32Ty, type));
-    params.push_back(what1 == NULL ? nilVal : what1);
-    params.push_back(what2 == NULL ? nilVal : what2);
+	params.push_back(self);
+	params.push_back(ConstantInt::get(Int32Ty, type));
+	params.push_back(what1 == NULL ? nilVal : what1);
+	params.push_back(what2 == NULL ? nilVal : what2);
 
-    // Call the runtime.
-    Value *val = compile_protected_call(definedFunc, params);
+	// Call the runtime.
+	val = compile_protected_call(definedFunc, params);
+    }
+    else {
+	val = ConstantInt::get(RubyObjTy, (long)CFSTR("expression"));
+    }
     BasicBlock *normal_bb = bb;
     BranchInst::Create(merge_bb, bb);
 
@@ -4481,13 +4491,9 @@
 	    break;
 
 	case NODE_DEFINED:
-	    {
-		assert(node->nd_head != NULL);
+	    assert(node->nd_head != NULL);
+	    return compile_defined_expression(node->nd_head);
 
-		return compile_defined_expression(node->nd_head);
-	    }
-	    break;
-
 	case NODE_DEFN:
 	case NODE_DEFS:
 	    {

Modified: MacRuby/trunk/test_vm/defined.rb
===================================================================
--- MacRuby/trunk/test_vm/defined.rb	2009-10-25 01:40:53 UTC (rev 2894)
+++ MacRuby/trunk/test_vm/defined.rb	2009-10-25 03:06:21 UTC (rev 2895)
@@ -30,4 +30,5 @@
 
 assert 'nil', "p defined?(yield)"
 
-assert '"expression"', "p (defined? FOO && 42)"
+assert '"expression"', "FOO=42; p (defined? FOO && 42)"
+assert 'nil', "p (defined? FOO && 42)"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20091024/a4fdaf6a/attachment.html>


More information about the macruby-changes mailing list