[macruby-changes] [1913] MacRuby/branches/experimental
source_changes at macosforge.org
source_changes at macosforge.org
Sat Jun 20 16:43:28 PDT 2009
Revision: 1913
http://trac.macosforge.org/projects/ruby/changeset/1913
Author: lsansonetti at apple.com
Date: 2009-06-20 16:43:28 -0700 (Sat, 20 Jun 2009)
Log Message:
-----------
Symbol#to_proc: implemented
Modified Paths:
--------------
MacRuby/branches/experimental/include/ruby/intern.h
MacRuby/branches/experimental/proc.c
MacRuby/branches/experimental/string.c
MacRuby/branches/experimental/test_vm/block.rb
MacRuby/branches/experimental/vm.cpp
MacRuby/branches/experimental/vm.h
Modified: MacRuby/branches/experimental/include/ruby/intern.h
===================================================================
--- MacRuby/branches/experimental/include/ruby/intern.h 2009-06-20 22:17:42 UTC (rev 1912)
+++ MacRuby/branches/experimental/include/ruby/intern.h 2009-06-20 23:43:28 UTC (rev 1913)
@@ -274,7 +274,6 @@
VALUE rb_class_new_instance(int, VALUE*, VALUE);
VALUE rb_block_proc(void);
VALUE rb_f_lambda(void);
-VALUE rb_proc_new(VALUE (*)(ANYARGS/* VALUE yieldarg[, VALUE procarg] */), VALUE);
VALUE rb_proc_call(VALUE, VALUE);
int rb_proc_arity(VALUE);
VALUE rb_binding_new(void);
Modified: MacRuby/branches/experimental/proc.c
===================================================================
--- MacRuby/branches/experimental/proc.c 2009-06-20 22:17:42 UTC (rev 1912)
+++ MacRuby/branches/experimental/proc.c 2009-06-20 23:43:28 UTC (rev 1913)
@@ -1350,16 +1350,6 @@
}
#endif
-VALUE
-rb_proc_new(
- VALUE (*func)(ANYARGS), /* VALUE yieldarg[, VALUE procarg] */
- VALUE val)
-{
-// VALUE procval = rb_iterate(mproc, 0, func, val);
-// return procval;
- return Qnil;
-}
-
/*
* call-seq:
* meth.to_proc => prc
@@ -1432,11 +1422,14 @@
return Data_Wrap_Struct(rb_cBinding, NULL, NULL, binding);
}
-static VALUE curry(VALUE dummy, VALUE args, int argc, VALUE *argv);
+//static VALUE curry(VALUE dummy, VALUE args, int argc, VALUE *argv);
static VALUE
make_curry_proc(VALUE proc, VALUE passed, VALUE arity)
{
+ // TODO
+ return Qnil;
+#if 0
#if WITH_OBJC
VALUE args = rb_ary_new3(3, proc, passed, arity);
#else
@@ -1449,8 +1442,10 @@
rb_ary_freeze(passed);
rb_ary_freeze(args);
return rb_proc_new(curry, args);
+#endif
}
+#if 0
static VALUE
curry(VALUE dummy, VALUE args, int argc, VALUE *argv)
{
@@ -1468,9 +1463,10 @@
arity = rb_proc_call(proc, passed);
return arity;
}
+#endif
/*
- * call-seq:
+ curry* call-seq:
* prc.curry => a_proc
* prc.curry(arity) => a_proc
*
Modified: MacRuby/branches/experimental/string.c
===================================================================
--- MacRuby/branches/experimental/string.c 2009-06-20 22:17:42 UTC (rev 1912)
+++ MacRuby/branches/experimental/string.c 2009-06-20 23:43:28 UTC (rev 1913)
@@ -5065,18 +5065,6 @@
return sym;
}
-static VALUE
-sym_call(VALUE args, VALUE sym, int argc, VALUE *argv)
-{
- VALUE obj;
-
- if (argc < 1) {
- rb_raise(rb_eArgError, "no receiver given");
- }
- obj = argv[0];
- return rb_funcall3(obj, (ID)sym, argc - 1, argv + 1);
-}
-
/*
* call-seq:
* sym.to_proc
@@ -5089,7 +5077,9 @@
static VALUE
sym_to_proc(VALUE sym, SEL sel)
{
- return rb_proc_new(sym_call, (VALUE)SYM2ID(sym));
+ SEL msel = sel_registerName(rb_id2name(SYM2ID(sym)));
+ rb_vm_block_t *b = rb_vm_create_block_calling_sel(msel);
+ return rb_proc_alloc_with_block(rb_cProc, b);
}
ID
Modified: MacRuby/branches/experimental/test_vm/block.rb
===================================================================
--- MacRuby/branches/experimental/test_vm/block.rb 2009-06-20 22:17:42 UTC (rev 1912)
+++ MacRuby/branches/experimental/test_vm/block.rb 2009-06-20 23:43:28 UTC (rev 1913)
@@ -521,3 +521,14 @@
p :ok if foo == 42
p :ok if $!.nil?
}
+
+assert ':ok', %{
+ b = :foo.to_proc
+ begin
+ b.call
+ rescue ArgumentError
+ p :ok
+ end
+}
+
+assert '[2, 3, 4]', "p [1, 2, 3].map(&:succ)"
Modified: MacRuby/branches/experimental/vm.cpp
===================================================================
--- MacRuby/branches/experimental/vm.cpp 2009-06-20 22:17:42 UTC (rev 1912)
+++ MacRuby/branches/experimental/vm.cpp 2009-06-20 23:43:28 UTC (rev 1913)
@@ -3088,8 +3088,6 @@
return GET_VM()->current_block();
}
-extern "C" VALUE rb_proc_alloc_with_block(VALUE klass, rb_vm_block_t *proc);
-
extern "C"
VALUE
rb_vm_current_block_object(void)
@@ -3187,6 +3185,31 @@
return b;
}
+static VALUE
+rb_vm_block_call_sel(VALUE rcv, SEL sel, VALUE **dvars, rb_vm_block_t *b,
+ VALUE x)
+{
+ if (x == Qnil) {
+ rb_raise(rb_eArgError, "no receiver given");
+ }
+ return rb_vm_call(x, (SEL)dvars[0], 0, NULL, false);
+}
+
+extern "C"
+rb_vm_block_t *
+rb_vm_create_block_calling_sel(SEL sel)
+{
+ rb_vm_block_t *b = (rb_vm_block_t *)xmalloc(sizeof(rb_vm_block_t)
+ + sizeof(VALUE *));
+
+ b->arity = rb_vm_arity(1);
+ b->flags = VM_BLOCK_PROC;
+ b->imp = (IMP)rb_vm_block_call_sel;
+ b->dvars[0] = (VALUE *)sel;
+
+ return b;
+}
+
static inline VALUE
rb_vm_block_eval0(rb_vm_block_t *b, VALUE self, int argc, const VALUE *argv)
{
Modified: MacRuby/branches/experimental/vm.h
===================================================================
--- MacRuby/branches/experimental/vm.h 2009-06-20 22:17:42 UTC (rev 1912)
+++ MacRuby/branches/experimental/vm.h 2009-06-20 23:43:28 UTC (rev 1913)
@@ -285,8 +285,12 @@
GC_WB(&robj->slots[slot], val);
}
+// Defined in proc.c
+VALUE rb_proc_alloc_with_block(VALUE klass, rb_vm_block_t *proc);
+
rb_vm_method_t *rb_vm_get_method(VALUE klass, VALUE obj, ID mid, int scope);
rb_vm_block_t *rb_vm_create_block_from_method(rb_vm_method_t *method);
+rb_vm_block_t *rb_vm_create_block_calling_sel(SEL sel);
static inline rb_vm_block_t *
rb_proc_get_block(VALUE proc)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090620/24446b20/attachment.html>
More information about the macruby-changes
mailing list