mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-19 19:10:17 +00:00
...
This commit is contained in:
parent
b51bf33572
commit
34d620c82f
@ -75,6 +75,8 @@ bool py_exec(const char* source,
|
||||
enum py_CompileMode mode,
|
||||
py_Ref module) PY_RAISE;
|
||||
|
||||
/// Compile a source string into a code object.
|
||||
/// Use python's `exec()` or `eval()` to execute it.
|
||||
bool py_compile(const char* source,
|
||||
const char* filename,
|
||||
enum py_CompileMode mode,
|
||||
|
@ -463,7 +463,11 @@ static bool _builtins_execdyn(const char* title, int argc, py_Ref argv, enum py_
|
||||
|
||||
// [globals, locals, code]
|
||||
CodeObject* co = py_touserdata(code);
|
||||
if(!co->src->is_dynamic) py_shrink(3);
|
||||
if(!co->src->is_dynamic) {
|
||||
if(argc != 1)
|
||||
return ValueError("code object is not dynamic, so globals and locals must be None");
|
||||
py_shrink(3);
|
||||
}
|
||||
Frame* frame = pk_current_vm->top_frame;
|
||||
return pk_exec(co, frame ? frame->module : NULL);
|
||||
}
|
||||
|
@ -59,6 +59,9 @@ globals = {'a': 2}
|
||||
locals = {'b': 3}
|
||||
assert eval('a*b', globals, locals) == 6
|
||||
|
||||
code = compile('a*b', '<string>', 'eval')
|
||||
assert eval(code, globals, locals) == 6
|
||||
|
||||
try:
|
||||
exec('a*b*c', globals, locals)
|
||||
exit(1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user