From 4a5f74b2d2fd16e16a7fadc032e83e14b62a3386 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sat, 29 Jun 2024 18:54:05 +0800 Subject: [PATCH] some move --- include/pocketpy/pocketpy.h | 10 +++++++--- src/interpreter/ceval.c | 7 +++---- src/interpreter/py_ops.c | 14 -------------- src/public/py_ops.c | 16 ++++++++++++++++ src/public/{stackops.c => stack_ops.c} | 0 src/public/values.c | 4 ++-- 6 files changed, 28 insertions(+), 23 deletions(-) delete mode 100644 src/interpreter/py_ops.c create mode 100644 src/public/py_ops.c rename src/public/{stackops.c => stack_ops.c} (100%) diff --git a/include/pocketpy/pocketpy.h b/include/pocketpy/pocketpy.h index d3d30950..0ae27667 100644 --- a/include/pocketpy/pocketpy.h +++ b/include/pocketpy/pocketpy.h @@ -146,6 +146,13 @@ 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); +int py_repr(const py_Ref); + +int py_vectorcall(int argc, int kwargc); +int py_call(py_Ref f, ...); +int py_callmethod(py_Ref self, py_Name name, ...); + #define py_isnull(self) ((self)->type == 0) /* tuple */ @@ -175,9 +182,6 @@ void py_dict__setitem(py_Ref self, const py_Ref key, const py_Ref val); void py_dict__delitem(py_Ref self, const py_Ref key); void py_dict__clear(py_Ref self); -int py_str(const py_Ref, py_Str* out); -int py_repr(const py_Ref, py_Str* out); - #ifdef __cplusplus } #endif diff --git a/src/interpreter/ceval.c b/src/interpreter/ceval.c index 0810a505..f62ac75e 100644 --- a/src/interpreter/ceval.c +++ b/src/interpreter/ceval.c @@ -83,11 +83,10 @@ pk_FrameResult pk_VM__run_top_frame(pk_VM* self) { } case OP_PRINT_EXPR: if(TOP().type != tp_none_type) { - py_Str out; - int err = py_repr(&TOP(), &out); + int err = py_repr(&TOP()); if(err) goto __ERROR; - self->_stdout("%s\n", py_Str__data(&out)); - py_Str__dtor(&out); + self->_stdout("%s\n", py_tostr(&TOP())); + POP(); } POP(); DISPATCH(); diff --git a/src/interpreter/py_ops.c b/src/interpreter/py_ops.c deleted file mode 100644 index abf41701..00000000 --- a/src/interpreter/py_ops.c +++ /dev/null @@ -1,14 +0,0 @@ -#include "pocketpy/interpreter/vm.h" -#include "pocketpy/pocketpy.h" - -int py_eq(const py_Ref lhs, const py_Ref rhs){ - return 0; -} - -int py_le(const py_Ref lhs, const py_Ref rhs){ - return 0; -} - -int py_hash(const py_Ref self, int64_t* out){ - return 0; -} \ No newline at end of file diff --git a/src/public/py_ops.c b/src/public/py_ops.c new file mode 100644 index 00000000..41baa2e4 --- /dev/null +++ b/src/public/py_ops.c @@ -0,0 +1,16 @@ +#include "pocketpy/interpreter/vm.h" +#include "pocketpy/pocketpy.h" + +int py_eq(const py_Ref lhs, const py_Ref rhs) { return 0; } + +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) { return 0; } + +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__); +} \ No newline at end of file diff --git a/src/public/stackops.c b/src/public/stack_ops.c similarity index 100% rename from src/public/stackops.c rename to src/public/stack_ops.c diff --git a/src/public/values.c b/src/public/values.c index ef66b5ce..bf769541 100644 --- a/src/public/values.c +++ b/src/public/values.c @@ -95,9 +95,9 @@ void py_pushstr(const char* val) { py_newstr(pk_current_vm->stack.sp++, val); } void py_pushstrn(const char* val, int size) { py_newstrn(pk_current_vm->stack.sp++, val, size); } -void py_push_none() { py_newnone(pk_current_vm->stack.sp++); } +void py_pushnone() { py_newnone(pk_current_vm->stack.sp++); } -void py_push_null() { py_newnull(pk_current_vm->stack.sp++); } +void py_pushnull() { py_newnull(pk_current_vm->stack.sp++); } void py_push_notimplemented() { pk_VM* vm = pk_current_vm;