diff --git a/src/pocketpy.h b/src/pocketpy.h index 53800186..220ae1c4 100644 --- a/src/pocketpy.h +++ b/src/pocketpy.h @@ -62,14 +62,12 @@ void __initializeBuiltinFunctions(VM* _vm) { }); _vm->bindBuiltinFunc<1>("eval", [](VM* vm, const pkpy::ArgList& args) { - const _Str& expr = vm->PyStr_AS_C(args[0]); - _Code code = vm->compile(expr, "", EVAL_MODE); + _Code code = vm->compile(vm->PyStr_AS_C(args[0]), "", EVAL_MODE); return vm->_exec(code, vm->top_frame()->_module, vm->top_frame()->_locals); }); _vm->bindBuiltinFunc<1>("exec", [](VM* vm, const pkpy::ArgList& args) { - const _Str& expr = vm->PyStr_AS_C(args[0]); - _Code code = vm->compile(expr, "", EXEC_MODE); + _Code code = vm->compile(vm->PyStr_AS_C(args[0]), "", EXEC_MODE); vm->_exec(code, vm->top_frame()->_module, vm->top_frame()->_locals); return vm->None; }); diff --git a/src/repl.h b/src/repl.h index e8603125..d243dacd 100644 --- a/src/repl.h +++ b/src/repl.h @@ -44,16 +44,13 @@ __NOT_ENOUGH_LINES: } try{ - vm->compile(line, "", mode); + vm->exec(line, "", mode); }catch(NeedMoreLines& ne){ buffer += line; buffer += '\n'; need_more_lines = ne.isClassDef ? 3 : 2; if (need_more_lines) return NEED_MORE_LINES; - }catch(...){ - // do nothing } - vm->exec(line, "", mode); return EXEC_STARTED; } }; \ No newline at end of file diff --git a/tests/_eval.py b/tests/_eval.py index 2d7f4e11..847ba91e 100644 --- a/tests/_eval.py +++ b/tests/_eval.py @@ -17,4 +17,10 @@ def f(x): exec('a = x') return a -assert f(2) == 2 \ No newline at end of file +assert f(2) == 2 + +exec( + "exec('a = eval(\"3 + 5\")')" +) + +assert a == 8 \ No newline at end of file