diff --git a/include/pocketpy/pocketpy.h b/include/pocketpy/pocketpy.h index 1e156250..03eaef54 100644 --- a/include/pocketpy/pocketpy.h +++ b/include/pocketpy/pocketpy.h @@ -30,8 +30,8 @@ void py_finalize(); /// Run a simple source string. Do not change the stack. int py_exec(const char*); -/// Eval a simple expression. -int py_eval(const char*, py_Ref out); +/// Eval a simple expression. The result is pushed to the stack. +int py_eval(const char*); /************* Values Creation *************/ void py_newint(py_Ref, int64_t); @@ -156,8 +156,8 @@ int py_eq(const py_Ref, const py_Ref); int py_le(const py_Ref, const py_Ref); int py_hash(const py_Ref, int64_t* out); -int py_str(const py_Ref, py_Ref out); -int py_repr(const py_Ref, py_Ref out); +int py_str(const py_Ref); +int py_repr(const py_Ref); int py_vectorcall(int argc, int kwargc); int py_call(py_Ref f, ...); diff --git a/src/interpreter/ceval.c b/src/interpreter/ceval.c index 8a0ae454..b30bfc16 100644 --- a/src/interpreter/ceval.c +++ b/src/interpreter/ceval.c @@ -87,9 +87,10 @@ 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(), &TOP()); + int err = py_repr(&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 c10c4ef5..41baa2e4 100644 --- a/src/public/py_ops.c +++ b/src/public/py_ops.c @@ -7,9 +7,9 @@ int py_le(const py_Ref lhs, const py_Ref rhs) { return 0; } int py_hash(const py_Ref val, int64_t* out) { return 0; } -int py_str(const py_Ref val, py_Ref out) { return 0; } +int py_str(const py_Ref val) { return 0; } -int py_repr(const py_Ref val, py_Ref out) { +int py_repr(const py_Ref val) { const pk_TypeInfo* ti = c11__at(pk_TypeInfo, &pk_current_vm->types, val->type); if(ti->m__repr__) return ti->m__repr__(1, val); return py_callmethod(val, __repr__); diff --git a/src/public/vm.c b/src/public/vm.c index 0beef209..cc4b8a36 100644 --- a/src/public/vm.c +++ b/src/public/vm.c @@ -25,7 +25,7 @@ void py_finalize() { int py_exec(const char* source) { PK_UNREACHABLE(); } -int py_eval(const char* source, py_Ref out) { +int py_eval(const char* source) { CodeObject co; pk_SourceData_ src = pk_SourceData__rcnew(source, "main.py", EVAL_MODE, false); Error* err = pk_compile(src, &co); diff --git a/src2/main.c b/src2/main.c index 0e6d6629..ad4867ec 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, py_pushtmp())){ + if(py_eval(source)){ 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_poptmp(1); + py_pop(); } py_finalize();