[macruby-changes] [977] MacRuby/branches/experimental
source_changes at macosforge.org
source_changes at macosforge.org
Tue Mar 17 18:59:27 PDT 2009
Revision: 977
http://trac.macosforge.org/projects/ruby/changeset/977
Author: lsansonetti at apple.com
Date: 2009-03-17 18:59:26 -0700 (Tue, 17 Mar 2009)
Log Message:
-----------
fixed single assignments using splats
Modified Paths:
--------------
MacRuby/branches/experimental/roxor.cpp
MacRuby/branches/experimental/test_roxor.rb
Modified: MacRuby/branches/experimental/roxor.cpp
===================================================================
--- MacRuby/branches/experimental/roxor.cpp 2009-03-18 00:53:48 UTC (rev 976)
+++ MacRuby/branches/experimental/roxor.cpp 2009-03-18 01:59:26 UTC (rev 977)
@@ -230,6 +230,8 @@
Function *aliasFunc;
Function *valiasFunc;
Function *newHashFunc;
+ Function *toArrayFunc;
+ Function *catArrayFunc;
Function *newArrayFunc;
Function *newRangeFunc;
Function *newRegexpFunc;
@@ -543,6 +545,8 @@
aliasFunc = NULL;
valiasFunc = NULL;
newHashFunc = NULL;
+ toArrayFunc = NULL;
+ catArrayFunc = NULL;
newArrayFunc = NULL;
newRangeFunc = NULL;
newRegexpFunc = NULL;
@@ -3063,6 +3067,52 @@
}
break;
+ case NODE_ARGSCAT:
+ case NODE_ARGSPUSH:
+ {
+ assert(node->nd_head != NULL);
+ Value *ary = compile_node(node->nd_head);
+
+ assert(node->nd_body != NULL);
+ Value *other = compile_node(node->nd_body);
+
+ if (catArrayFunc == NULL) {
+ // VALUE rb_vm_ary_cat(VALUE obj);
+ catArrayFunc = cast<Function>(
+ module->getOrInsertFunction("rb_vm_ary_cat",
+ RubyObjTy, RubyObjTy, RubyObjTy, NULL));
+ }
+
+ std::vector<Value *> params;
+ params.push_back(ary);
+ params.push_back(other);
+
+ return compile_protected_call(catArrayFunc, params);
+ }
+ break;
+
+ case NODE_SPLAT:
+ {
+ assert(node->nd_head != NULL);
+ Value *val = compile_node(node->nd_head);
+
+ if (nd_type(node->nd_head) != NODE_ARRAY) {
+ if (toArrayFunc == NULL) {
+ // VALUE rb_vm_to_a(VALUE obj);
+ toArrayFunc = cast<Function>(
+ module->getOrInsertFunction("rb_vm_to_a",
+ RubyObjTy, RubyObjTy, NULL));
+ }
+
+ std::vector<Value *> params;
+ params.push_back(val);
+ val = compile_protected_call(toArrayFunc, params);
+ }
+
+ return val;
+ }
+ break;
+
case NODE_ARRAY:
case NODE_ZARRAY:
case NODE_VALUES:
@@ -3075,7 +3125,7 @@
newArrayFunc = cast<Function>(module->getOrInsertFunction("rb_ary_new_fast", ft));
}
- std::vector<Value *>params;
+ std::vector<Value *> params;
if (nd_type(node) == NODE_ZARRAY) {
params.push_back(ConstantInt::get(Type::Int32Ty, 0));
@@ -3912,10 +3962,35 @@
}
}
+extern "C"
+VALUE
+rb_vm_ary_cat(VALUE ary, VALUE obj)
+{
+ if (TYPE(obj) == T_ARRAY) {
+ rb_ary_concat(ary, obj);
+ }
+ else {
+ rb_ary_push(ary, obj);
+ }
+ return ary;
+}
+
+extern "C"
+VALUE
+rb_vm_to_a(VALUE obj)
+{
+ VALUE ary = rb_check_convert_type(obj, T_ARRAY, "Array", "to_a");
+ if (NIL_P(ary)) {
+ ary = rb_ary_new3(1, obj);
+ }
+ return ary;
+}
+
extern "C" void rb_print_undef(VALUE, ID, int);
extern "C"
-void rb_vm_alias(VALUE outer, ID name, ID def)
+void
+rb_vm_alias(VALUE outer, ID name, ID def)
{
// TODO reassign klass if called within module_eval
Modified: MacRuby/branches/experimental/test_roxor.rb
===================================================================
--- MacRuby/branches/experimental/test_roxor.rb 2009-03-18 00:53:48 UTC (rev 976)
+++ MacRuby/branches/experimental/test_roxor.rb 2009-03-18 01:59:26 UTC (rev 977)
@@ -268,6 +268,11 @@
assert '42', "def foo=(x); @x=x; end; x,self.foo = 1,41; p @x+x"
assert '42', "def []=(x,y); @x=x+y; end; x,self[40] = 1,1; p @x+x"
+ assert '[1, 2, 3]', "a=[1,2,3]; x=*a; p x"
+ assert '[1, 2, 3]', "a=[2,3]; x=1,*a; p x"
+ assert '[1, 2, 3]', "a=[1,2]; x=*a,3; p x"
+ assert '[1, 2, 3]', "a=[2]; x=1,*a,3; p x"
+
# TODO add more multiple assignments test
assert '42', "a=[20]; a[0] += 22; p a[0]"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090317/275ebd9a/attachment.html>
More information about the macruby-changes
mailing list