blueloveTH 1 год назад
Родитель
Сommit
6c46705e98
4 измененных файлов с 6 добавлено и 14 удалено
  1. 1 2
      src/interpreter/ceval.c
  2. 2 6
      src/public/py_ops.c
  3. 1 4
      src/public/vm.c
  4. 2 2
      src2/main.c

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

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

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

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