blueloveTH 1 anno fa
parent
commit
ac19ece535
2 ha cambiato i file con 11 aggiunte e 44 eliminazioni
  1. 11 12
      include/pocketpy/pocketpy.h
  2. 0 32
      src/public/stack_ops.c

+ 11 - 12
include/pocketpy/pocketpy.h

@@ -177,27 +177,26 @@ bool py_binaryop(const py_Ref lhs, const py_Ref rhs, py_Name op, py_Name rop);
 void py_assign(py_Ref dst, const py_Ref src);
 
 /************* Stack Operations *************/
-py_Ref py_gettop();
-void py_settop(const py_Ref);
-py_Ref py_getsecond();
-void py_setsecond(const py_Ref);
-void py_duptop();
-void py_dupsecond();
 /// Returns a reference to the i-th object from the top of the stack.
 /// i should be negative, e.g. (-1) means TOS.
 py_Ref py_peek(int i);
+/// Pushes the object to the stack.
+void py_push(const py_Ref src);
 /// Pops an object from the stack.
 void py_pop();
+/// Shrink the stack by n.
 void py_shrink(int n);
-
-/// Pushes the object to the stack.
-void py_push(const py_Ref src);
-
 /// Get a temporary variable from the stack and returns the reference to it.
 py_Ref py_pushtmp();
 /// Free n temporary variable.
-void py_poptmp(int n);
-
+#define py_poptmp(n) py_shrink(n)
+
+#define py_gettop() py_peek(-1)
+#define py_getsecond() py_peek(-2)
+#define py_settop(v) py_assign(py_peek(-1), v)
+#define py_setsecond(v) py_assign(py_peek(-2), v)
+#define py_duptop() py_push(py_peek(-1))
+#define py_dupsecond() py_push(py_peek(-2))
 /************* Modules *************/
 py_Ref py_newmodule(const char* name, const char* package);
 py_Ref py_getmodule(const char* name);

+ 0 - 32
src/public/stack_ops.c

@@ -35,34 +35,6 @@ void py_assign(py_Ref dst, const py_Ref src){
 }
 
 /* Stack References */
-py_Ref py_gettop(){
-    return pk_current_vm->stack.sp - 1;
-}
-
-void py_settop(const py_Ref val){
-    pk_current_vm->stack.sp[-1] = *val;
-}
-
-py_Ref py_getsecond(){
-    return pk_current_vm->stack.sp - 2;
-}
-
-void py_setsecond(const py_Ref val){
-    pk_current_vm->stack.sp[-2] = *val;
-}
-
-void py_duptop(){
-    pk_VM* vm = pk_current_vm;
-    *vm->stack.sp = vm->stack.sp[-1];
-    vm->stack.sp++;
-}
-
-void py_dupsecond(){
-    pk_VM* vm = pk_current_vm;
-    *vm->stack.sp = vm->stack.sp[-2];
-    vm->stack.sp++;
-}
-
 py_Ref py_peek(int i){
     assert(i < 0);
     return pk_current_vm->stack.sp + i;
@@ -87,8 +59,4 @@ py_Ref py_pushtmp(){
     pk_VM* vm = pk_current_vm;
     py_newnull(vm->stack.sp++);
     return py_gettop();
-}
-
-void py_poptmp(int n){
-    py_shrink(n);
 }