blueloveTH 1 an în urmă
părinte
comite
f53ae5e459
5 a modificat fișierele cu 11 adăugiri și 10 ștergeri
  1. 4 4
      include/pocketpy/pocketpy.h
  2. 2 1
      src/interpreter/ceval.c
  3. 2 2
      src/public/py_ops.c
  4. 1 1
      src/public/vm.c
  5. 2 2
      src2/main.c

+ 4 - 4
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, ...);

+ 2 - 1
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();

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

+ 1 - 1
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);

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