[macruby-changes] [1432] MacRuby/branches/experimental/roxor.cpp
source_changes at macosforge.org
source_changes at macosforge.org
Mon Apr 20 16:30:03 PDT 2009
Revision: 1432
http://trac.macosforge.org/projects/ruby/changeset/1432
Author: vincent.isambart at gmail.com
Date: 2009-04-20 16:30:02 -0700 (Mon, 20 Apr 2009)
Log Message:
-----------
fixed the last masgn problem (calling to_ary when necessary)
Modified Paths:
--------------
MacRuby/branches/experimental/roxor.cpp
Modified: MacRuby/branches/experimental/roxor.cpp
===================================================================
--- MacRuby/branches/experimental/roxor.cpp 2009-04-19 03:39:26 UTC (rev 1431)
+++ MacRuby/branches/experimental/roxor.cpp 2009-04-20 23:30:02 UTC (rev 1432)
@@ -244,7 +244,8 @@
Function *aliasFunc;
Function *valiasFunc;
Function *newHashFunc;
- Function *toArrayFunc;
+ Function *toAFunc;
+ Function *toAryFunc;
Function *catArrayFunc;
Function *dupArrayFunc;
Function *newArrayFunc;
@@ -611,7 +612,8 @@
aliasFunc = NULL;
valiasFunc = NULL;
newHashFunc = NULL;
- toArrayFunc = NULL;
+ toAFunc = NULL;
+ toAryFunc = NULL;
catArrayFunc = NULL;
dupArrayFunc = NULL;
newArrayFunc = NULL;
@@ -1019,20 +1021,26 @@
RoxorCompiler::compile_multiple_assignment(NODE *node, Value *val)
{
assert(nd_type(node) == NODE_MASGN);
+ if (toAryFunc == NULL) {
+ // VALUE rb_vm_to_ary(VALUE ary);
+ toAryFunc = cast<Function>(module->getOrInsertFunction(
+ "rb_vm_to_ary",
+ RubyObjTy, RubyObjTy, NULL));
+ }
if (masgnGetElemBeforeSplatFunc == NULL) {
- // VALUE rb_vm_masgn_get_elem_before_splat(VALUE obj, int offset);
+ // VALUE rb_vm_masgn_get_elem_before_splat(VALUE ary, int offset);
masgnGetElemBeforeSplatFunc = cast<Function>(module->getOrInsertFunction(
"rb_vm_masgn_get_elem_before_splat",
RubyObjTy, RubyObjTy, Type::Int32Ty, NULL));
}
if (masgnGetElemAfterSplatFunc == NULL) {
- // VALUE rb_vm_masgn_get_elem_after_splat(VALUE obj, int before_splat_count, int after_splat_count, int offset);
+ // VALUE rb_vm_masgn_get_elem_after_splat(VALUE ary, int before_splat_count, int after_splat_count, int offset);
masgnGetElemAfterSplatFunc = cast<Function>(module->getOrInsertFunction(
"rb_vm_masgn_get_elem_after_splat",
RubyObjTy, RubyObjTy, Type::Int32Ty, Type::Int32Ty, Type::Int32Ty, NULL));
}
if (masgnGetSplatFunc == NULL) {
- // VALUE rb_vm_masgn_get_splat(VALUE obj, int before_splat_count, int after_splat_count);
+ // VALUE rb_vm_masgn_get_splat(VALUE ary, int before_splat_count, int after_splat_count);
masgnGetSplatFunc = cast<Function>(module->getOrInsertFunction(
"rb_vm_masgn_get_splat",
RubyObjTy, RubyObjTy, Type::Int32Ty, Type::Int32Ty, NULL));
@@ -1062,6 +1070,13 @@
++after_splat_count;
}
+ {
+ std::vector<Value *> params;
+ params.push_back(val);
+ val = CallInst::Create(toAryFunc, params.begin(),
+ params.end(), "", bb);
+ }
+
NODE *l = before_splat;
for (int i = 0; l != NULL; ++i) {
std::vector<Value *> params;
@@ -3899,16 +3914,16 @@
Value *val = compile_node(node->nd_head);
if (nd_type(node->nd_head) != NODE_ARRAY) {
- if (toArrayFunc == NULL) {
+ if (toAFunc == NULL) {
// VALUE rb_vm_to_a(VALUE obj);
- toArrayFunc = cast<Function>(
+ toAFunc = 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);
+ val = compile_protected_call(toAFunc, params);
}
return val;
@@ -5408,6 +5423,17 @@
return ary;
}
+extern "C"
+VALUE
+rb_vm_to_ary(VALUE obj)
+{
+ VALUE ary = rb_check_convert_type(obj, T_ARRAY, "Array", "to_ary");
+ if (NIL_P(ary)) {
+ ary = rb_ary_new3(1, obj);
+ }
+ return ary;
+}
+
extern "C" void rb_print_undef(VALUE, ID, int);
static void
@@ -5965,61 +5991,41 @@
extern "C"
VALUE
-rb_vm_masgn_get_elem_before_splat(VALUE obj, int offset)
+rb_vm_masgn_get_elem_before_splat(VALUE ary, int offset)
{
- if (TYPE(obj) == T_ARRAY) {
- if (offset < RARRAY_LEN(obj)) {
- return OC2RB(CFArrayGetValueAtIndex((CFArrayRef)obj, offset));
- }
+ if (offset < RARRAY_LEN(ary)) {
+ return OC2RB(CFArrayGetValueAtIndex((CFArrayRef)ary, offset));
}
- else if (offset == 0) {
- return obj;
- }
return Qnil;
}
extern "C"
VALUE
-rb_vm_masgn_get_elem_after_splat(VALUE obj, int before_splat_count, int after_splat_count, int offset)
+rb_vm_masgn_get_elem_after_splat(VALUE ary, int before_splat_count, int after_splat_count, int offset)
{
- if (TYPE(obj) == T_ARRAY) {
- int len = RARRAY_LEN(obj);
- if (len < before_splat_count + after_splat_count) {
- offset += before_splat_count;
- if (offset < len) {
- return OC2RB(CFArrayGetValueAtIndex((CFArrayRef)obj, offset));
- }
+ int len = RARRAY_LEN(ary);
+ if (len < before_splat_count + after_splat_count) {
+ offset += before_splat_count;
+ if (offset < len) {
+ return OC2RB(CFArrayGetValueAtIndex((CFArrayRef)ary, offset));
}
- else {
- offset += len - after_splat_count;
- return OC2RB(CFArrayGetValueAtIndex((CFArrayRef)obj, offset));
- }
}
- else if (offset == 0 && before_splat_count == 0) {
- return obj;
+ else {
+ offset += len - after_splat_count;
+ return OC2RB(CFArrayGetValueAtIndex((CFArrayRef)ary, offset));
}
return Qnil;
}
extern "C"
VALUE
-rb_vm_masgn_get_splat(VALUE obj, int before_splat_count, int after_splat_count) {
- if (TYPE(obj) == T_ARRAY) {
- int len = RARRAY_LEN(obj);
- if (len > before_splat_count + after_splat_count) {
- return rb_ary_subseq(obj, before_splat_count, len - before_splat_count - after_splat_count);
- }
- else {
- return rb_ary_new();
- }
+rb_vm_masgn_get_splat(VALUE ary, int before_splat_count, int after_splat_count) {
+ int len = RARRAY_LEN(ary);
+ if (len > before_splat_count + after_splat_count) {
+ return rb_ary_subseq(ary, before_splat_count, len - before_splat_count - after_splat_count);
}
else {
- if (before_splat_count == 0 && after_splat_count == 0) {
- return rb_ary_new3(1, obj);
- }
- else {
- return rb_ary_new();
- }
+ return rb_ary_new();
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090420/bbd23381/attachment.html>
More information about the macruby-changes
mailing list