Permalink
Browse files

fixed multiple assignment where the left side does not exist + misc f…

…ixes

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/branches/experimental@1068 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
1 parent e12dc44 commit d5fb09e845c20f11927f25116875d34cd1459606 @lrz lrz committed Mar 22, 2009
Showing with 35 additions and 17 deletions.
  1. +3 −2 class.c
  2. +1 −1 encoding.c
  3. +1 −1 include/ruby/encoding.h
  4. +2 −2 object.c
  5. +2 −2 proc.c
  6. +1 −1 re.c
  7. +19 −6 roxor.cpp
  8. +4 −1 roxor.h
  9. +1 −1 string.c
  10. +1 −0 test_roxor.rb
View
@@ -464,6 +464,8 @@ rb_module_new(void)
return rb_define_module_id(0);
}
+VALUE rb_mod_initialize(VALUE, SEL);
+
VALUE
rb_define_module_id(ID id)
{
@@ -474,8 +476,7 @@ rb_define_module_id(ID id)
if (rb_mKernel != 0) {
/* because Module#initialize can accept a block */
- extern VALUE rb_mod_initialize(VALUE);
- rb_define_method(*(VALUE *)mdl, "initialize", rb_mod_initialize, 0);
+ rb_objc_define_method(*(VALUE *)mdl, "initialize", rb_mod_initialize, 0);
}
return mdl;
View
@@ -164,7 +164,7 @@ rb_enc_compatible(VALUE str1, VALUE str2)
*/
VALUE
-rb_obj_encoding(VALUE obj)
+rb_obj_encoding(VALUE obj, SEL sel)
{
rb_encoding *enc = rb_enc_get(obj);
if (!enc) {
View
@@ -107,7 +107,7 @@ PRINTF_ARGS(VALUE rb_enc_sprintf(rb_encoding *, const char*, ...), 2, 3);
VALUE rb_enc_vsprintf(rb_encoding *, const char*, va_list);
long rb_enc_strlen(const char*, const char*, rb_encoding*);
char* rb_enc_nth(const char*, const char*, int, rb_encoding*);
-VALUE rb_obj_encoding(VALUE);
+VALUE rb_obj_encoding(VALUE, SEL);
VALUE rb_enc_str_buf_cat(VALUE str, const char *ptr, long len, rb_encoding *enc);
/* index -> rb_encoding */
View
@@ -1556,7 +1556,7 @@ rb_class_s_alloc(VALUE klass, SEL sel)
VALUE rb_mod_module_exec(VALUE mod, SEL sel, int argc, VALUE *argv);
VALUE
-rb_mod_initialize(VALUE module)
+rb_mod_initialize(VALUE module, SEL sel)
{
if (rb_block_given_p()) {
rb_mod_module_exec(module, 0, 1, &module);
@@ -1614,7 +1614,7 @@ rb_class_initialize(int argc, VALUE *argv, VALUE klass)
rb_define_object_special_methods(klass);
rb_class_inherited(super, klass);
- rb_mod_initialize(klass);
+ rb_mod_initialize(klass, 0);
return klass;
}
View
4 proc.c
@@ -43,6 +43,7 @@ rb_proc_alloc_with_block(VALUE klass, rb_vm_block_t *proc)
{
VALUE obj;
obj = Data_Wrap_Struct(klass, NULL, NULL, proc);
+ proc->flags |= VM_BLOCK_PROC;
return obj;
}
@@ -192,7 +193,7 @@ proc_lambda_p(VALUE procval, SEL sel)
rb_vm_block_t *proc;
GetProcPtr(procval, proc);
- return proc->is_lambda ? Qtrue : Qfalse;
+ return proc->flags & VM_BLOCK_LAMBDA ? Qtrue : Qfalse;
}
/* Binding */
@@ -350,7 +351,6 @@ proc_new(VALUE klass, int is_lambda)
rb_raise(rb_eArgError,
"tried to create Proc object without a block");
}
- // FIXME current_block is not from autozone
return rb_proc_alloc_with_block(klass, current_block);
}
View
2 re.c
@@ -3558,7 +3558,7 @@ Init_Regexp(void)
rb_objc_define_method(rb_cRegexp, "source", rb_reg_source, 0);
rb_objc_define_method(rb_cRegexp, "casefold?", rb_reg_casefold_p, 0);
rb_objc_define_method(rb_cRegexp, "options", rb_reg_options_m, 0);
- rb_define_method(rb_cRegexp, "encoding", rb_obj_encoding, 0); /* in encoding.c */
+ rb_objc_define_method(rb_cRegexp, "encoding", rb_obj_encoding, 0); /* in encoding.c */
rb_objc_define_method(rb_cRegexp, "fixed_encoding?", rb_reg_fixed_encoding_p, 0);
rb_objc_define_method(rb_cRegexp, "names", rb_reg_names, 0);
rb_objc_define_method(rb_cRegexp, "named_captures", rb_reg_named_captures, 0);
View
@@ -2275,23 +2275,26 @@ RoxorCompiler::compile_node(NODE *node)
NODE *rhsn = node->nd_value;
assert(rhsn != NULL);
- NODE *splatn = node->nd_args;
- assert(splatn == NULL); // TODO
+ Value *ary = compile_node(rhsn);
NODE *lhsn = node->nd_head;
+
+ if (lhsn == NULL) {
+ // * = 1, 2
+ return ary;
+ }
+
assert(lhsn != NULL);
assert(nd_type(lhsn) == NODE_ARRAY);
- Value *ary = compile_node(rhsn); // XXX should always build as an array
- NODE *l = lhsn;
-
if (rhsnGetFunc == NULL) {
// VALUE rb_vm_rhsn_get(VALUE ary, int offset);
rhsnGetFunc = cast<Function>(module->getOrInsertFunction("rb_vm_rhsn_get",
RubyObjTy, RubyObjTy, Type::Int32Ty, NULL));
}
int i = 0;
+ NODE *l = lhsn;
while (l != NULL) {
NODE *ln = l->nd_head;
@@ -4892,7 +4895,7 @@ rb_vm_prepare_block(void *llvm_function, NODE *node, VALUE self,
b->imp = GET_VM()->compile((Function *)llvm_function);
b->arity = rb_vm_node_arity(node);
}
- b->is_lambda = true;
+ b->flags = 0;
b->dvars_size = dvars_size;
rb_objc_retain(b);
@@ -5354,6 +5357,16 @@ extern "C"
void
rb_vm_break(VALUE val)
{
+#if 0
+ // XXX this doesn't work yet since break is called inside the block and
+ // we do not have a reference to it. This isn't very important though,
+ // but since 1.9 doesn't support break without Proc objects we should also
+ // raise a similar exception.
+ assert(GET_VM()->current_block != NULL);
+ if (GET_VM()->current_block->flags & VM_BLOCK_PROC) {
+ rb_raise(rb_eLocalJumpError, "break from proc-closure");
+ }
+#endif
GET_VM()->broken_with = val;
}
View
@@ -94,12 +94,15 @@ typedef struct {
short real;
} rb_vm_arity_t;
+#define VM_BLOCK_PROC 0x0001 // block is a Proc object
+#define VM_BLOCK_LAMBDA 0x0002 // block is a lambda
+
typedef struct {
VALUE self;
NODE *node;
rb_vm_arity_t arity;
IMP imp;
- bool is_lambda;
+ int flags;
int dvars_size;
VALUE *dvars[1];
} rb_vm_block_t;
View
@@ -5507,7 +5507,7 @@ Init_String(void)
rb_objc_define_method(rb_cString, "partition", rb_str_partition, 1);
rb_objc_define_method(rb_cString, "rpartition", rb_str_rpartition, 1);
- rb_define_method(rb_cString, "encoding", rb_obj_encoding, 0); /* in encoding.c */
+ rb_objc_define_method(rb_cString, "encoding", rb_obj_encoding, 0); /* in encoding.c */
rb_objc_define_method(rb_cString, "force_encoding", rb_str_force_encoding, 1);
rb_objc_define_method(rb_cString, "valid_encoding?", rb_str_valid_encoding_p, 0);
rb_objc_define_method(rb_cString, "ascii_only?", rb_str_is_ascii_only_p, 0);
View
@@ -317,6 +317,7 @@ def foo; a,b,c=1,2,3; end
assert ':ok', "a, b, c = nil; p :ok if a == nil and b == nil and c == nil"
assert ':ok', '* = 1,2; p :ok'
+ assert '[1, 2]', 'x = (* = 1,2); p x'
# TODO add more multiple assignments test

0 comments on commit d5fb09e

Please sign in to comment.