diff options
| author | dearblue <[email protected]> | 2021-02-22 23:32:18 +0900 |
|---|---|---|
| committer | dearblue <[email protected]> | 2021-02-22 23:32:18 +0900 |
| commit | 792f6ac6700469ddf9be8f87ca3376082f9af7f3 (patch) | |
| tree | f04a5ffe00d4f442286a833b06d472941b20c93c /mrbgems/mruby-binding-core | |
| parent | 935ffa46a3a89a5f1662e5a4111ca0ed19566698 (diff) | |
| download | mruby-792f6ac6700469ddf9be8f87ca3376082f9af7f3.tar.gz mruby-792f6ac6700469ddf9be8f87ca3376082f9af7f3.zip | |
Adjustment of the current HEAD and bindings, and separation
Make changes to make `Binding` work.
At the same time, it separates `Binding#eval`, which depends on `mruby-eval`, from `mruby-binding-core`.
Diffstat (limited to 'mrbgems/mruby-binding-core')
| -rw-r--r-- | mrbgems/mruby-binding-core/mrbgem.rake | 4 | ||||
| -rw-r--r-- | mrbgems/mruby-binding-core/mrblib/binding-core.rb | 5 | ||||
| -rw-r--r-- | mrbgems/mruby-binding-core/src/binding-core.c | 33 | ||||
| -rw-r--r-- | mrbgems/mruby-binding-core/test/binding-core.rb | 8 |
4 files changed, 21 insertions, 29 deletions
diff --git a/mrbgems/mruby-binding-core/mrbgem.rake b/mrbgems/mruby-binding-core/mrbgem.rake index 1dbc768de..f6b34982f 100644 --- a/mrbgems/mruby-binding-core/mrbgem.rake +++ b/mrbgems/mruby-binding-core/mrbgem.rake @@ -1,7 +1,5 @@ -MRuby::Gem::Specification.new('mruby-binding') do |spec| +MRuby::Gem::Specification.new('mruby-binding-core') do |spec| spec.license = 'MIT' spec.author = 'mruby developers' spec.summary = 'Binding class' - - spec.add_dependency('mruby-eval', :core => 'mruby-eval') end diff --git a/mrbgems/mruby-binding-core/mrblib/binding-core.rb b/mrbgems/mruby-binding-core/mrblib/binding-core.rb deleted file mode 100644 index b07480db1..000000000 --- a/mrbgems/mruby-binding-core/mrblib/binding-core.rb +++ /dev/null @@ -1,5 +0,0 @@ -class Binding - def eval(expr, *args) - Kernel.eval(expr, self, *args) - end -end diff --git a/mrbgems/mruby-binding-core/src/binding-core.c b/mrbgems/mruby-binding-core/src/binding-core.c index 4899dcc20..0113fc030 100644 --- a/mrbgems/mruby-binding-core/src/binding-core.c +++ b/mrbgems/mruby-binding-core/src/binding-core.c @@ -1,39 +1,44 @@ -#include "mruby.h" -#include "mruby/array.h" -#include "mruby/hash.h" -#include "mruby/proc.h" -#include "mruby/variable.h" +#include <mruby.h> +#include <mruby/array.h> +#include <mruby/hash.h> +#include <mruby/proc.h> +#include <mruby/variable.h> +#include <mruby/presym.h> -mrb_value proc_local_variables(mrb_state *mrb, struct RProc *proc); +mrb_value mrb_proc_local_variables(mrb_state *mrb, const struct RProc *proc); static mrb_value binding_local_variables(mrb_state *mrb, mrb_value self) { - struct RProc *proc = mrb_proc_ptr(mrb_iv_get(mrb, self, mrb_intern_lit(mrb, "proc"))); - return proc_local_variables(mrb, proc); + const struct RProc *proc = mrb_proc_ptr(mrb_iv_get(mrb, self, MRB_SYM(proc))); + return mrb_proc_local_variables(mrb, proc); } +const struct RProc *mrb_proc_get_caller(mrb_state *mrb, struct REnv **env); + static mrb_value mrb_f_binding(mrb_state *mrb, mrb_value self) { struct RObject *obj; mrb_value binding; struct RProc *proc; - mrb_int i; + struct REnv *env; obj = (struct RObject*)mrb_obj_alloc(mrb, MRB_TT_OBJECT, mrb_class_get(mrb, "Binding")); binding = mrb_obj_value(obj); - proc = mrb->c->ci[-1].proc; - mrb_iv_set(mrb, binding, mrb_intern_lit(mrb, "proc"), mrb_obj_value(proc)); - mrb_iv_set(mrb, binding, mrb_intern_lit(mrb, "recv"), self); + proc = (struct RProc*)mrb_proc_get_caller(mrb, &env); + mrb_iv_set(mrb, binding, MRB_SYM(proc), mrb_obj_value(proc)); + mrb_iv_set(mrb, binding, MRB_SYM(recv), self); + mrb_iv_set(mrb, binding, MRB_SYM(env), mrb_obj_value(env)); return binding; } void -mrb_mruby_binding_gem_init(mrb_state *mrb) +mrb_mruby_binding_core_gem_init(mrb_state *mrb) { struct RClass *binding = mrb_define_class(mrb, "Binding", mrb->object_class); mrb_undef_class_method(mrb, binding, "new"); + mrb_undef_class_method(mrb, binding, "allocate"); mrb_define_method(mrb, mrb->kernel_module, "binding", mrb_f_binding, MRB_ARGS_NONE()); @@ -41,6 +46,6 @@ mrb_mruby_binding_gem_init(mrb_state *mrb) } void -mrb_mruby_binding_gem_final(mrb_state *mrb) +mrb_mruby_binding_core_gem_final(mrb_state *mrb) { } diff --git a/mrbgems/mruby-binding-core/test/binding-core.rb b/mrbgems/mruby-binding-core/test/binding-core.rb index 3bed9b31e..d93f43619 100644 --- a/mrbgems/mruby-binding-core/test/binding-core.rb +++ b/mrbgems/mruby-binding-core/test/binding-core.rb @@ -7,11 +7,5 @@ assert("Binding#local_variables") do b = 1 binding end - assert_equal [:a, :b, :block], block.call(0).local_variables -end - -assert("Binding#eval") do - b = nil - 1.times { x, y, z = 1, 2, 3; [x,y,z]; b = binding } - assert_equal([1, 2, 3], b.eval("[x, y, z]")) + assert_equal [:a, :b, :block], block.call(0).local_variables.sort end |
