From 6c46705e9840dbedbc6fe3eddbb25587b7460c7f Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sat, 29 Jun 2024 19:39:28 +0800 Subject: [PATCH] some fix --- src/interpreter/ceval.c | 3 +-- src/public/py_ops.c | 8 ++------ src/public/vm.c | 5 +---- src2/main.c | 4 ++-- 4 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/interpreter/ceval.c b/src/interpreter/ceval.c index a859bf2f..8a0ae454 100644 --- a/src/interpreter/ceval.c +++ b/src/interpreter/ceval.c @@ -87,10 +87,9 @@ pk_FrameResult pk_VM__run_top_frame(pk_VM* self) { } case OP_PRINT_EXPR: if(TOP().type != tp_none_type) { - int err = py_repr(&TOP(), NULL); + int err = py_repr(&TOP(), &TOP()); if(err) goto __ERROR; self->_stdout("%s\n", py_tostr(&TOP())); - POP(); } POP(); DISPATCH(); diff --git a/src/public/py_ops.c b/src/public/py_ops.c index c609a2f3..c10c4ef5 100644 --- a/src/public/py_ops.c +++ b/src/public/py_ops.c @@ -11,10 +11,6 @@ int py_str(const py_Ref val, py_Ref out) { return 0; } int py_repr(const py_Ref val, py_Ref out) { const pk_TypeInfo* ti = c11__at(pk_TypeInfo, &pk_current_vm->types, val->type); - int err; - if(ti->m__repr__) err = ti->m__repr__(1, val); - err = py_callmethod(val, __repr__); - if(err) return err; - if(out) *out = *--pk_current_vm->stack.sp; - return 0; + if(ti->m__repr__) return ti->m__repr__(1, val); + return py_callmethod(val, __repr__); } \ No newline at end of file diff --git a/src/public/vm.c b/src/public/vm.c index c6dce675..0beef209 100644 --- a/src/public/vm.c +++ b/src/public/vm.c @@ -40,9 +40,6 @@ int py_eval(const char* source, py_Ref out) { CodeObject__dtor(&co); PK_DECREF(src); if(res == RES_ERROR) return vm->last_error->type; - if(res == RES_RETURN){ - if(out) *out = *--vm->stack.sp; - return 0; - } + if(res == RES_RETURN) return 0; PK_UNREACHABLE(); } \ No newline at end of file diff --git a/src2/main.c b/src2/main.c index 635dd94c..0e6d6629 100644 --- a/src2/main.c +++ b/src2/main.c @@ -27,7 +27,7 @@ int main(int argc, char** argv) { py_initialize(); const char* source = "[1, 'a']"; - if(py_eval(source, NULL)){ + if(py_eval(source, py_pushtmp())){ py_Error* err = py_getlasterror(); py_Error__print(err); }else{ @@ -37,7 +37,7 @@ int main(int argc, char** argv) { int _L0 = py_toint(_0); const char* _L1 = py_tostr(_1); printf("%d, %s\n", _L0, _L1); - py_pop(); + py_poptmp(1); } py_finalize();