blueloveTH 1 год назад
Родитель
Сommit
4a5f74b2d2

+ 7 - 3
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

+ 3 - 4
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();

+ 0 - 14
src/interpreter/py_ops.c

@@ -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;
-}

+ 16 - 0
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__);
+}

+ 0 - 0
src/public/stackops.c → src/public/stack_ops.c


+ 2 - 2
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;