summaryrefslogtreecommitdiff
path: root/vm_eval.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-27 02:55:16 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-27 02:55:16 +0000
commited6680c1df1b86d7bec619afaca8de0f3f9fbb08 (patch)
treec2ab77b9cda226de0fc61dd1817a4ee993c28bfb /vm_eval.c
parent5f0dca59a3fff1b56dac9c49648299a0ad41019c (diff)
vm_eval.c: split eval_string_with_cref
* vm_eval.c (eval_string_with_cref): split into cref and scope modes, which are exclusive. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61493 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm_eval.c')
-rw-r--r--vm_eval.c85
1 files changed, 41 insertions, 44 deletions
diff --git a/vm_eval.c b/vm_eval.c
index d4f6542..23a85e3 100644
--- a/vm_eval.c
+++ b/vm_eval.c
@@ -1289,58 +1289,52 @@ eval_make_iseq(VALUE src, VALUE fname, int line, const rb_binding_t *bind,
}
static VALUE
-eval_string_with_cref(VALUE self, VALUE src, VALUE scope, rb_cref_t *cref, VALUE file, int line)
+eval_string_with_cref(VALUE self, VALUE src, rb_cref_t *cref, VALUE file, int line)
{
rb_execution_context_t *ec = GET_EC();
struct rb_block block;
- const struct rb_block *base_block;
+ const rb_iseq_t *iseq;
+ rb_control_frame_t *cfp = rb_vm_get_ruby_level_next_cfp(ec, ec->cfp);
+ if (!cfp) {
+ rb_raise(rb_eRuntimeError, "Can't eval on top of Fiber or Thread");
+ }
- {
- rb_binding_t *bind = 0;
- const rb_iseq_t *iseq;
+ block.as.captured = *VM_CFP_TO_CAPTURED_BLOCK(cfp);
+ block.as.captured.self = self;
+ block.as.captured.code.iseq = cfp->iseq;
+ block.type = block_type_iseq;
- if (!NIL_P(scope)) {
- bind = Check_TypedStruct(scope, &ruby_binding_data_type);
+ iseq = eval_make_iseq(src, file, line, NULL, &block);
+ if (!iseq) {
+ rb_exc_raise(ec->errinfo);
+ }
- base_block = &bind->block;
- }
- else {
- rb_control_frame_t *cfp = rb_vm_get_ruby_level_next_cfp(ec, ec->cfp);
-
- if (cfp != 0) {
- block.as.captured = *VM_CFP_TO_CAPTURED_BLOCK(cfp);
- block.as.captured.self = self;
- block.as.captured.code.iseq = cfp->iseq;
- block.type = block_type_iseq;
- base_block = &block;
- }
- else {
- rb_raise(rb_eRuntimeError, "Can't eval on top of Fiber or Thread");
- }
- }
+ /* TODO: what the code checking? */
+ if (!cref && block.as.captured.code.val) {
+ rb_cref_t *orig_cref = rb_vm_get_cref(vm_block_ep(&block));
+ cref = vm_cref_dup(orig_cref);
+ }
+ vm_set_eval_stack(ec, iseq, cref, &block);
- iseq = eval_make_iseq(src, file, line, bind, base_block);
- if (!iseq) {
- rb_exc_raise(ec->errinfo);
- }
+ /* kick */
+ return vm_exec(ec);
+}
- /* TODO: what the code checking? */
- if (!cref && base_block->as.captured.code.val) {
- if (NIL_P(scope)) {
- rb_cref_t *orig_cref = rb_vm_get_cref(vm_block_ep(base_block));
- cref = vm_cref_dup(orig_cref);
- }
- else {
- cref = NULL; /* use stacked CREF */
- }
- }
- vm_set_eval_stack(ec, iseq, cref, base_block);
+static VALUE
+eval_string_with_scope(VALUE scope, VALUE src, VALUE file, int line)
+{
+ rb_execution_context_t *ec = GET_EC();
+ rb_binding_t *bind = Check_TypedStruct(scope, &ruby_binding_data_type);
+ const rb_iseq_t *iseq = eval_make_iseq(src, file, line, bind, &bind->block);
+ if (!iseq) {
+ rb_exc_raise(ec->errinfo);
+ }
+ vm_set_eval_stack(ec, iseq, NULL, &bind->block);
- /* save new env */
- if (bind && iseq->body->local_table_size > 0) {
- vm_bind_update_env(scope, bind, vm_make_env_object(ec, ec->cfp));
- }
+ /* save new env */
+ if (iseq->body->local_table_size > 0) {
+ vm_bind_update_env(scope, bind, vm_make_env_object(ec, ec->cfp));
}
/* kick */
@@ -1350,7 +1344,10 @@ eval_string_with_cref(VALUE self, VALUE src, VALUE scope, rb_cref_t *cref, VALUE
static VALUE
eval_string(VALUE self, VALUE src, VALUE scope, VALUE file, int line)
{
- return eval_string_with_cref(self, src, scope, 0, file, line);
+ if (NIL_P(scope))
+ return eval_string_with_cref(self, src, NULL, file, line);
+ else
+ return eval_string_with_scope(scope, src, file, line);
}
/*
@@ -1598,7 +1595,7 @@ eval_under(VALUE under, VALUE self, VALUE src, VALUE file, int line)
{
rb_cref_t *cref = vm_cref_push(GET_EC(), under, NULL, SPECIAL_CONST_P(self) && !NIL_P(under));
SafeStringValue(src);
- return eval_string_with_cref(self, src, Qnil, cref, file, line);
+ return eval_string_with_cref(self, src, cref, file, line);
}
static VALUE