[macruby-changes] [1552] MacRuby/branches/experimental
source_changes at macosforge.org
source_changes at macosforge.org
Thu May 7 15:05:47 PDT 2009
Revision: 1552
http://trac.macosforge.org/projects/ruby/changeset/1552
Author: lsansonetti at apple.com
Date: 2009-05-07 15:05:46 -0700 (Thu, 07 May 2009)
Log Message:
-----------
fixed Proc.new & co so that it actually looks at the previously-pushed block if there is no current one, in order to conform to some kind of inconsistent Ruby behavior (which is unfortunately used in optparse.rb and also supported in 1.9)
Modified Paths:
--------------
MacRuby/branches/experimental/proc.c
MacRuby/branches/experimental/roxor.cpp
MacRuby/branches/experimental/roxor.h
MacRuby/branches/experimental/test_vm/block.rb
Modified: MacRuby/branches/experimental/proc.c
===================================================================
--- MacRuby/branches/experimental/proc.c 2009-05-07 21:52:44 UTC (rev 1551)
+++ MacRuby/branches/experimental/proc.c 2009-05-07 22:05:46 UTC (rev 1552)
@@ -295,60 +295,23 @@
static VALUE
proc_new(VALUE klass, int is_lambda)
{
-#if 0
- VALUE procval = Qnil;
- rb_thread_t *th = GET_THREAD();
- rb_control_frame_t *cfp = th->cfp;
- rb_block_t *block;
-
- if ((GC_GUARDED_PTR_REF(cfp->lfp[0])) != 0 &&
- !RUBY_VM_CLASS_SPECIAL_P(cfp->lfp[0])) {
-
- block = GC_GUARDED_PTR_REF(cfp->lfp[0]);
- cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
+ rb_vm_block_t *block = rb_vm_current_block();
+ if (block == NULL) {
+ /* If the current block is NULL, let's check if there is a previous
+ * block. This is to conform to some dark Ruby behaviors, such as:
+ *
+ * def foo; Proc.new; end; foo { p 42 }.call
+ *
+ * def foo(x=Proc.new); x.call; end; foo { p 42 }
+ */
+ block = rb_vm_previous_block();
}
- else {
- cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
- if ((GC_GUARDED_PTR_REF(cfp->lfp[0])) != 0 &&
- !RUBY_VM_CLASS_SPECIAL_P(cfp->lfp[0])) {
-
- block = GC_GUARDED_PTR_REF(cfp->lfp[0]);
-
- /* TODO: check more (cfp limit, called via cfunc, etc) */
- while (cfp->dfp != block->dfp) {
- cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
- }
-
- if (is_lambda) {
- rb_warn("tried to create Proc object without a block");
- }
- }
- else {
- rb_raise(rb_eArgError,
- "tried to create Proc object without a block");
- }
- }
-
- if (block->proc) {
- return block->proc;
- }
-
- procval = vm_make_proc(th, cfp, block);
-
- if (is_lambda) {
- rb_proc_t *proc;
- GetProcPtr(procval, proc);
- proc->is_lambda = Qtrue;
- }
- return procval;
-#endif
- rb_vm_block_t *current_block = rb_vm_current_block();
- if (current_block == NULL) {
+ if (block == NULL) {
rb_raise(rb_eArgError,
"tried to create Proc object without a block");
}
- return rb_proc_alloc_with_block(klass, current_block);
+ return rb_proc_alloc_with_block(klass, block);
}
/*
Modified: MacRuby/branches/experimental/roxor.cpp
===================================================================
--- MacRuby/branches/experimental/roxor.cpp 2009-05-07 21:52:44 UTC (rev 1551)
+++ MacRuby/branches/experimental/roxor.cpp 2009-05-07 22:05:46 UTC (rev 1552)
@@ -8255,6 +8255,13 @@
}
extern "C"
+rb_vm_block_t *
+rb_vm_previous_block(void)
+{
+ return GET_VM()->previous_block;
+}
+
+extern "C"
void
rb_vm_change_current_block(rb_vm_block_t *block)
{
Modified: MacRuby/branches/experimental/roxor.h
===================================================================
--- MacRuby/branches/experimental/roxor.h 2009-05-07 21:52:44 UTC (rev 1551)
+++ MacRuby/branches/experimental/roxor.h 2009-05-07 22:05:46 UTC (rev 1552)
@@ -147,6 +147,7 @@
rb_vm_block_t *parent_block,
int dvars_size, ...);
rb_vm_block_t *rb_vm_current_block(void);
+rb_vm_block_t *rb_vm_previous_block(void);
bool rb_vm_block_saved(void);
void rb_vm_change_current_block(rb_vm_block_t *block);
void rb_vm_restore_current_block(void);
Modified: MacRuby/branches/experimental/test_vm/block.rb
===================================================================
--- MacRuby/branches/experimental/test_vm/block.rb 2009-05-07 21:52:44 UTC (rev 1551)
+++ MacRuby/branches/experimental/test_vm/block.rb 2009-05-07 22:05:46 UTC (rev 1552)
@@ -401,3 +401,11 @@
def bar; p :ok if block_given?; self; end
foo.bar {}
}
+
+assert ':ok', %{
+ def foo; Proc.new; end; foo { p :ok }.call
+}
+
+assert ':ok', %{
+ def foo(x=Proc.new); x.call; end; foo { p :ok }
+}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090507/42afadde/attachment.html>
More information about the macruby-changes
mailing list