[macruby-changes] [204] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Wed May 21 14:47:07 PDT 2008


Revision: 204
          http://trac.macosforge.org/projects/ruby/changeset/204
Author:   lsansonetti at apple.com
Date:     2008-05-21 14:47:03 -0700 (Wed, 21 May 2008)

Log Message:
-----------
fixed named method definitions, fixed nested named method definitions, fixed named method definitions on metaclasses (#50)

Modified Paths:
--------------
    MacRuby/trunk/parse.y

Added Paths:
-----------
    MacRuby/trunk/test/ruby/test_objc.rb

Modified: MacRuby/trunk/parse.y
===================================================================
--- MacRuby/trunk/parse.y	2008-05-21 19:34:54 UTC (rev 203)
+++ MacRuby/trunk/parse.y	2008-05-21 21:47:03 UTC (rev 204)
@@ -2958,14 +2958,26 @@
 		    /*%%%*/
 			NODE *body = remove_begin($5);
 			reduce_nodes(&body);
+#if WITH_OBJC
+			$$ = NEW_DEFN(cur_mid, $4, body, NOEX_PRIVATE);
+#else
 			$$ = NEW_DEFN($2, $4, body, NOEX_PRIVATE);
+#endif
 			fixpos($$, $4);
+#if WITH_OBJC
 			if (in_def_named_args > 0
-			    && in_def_named_args != 
-			       $$->nd_defn->nd_args->nd_frml - 1)
-			    yyerror("invalid use of named arguments in method definition");
+			    && in_def_named_args 
+			       != $$->nd_defn->nd_args->nd_frml - 1)
+{printf("xxx %d != %d\n", in_def_named_args, $$->nd_defn->nd_args->nd_frml-1);
+			    yyerror("invalid use of named arguments in " \
+				    "method definition");
+}
+#endif
 			local_pop();
 			in_def--;
+#if WITH_OBJC
+			in_def_named_args = 0;
+#endif
 			cur_mid = $<id>3;
 		    /*%
 			$$ = dispatch3(def, $2, $4, $5);
@@ -2977,6 +2989,10 @@
 		    {
 			in_single++;
 			lex_state = EXPR_END; /* force for args */
+#if WITH_OBJC
+			cur_mid = $5;
+			in_def_named_args = 0;
+#endif
 		    /*%%%*/
 			local_push(0);
 		    /*%
@@ -2989,10 +3005,26 @@
 		    /*%%%*/
 			NODE *body = remove_begin($8);
 			reduce_nodes(&body);
+#if WITH_OBJC
+			$$ = NEW_DEFS($2, cur_mid, $7, body);
+#else
 			$$ = NEW_DEFS($2, $5, $7, body);
+#endif
 			fixpos($$, $2);
+#if WITH_OBJC
+			if (in_def_named_args > 0
+			    && in_def_named_args 
+			       != $$->nd_defn->nd_args->nd_frml - 1)
+{printf("yyy %d != %d\n", in_def_named_args, $$->nd_defn->nd_args->nd_frml-1);
+			    yyerror("invalid use of named arguments in " \
+				    "method definition");
+}
+#endif
 			local_pop();
 			in_single--;
+#if WITH_OBJC
+			in_def_named_args = 0;
+#endif
 		    /*%
 			$$ = dispatch5(defs, $2, $3, $5, $7, $8);
 			in_single--;

Added: MacRuby/trunk/test/ruby/test_objc.rb
===================================================================
--- MacRuby/trunk/test/ruby/test_objc.rb	                        (rev 0)
+++ MacRuby/trunk/test/ruby/test_objc.rb	2008-05-21 21:47:03 UTC (rev 204)
@@ -0,0 +1,59 @@
+require 'test/unit'
+
+class TestObjC < Test::Unit::TestCase
+
+  def test_all_objects_inherit_from_nsobject
+    assert_kind_of(NSObject, true)
+    assert_kind_of(NSObject, false)
+    assert_kind_of(NSObject, 42)
+    assert_kind_of(NSObject, 42.42)
+    assert_kind_of(NSObject, 42_000_000_000_000)
+    assert_kind_of(NSObject, 'foo')
+    assert_kind_of(NSObject, [])
+  end
+
+  class ClassWithNamedArg
+    def doSomethingWith(ary, andObject:obj1, andObject:obj2)
+      ary << obj1
+      ary << obj2
+      return ary
+    end
+    def doSomethingWith(ary, andObject:obj)
+      ary << obj
+      return ary
+    end
+  end
+
+  def test_named_argument_call
+    o = ClassWithNamedArg.new
+    a = []
+    a2 = o.doSomethingWith(a, andObject:'x', andObject:'y')
+    assert_equal(a, a2)
+    assert_equal(['x', 'y'], a)
+
+    a = []
+    a2 = o.performSelector('doSomethingWith:andObject:',
+			   withObject:a, withObject:'xxx')
+    assert_equal(a, a2)
+    assert_equal(['xxx'], a)
+
+    o = Object.new
+    def o.doSomethingWith(ary, andObject:obj)
+      ary << obj
+      return ary
+    end
+
+    a = []
+    a2 = o.doSomethingWith(a, andObject:'xxx')
+    assert_equal(a, a2)
+    assert_equal(['xxx'], a)
+
+    a = []
+    a2 = o.performSelector('doSomethingWith:andObject:',
+			   withObject:a, withObject:'xxx')
+    assert_equal(a, a2)
+    assert_equal(['xxx'], a)
+  end
+
+end
+

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macruby-changes/attachments/20080521/0b532b65/attachment-0001.htm 


More information about the macruby-changes mailing list