mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-21 12:00:18 +00:00
some fix
This commit is contained in:
parent
47c6639627
commit
c9b58e2270
@ -56,7 +56,8 @@ void __initializeBuiltinFunctions(VM* _vm) {
|
|||||||
if (!args[0]->isType(vm->_tp_str)) vm->typeError("eval() argument must be a string");
|
if (!args[0]->isType(vm->_tp_str)) vm->typeError("eval() argument must be a string");
|
||||||
const _Str& expr = vm->PyStr_AS_C(args[0]);
|
const _Str& expr = vm->PyStr_AS_C(args[0]);
|
||||||
_Code code = compile(vm, expr, "<eval>", EVAL_MODE);
|
_Code code = compile(vm, expr, "<eval>", EVAL_MODE);
|
||||||
return vm->exec(code); // not working in function
|
if(code == nullptr) return vm->None;
|
||||||
|
return vm->_exec(code); // not working in function
|
||||||
});
|
});
|
||||||
|
|
||||||
_vm->bindBuiltinFunc("repr", [](VM* vm, PyVarList args) {
|
_vm->bindBuiltinFunc("repr", [](VM* vm, PyVarList args) {
|
||||||
@ -413,7 +414,7 @@ void __initializeBuiltinFunctions(VM* _vm) {
|
|||||||
|
|
||||||
void __runCodeBuiltins(VM* vm, const char* src){
|
void __runCodeBuiltins(VM* vm, const char* src){
|
||||||
_Code code = compile(vm, src, "builtins.py");
|
_Code code = compile(vm, src, "builtins.py");
|
||||||
vm->exec(code, {}, vm->builtins);
|
if(code != nullptr) vm->_exec(code, {}, vm->builtins);
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "builtins.h"
|
#include "builtins.h"
|
||||||
|
25
src/vm.h
25
src/vm.h
@ -390,7 +390,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(i < args.size()) typeError("too many arguments");
|
if(i < args.size()) typeError("too many arguments");
|
||||||
return exec(fn.code, locals);
|
return _exec(fn.code, locals);
|
||||||
}
|
}
|
||||||
typeError("'" + callable->getTypeName() + "' object is not callable");
|
typeError("'" + callable->getTypeName() + "' object is not callable");
|
||||||
return None;
|
return None;
|
||||||
@ -399,18 +399,10 @@ public:
|
|||||||
inline PyVar call(const PyVar& obj, const _Str& func, PyVarList args){
|
inline PyVar call(const PyVar& obj, const _Str& func, PyVarList args){
|
||||||
return call(getAttr(obj, func), args);
|
return call(getAttr(obj, func), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
PyVar exec(const _Code& code, const PyVarDict& locals={}, PyVar _module=nullptr){
|
|
||||||
if(code == nullptr) UNREACHABLE();
|
|
||||||
if(_module == nullptr) _module = _main;
|
|
||||||
auto frame = std::make_shared<Frame>(
|
|
||||||
code.get(),
|
|
||||||
locals,
|
|
||||||
&_module->attribs
|
|
||||||
);
|
|
||||||
|
|
||||||
|
PyVar exec(const _Code& code, const PyVarDict& locals={}, PyVar _module=nullptr){
|
||||||
try {
|
try {
|
||||||
return runFrame(frame);
|
return _exec(code, locals, _module);
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
if(const _Error* _ = dynamic_cast<const _Error*>(&e)){
|
if(const _Error* _ = dynamic_cast<const _Error*>(&e)){
|
||||||
_stderr(e.what());
|
_stderr(e.what());
|
||||||
@ -422,6 +414,17 @@ public:
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PyVar _exec(const _Code& code, const PyVarDict& locals={}, PyVar _module=nullptr){
|
||||||
|
if(code == nullptr) UNREACHABLE();
|
||||||
|
if(_module == nullptr) _module = _main;
|
||||||
|
auto frame = std::make_shared<Frame>(
|
||||||
|
code.get(),
|
||||||
|
locals,
|
||||||
|
&_module->attribs
|
||||||
|
);
|
||||||
|
return runFrame(frame);
|
||||||
|
}
|
||||||
|
|
||||||
PyVar newUserClassType(_Str name, PyVar base){
|
PyVar newUserClassType(_Str name, PyVar base){
|
||||||
PyVar obj = newClassType(name, base);
|
PyVar obj = newClassType(name, base);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user