mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
up
This commit is contained in:
parent
57c8f9ede4
commit
2008ecbd0f
@ -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>", EVAL_MODE);
|
||||
_Code code = vm->compile(vm->PyStr_AS_C(args[0]), "<eval>", 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>", EXEC_MODE);
|
||||
_Code code = vm->compile(vm->PyStr_AS_C(args[0]), "<exec>", EXEC_MODE);
|
||||
vm->_exec(code, vm->top_frame()->_module, vm->top_frame()->_locals);
|
||||
return vm->None;
|
||||
});
|
||||
|
@ -44,16 +44,13 @@ __NOT_ENOUGH_LINES:
|
||||
}
|
||||
|
||||
try{
|
||||
vm->compile(line, "<stdin>", mode);
|
||||
vm->exec(line, "<stdin>", 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, "<stdin>", mode);
|
||||
return EXEC_STARTED;
|
||||
}
|
||||
};
|
@ -17,4 +17,10 @@ def f(x):
|
||||
exec('a = x')
|
||||
return a
|
||||
|
||||
assert f(2) == 2
|
||||
assert f(2) == 2
|
||||
|
||||
exec(
|
||||
"exec('a = eval(\"3 + 5\")')"
|
||||
)
|
||||
|
||||
assert a == 8
|
Loading…
x
Reference in New Issue
Block a user