diff --git a/src/compiler.h b/src/compiler.h index 928fbbee..314b48dc 100644 --- a/src/compiler.h +++ b/src/compiler.h @@ -321,8 +321,10 @@ public: void exprLambda() { _Func func; func.name = ""; - __compileFunctionArgs(func); - consume(TK(":")); + if(!match(TK(":"))){ + __compileFunctionArgs(func); + consume(TK(":")); + } func.code = std::make_shared(parser->src, func.name); this->codes.push(func.code); EXPR_TUPLE(); diff --git a/src/pocketpy.h b/src/pocketpy.h index e4f6f91e..5e244cda 100644 --- a/src/pocketpy.h +++ b/src/pocketpy.h @@ -497,11 +497,6 @@ void __initializeBuiltinFunctions(VM* _vm) { }); } -void __runCodeBuiltins(VM* vm, const char* src){ - _Code code = compile(vm, src, "builtins.py"); - if(code != nullptr) vm->exec(code, vm->builtins); -} - #include "builtins.h" #ifdef _WIN32 @@ -535,11 +530,15 @@ extern "C" { VM* createVM(PrintFn _stdout, PrintFn _stderr){ VM* vm = new VM(); __initializeBuiltinFunctions(vm); - __runCodeBuiltins(vm, __BUILTINS_CODE); - __addModuleSys(vm); - __addModuleTime(vm); vm->_stdout = _stdout; vm->_stderr = _stderr; + + _Code code = compile(vm, __BUILTINS_CODE, "builtins.py"); + if(code == nullptr) exit(1); + vm->_exec(code, vm->builtins); + + __addModuleSys(vm); + __addModuleTime(vm); return vm; } diff --git a/src/vm.h b/src/vm.h index 21c37261..1bb9c706 100644 --- a/src/vm.h +++ b/src/vm.h @@ -411,8 +411,7 @@ public: PyVar exec(const _Code& code, PyVar _module=nullptr){ if(_module == nullptr) _module = _main; try { - PyVarDict locals; - return _exec(code, _module, locals); + return _exec(code, _module); } catch (const std::exception& e) { if(const _Error* _ = dynamic_cast(&e)){ _stderr(e.what()); @@ -425,6 +424,11 @@ public: } } + PyVar _exec(const _Code& code, PyVar _module){ + PyVarDict locals; + return _exec(code, _module, locals); + } + PyVar _exec(const _Code& code, PyVar _module, PyVarDict& locals){ if(code == nullptr) UNREACHABLE(); Frame* frame = new Frame(