Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop running after eval #3429

Closed
ksss opened this issue Feb 5, 2017 · 4 comments
Closed

Stop running after eval #3429

ksss opened this issue Feb 5, 2017 · 4 comments

Comments

@ksss
Copy link
Contributor

@ksss ksss commented Feb 5, 2017

From 48e0bbb

$ cat t.rb
p "---"
p eval "1"
p "---"

Before (bf4e79c )

$ mruby -v t.rb
mruby 1.2.0 (2015-11-17)
00001 NODE_SCOPE:
00001   NODE_BEGIN:
00001     NODE_FCALL:
00001       NODE_SELF
00001       method='p' (385)
00001       args:
00001         NODE_STR "---" len 3
00002     NODE_FCALL:
00002       NODE_SELF
00002       method='p' (385)
00002       args:
00002         NODE_FCALL:
00002           NODE_SELF
00002           method='eval' (507)
00002           args:
00002             NODE_STR "1" len 1
00003     NODE_FCALL:
00003       NODE_SELF
00003       method='p' (385)
00003       args:
00003         NODE_STR "---" len 3
irep 0x7fc01ac36430 nregs=5 nlocals=1 pools=2 syms=2 reps=0
file: t.rb
    1 000 OP_LOADSELF	R1
    1 001 OP_STRING	R2	L(0)	; "---"
    1 002 OP_SEND	R1	:p	1
    2 003 OP_LOADSELF	R1
    2 004 OP_LOADSELF	R2
    2 005 OP_STRING	R3	L(1)	; "1"
    2 006 OP_SEND	R2	:eval	1
    2 007 OP_SEND	R1	:p	1
    3 008 OP_LOADSELF	R1
    3 009 OP_STRING	R2	L(0)	; "---"
    3 010 OP_SEND	R1	:p	1
    3 011 OP_STOP

"---"
1
"---"

After ( 48e0bbb )

mruby 1.2.0 (2015-11-17)
00001 NODE_SCOPE:
00001   NODE_BEGIN:
00001     NODE_FCALL:
00001       NODE_SELF
00001       method='p' (385)
00001       args:
00001         NODE_STR "---" len 3
00002     NODE_FCALL:
00002       NODE_SELF
00002       method='p' (385)
00002       args:
00002         NODE_FCALL:
00002           NODE_SELF
00002           method='eval' (507)
00002           args:
00002             NODE_STR "1" len 1
00003     NODE_FCALL:
00003       NODE_SELF
00003       method='p' (385)
00003       args:
00003         NODE_STR "---" len 3
irep 0x7fff1fc317a0 nregs=5 nlocals=1 pools=2 syms=2 reps=0
file: t.rb
    1 000 OP_LOADSELF	R1
    1 001 OP_STRING	R2	L(0)	; "---"
    1 002 OP_SEND	R1	:p	1
    2 003 OP_LOADSELF	R1
    2 004 OP_LOADSELF	R2
    2 005 OP_STRING	R3	L(1)	; "1"
    2 006 OP_SEND	R2	:eval	1
    2 007 OP_SEND	R1	:p	1
    3 008 OP_LOADSELF	R1
    3 009 OP_STRING	R2	L(0)	; "---"
    3 010 OP_SEND	R1	:p	1
    3 011 OP_STOP

"---"
@christopheraue
Copy link
Contributor

@christopheraue christopheraue commented Feb 15, 2017

In the meantime, explicitly returning in eval is a workaround:

$ cat t.rb
p "---"
p eval "return 1"
p "---"

$ mruby t.rb 
"---"
1
"---"

@matz
Copy link
Member

@matz matz commented Feb 16, 2017

The fix is easy by the following patch, but we still have a related scoping bug.

diff --git a/mrbgems/mruby-eval/src/eval.c b/mrbgems/mruby-eval/src/eval.c
index 81bc802..bf614f3 100644
--- a/mrbgems/mruby-eval/src/eval.c
+++ b/mrbgems/mruby-eval/src/eval.c
@@ -131,6 +131,10 @@ patch_irep(mrb_state *mrb, mrb_irep *irep, int bnest)
         }
       }
       break;
+
+    case OP_STOP:
+      irep->iseq[i] = MKOP_AB(OP_RETURN, irep->nlocals, OP_R_NORMAL);
+      break;
     }
   }
 }
@@ -218,6 +222,7 @@ f_eval(mrb_state *mrb, mrb_value self)
 
   proc = create_proc_from_string(mrb, s, len, binding, file, line);
   mrb_assert(!MRB_PROC_CFUNC_P(proc));
+  // mrb_codedump_all(mrb, proc);
   return mrb_exec_irep(mrb, self, proc);
 }

@christopheraue
Copy link
Contributor

@christopheraue christopheraue commented Feb 16, 2017

Which scoping bug?

@matz
Copy link
Member

@matz matz commented Feb 16, 2017

@christopheraue A bug caused by a=1; eval "b=2; lambda{c=3; p [a,b,c]}.call.
But 5e3c329 fixed the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants