This commit is contained in:
blueloveTH 2024-07-01 01:55:26 +08:00
parent c954431442
commit ac19ece535
2 changed files with 11 additions and 44 deletions

View File

@ -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);
/// Pops an object from the stack.
void py_pop();
void py_shrink(int n);
/// 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);
/// 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);

View File

@ -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;
@ -88,7 +60,3 @@ py_Ref py_pushtmp(){
py_newnull(vm->stack.sp++);
return py_gettop();
}
void py_poptmp(int n){
py_shrink(n);
}