This commit is contained in:
blueloveTH 2023-01-31 21:31:23 +08:00
parent c1485392cf
commit 6791c0784a
2 changed files with 11 additions and 1 deletions

View File

@ -838,7 +838,7 @@ __LISTCOMP:
EXPR_TUPLE(); EXPR_TUPLE();
consumeEndStatement(); consumeEndStatement();
} }
emit(OP_RETURN_VALUE); emit(OP_RETURN_VALUE, -1, true);
} else if (match(TK("if"))) { } else if (match(TK("if"))) {
compileIfStatement(); compileIfStatement();
} else if (match(TK("while"))) { } else if (match(TK("while"))) {

View File

@ -588,6 +588,15 @@ void __addModuleMath(VM* vm){
}); });
} }
void __addModuleDis(VM* vm){
PyVar mod = vm->new_module("dis");
vm->bindFunc<1>(mod, "dis", [](VM* vm, const pkpy::ArgList& args) {
_Code code = vm->PyFunction_AS_C(args[0])->code;
(*vm->_stdout) << vm->disassemble(code);
return vm->None;
});
}
#define PY_CLASS(mod, name) inline static PyVar _tp(VM* vm) { return vm->_modules[#mod]->attribs[#name]; } #define PY_CLASS(mod, name) inline static PyVar _tp(VM* vm) { return vm->_modules[#mod]->attribs[#name]; }
@ -790,6 +799,7 @@ extern "C" {
__addModuleJson(vm); __addModuleJson(vm);
__addModuleMath(vm); __addModuleMath(vm);
__addModuleRe(vm); __addModuleRe(vm);
__addModuleDis(vm);
// add builtins | no exception handler | must succeed // add builtins | no exception handler | must succeed
_Code code = vm->compile(__BUILTINS_CODE, "<builtins>", EXEC_MODE); _Code code = vm->compile(__BUILTINS_CODE, "<builtins>", EXEC_MODE);