int cpu_jne(cpu_t* _this, char** current_byte) { ISNOTNULL(current_byte); ISNOTNULL(*current_byte); ISNOTNULL(_this); int __errnum = 0; double a = 0.0; __errnum = stack_Pop(_this->stk, &a); ERRHANDLER; double b = 0.0; __errnum = stack_Pop(_this->stk, &b); ERRHANDLER; int label = *(int*)(*current_byte); if (label < 0) __errnum = EJMPBADLABEL; ERRHANDLER; if (a > b) *current_byte = _this->addr + label; else *current_byte += sizeof(int); return 0; }
int cpu_ret(cpu_t* _this, char** ptr_current_byte) { ISNOTNULL(ptr_current_byte); ISNOTNULL(*ptr_current_byte); ISNOTNULL(_this); char* current_byte = *ptr_current_byte; int __errnum = 0; double addr_d = 0; __errnum = stack_Pop(_this->call, &addr_d); ERRHANDLER; int addr_func = (int) addr_d; //printf("addr func = %d\n", addr_func); if (addr_func < 0) __errnum = EJMPBADLABEL; ERRHANDLER; current_byte = (char*)addr_func; *ptr_current_byte = current_byte; return 0; }
int cpu_pop(cpu_t* _this, char** ptr_current_byte) { ISNOTNULL(_this); ISNOTNULL(ptr_current_byte); ISNOTNULL(*ptr_current_byte); int __errnum = 0; char* current_byte = *ptr_current_byte; if (*current_byte == AX) __errnum = stack_Pop(_this->stk, &(_this->ax)); if (*current_byte == BX) __errnum = stack_Pop(_this->stk, &(_this->bx)); if (*current_byte == CX) __errnum = stack_Pop(_this->stk, &(_this->cx)); if (*current_byte == DX) __errnum = stack_Pop(_this->stk, &(_this->dx)); ERRHANDLER; (*ptr_current_byte)++; return 0; }
void iter_SaveBlockStack(ITER_ID iter_id,VM_ID vm_id) { struct _vm *vm = (struct _vm*)mem_lock(vm_id); iter_object *iter = (iter_object*)mem_lock(iter_id); OBJECT_ID bo = 0; while((bo = stack_Pop(vm->blocks)) != iter->tag) { stack_Push(iter->block_stack,bo);//reverserd order } mem_unlock(iter_id,0); mem_unlock(vm_id,0); }
void iter_ClearBlockStack(ITER_ID iter_id,VM_ID vm_id) { //struct _vm *vm = (struct _vm*)mem_lock(vm_id); iter_object *iter = (iter_object*)mem_lock(iter_id); while(!stack_IsEmpty(iter->block_stack)) { //OBJECT_ID bo = stack_Pop(iter->block_stack); stack_Pop(iter->block_stack); //obj_DecRefCount(bo); } //mem_unlock(vm_id,0); mem_unlock(iter_id,0); }
void iter_RestoreBlockStack(ITER_ID iter_id,VM_ID vm_id) { struct _vm *vm = (struct _vm*)mem_lock(vm_id); iter_object *iter = (iter_object*)mem_lock(iter_id); stack_Push(vm->blocks,iter->tag); while(!stack_IsEmpty(iter->block_stack)) { OBJECT_ID bo = stack_Pop(iter->block_stack); stack_Push(vm->blocks,bo);//reverserd order } mem_unlock(iter_id,0); mem_unlock(vm_id,0); }
int cpu_add(cpu_t* _this) { ISNOTNULL(_this); int __errnum = 0; double a = 0.0; __errnum = stack_Pop(_this->stk, &a); ERRHANDLER; double b = 0.0; __errnum = stack_Pop(_this->stk, &b); ERRHANDLER; __errnum = stack_Push(_this->stk, (a + b)); ERRHANDLER; return 0; }
int cpu_sqrt(cpu_t* _this) { ISNOTNULL(_this); int __errnum = 0; double a = 0.0; __errnum = stack_Pop(_this->stk, &a); ERRHANDLER; __errnum = stack_Push(_this->stk, sqrt(a)); ERRHANDLER; return 0; }
void iter_Expand(ITER_ID iter_id,VM_ID vm_id,STACK_ID stack_id) { obj_IncRefCount(iter_id); OBJECT_ID n = 0; STACK_ID tmp = stack_Create(); //BOOL found_none = 0; do { n = iter_NextNow(iter_id,vm_id); stack_Push(tmp,n); }while(obj_GetType(n) != TYPE_NONE); while(!stack_IsEmpty(tmp)) { OBJECT_ID s = stack_Pop(tmp); stack_Push(stack_id,s); } stack_Close(tmp,0); obj_DecRefCount(iter_id); }
int cpu_out(cpu_t* _this) { ISNOTNULL(_this); int __errnum = 0; double a = 0.0; __errnum = stack_Pop(_this->stk, &a); ERRHANDLER; __errnum = stack_Push(_this->stk, a); ERRHANDLER; printf("%lg\n", a); return 0; }
OBJECT_ID iter_NextNow(ITER_ID iter_id,VM_ID vm_id) { OBJECT_ID next = iter_Next(iter_id,vm_id); if(obj_GetType(next) == TYPE_BLOCK) //used only to differentiate between an object to return and a generator not finished { struct _vm *vm = (struct _vm*)mem_lock(vm_id); iter_object *iter = (iter_object*)mem_lock(iter_id); OBJECT_ID ret = 0; BLOCK_ID bo = iter->tag; iter_RestoreBlockStack(iter_id,vm_id); obj_IncRefCount(iter_id); while(ret == 0)//TODO doesnt stop after one block { ret = vm_Step(vm_id,0); if(!stack_Contains(vm->blocks,bo)) //via normal return //TODO switch to integer comparison to block stack num with the block stack num at the beginning { BLOCK_ID n = stack_Top(vm->blocks); if(!stack_IsEmpty(vm->blocks)) { block_object *bn = (block_object*)mem_lock(n); ret = stack_Pop(bn->stack); mem_unlock(n,0); } iter_ClearBlockStack(iter_id,vm_id); break; } else if(ret != 0) //via yield { iter_SaveBlockStack(iter_id,vm_id); obj_DecRefCount(ret); } } mem_unlock(iter_id,0); mem_unlock(vm_id,0); obj_DecRefCount(iter_id); return(ret); } obj_DecRefCount(next); return(next); }
int cpu_dec(cpu_t* _this, char** ptr_current_byte) { ISNOTNULL(ptr_current_byte); ISNOTNULL(*ptr_current_byte); ISNOTNULL(_this); char* current_byte = *ptr_current_byte; int __errnum = 0; if (*current_byte == NOARG) { current_byte++; double a = 0.0; __errnum = stack_Pop(_this->stk, &a); ERRHANDLER; __errnum = stack_Push(_this->stk, (a - 1)); ERRHANDLER; } else if (*current_byte == REG) { current_byte++; if (*current_byte == AX) _this->ax--; if (*current_byte == BX) _this->bx--; if (*current_byte == CX) _this->cx--; if (*current_byte == DX) _this->dx--; current_byte++; } *ptr_current_byte = current_byte; return 0; }
static int kbo_CompVarCondAndWeight(TERM Term1, BOOL *VarCond1, TERM Term2, BOOL *VarCond2) /************************************************************** INPUT: Two terms and two pointers to booleans. EFFECT: Sets the booleans with respect to the kbo variable condition. Computes the kbo weight difference. ***************************************************************/ { SYMBOL MaxVar1,MaxVar2; TERM Term; LIST Scan; int i,Stack,Weight; *VarCond1 = *VarCond2 = TRUE; MaxVar1 = term_MaxVar(Term1); MaxVar2 = term_MaxVar(Term2); Stack = stack_Bottom(); Weight = 0; if (MaxVar1 < MaxVar2) MaxVar1 = MaxVar2; for (i = 0; i <= MaxVar1; i++) { ord_VARCOUNT[i][0] = 0; ord_VARCOUNT[i][1] = 0; } Term = Term1; if (term_IsStandardVariable(Term)) { ord_VARCOUNT[term_TopSymbol(Term)][0]++; Weight += kbo_MINWEIGHT; } else { Weight += symbol_Weight(term_TopSymbol(Term)); if (term_IsComplex(Term)) stack_Push(term_ArgumentList(Term)); } while (!stack_Empty(Stack)) { Scan = stack_Top(); Term = (TERM)list_Car(Scan); stack_RplacTop(list_Cdr(Scan)); if (term_IsStandardVariable(Term)) { Weight += kbo_MINWEIGHT; ord_VARCOUNT[term_TopSymbol(Term)][0]++; } else { Weight += symbol_Weight(term_TopSymbol(Term)); if (term_IsComplex(Term)) stack_Push(term_ArgumentList(Term)); } while (!stack_Empty(Stack) && list_Empty(stack_Top())) stack_Pop(); } Term = Term2; if (term_IsStandardVariable(Term)) { Weight -= kbo_MINWEIGHT; ord_VARCOUNT[term_TopSymbol(Term)][1]++; } else { Weight -= symbol_Weight(term_TopSymbol(Term)); if (term_IsComplex(Term)) stack_Push(term_ArgumentList(Term)); } while (!stack_Empty(Stack)) { Scan = stack_Top(); Term = (TERM)list_Car(Scan); stack_RplacTop(list_Cdr(Scan)); if (term_IsStandardVariable(Term)) { Weight -= kbo_MINWEIGHT; ord_VARCOUNT[term_TopSymbol(Term)][1]++; } else { Weight -= symbol_Weight(term_TopSymbol(Term)); if (term_IsComplex(Term)) stack_Push(term_ArgumentList(Term)); } while (!stack_Empty(Stack) && list_Empty(stack_Top())) stack_Pop(); } for (i = 0; i <= MaxVar1; i++) { if (ord_VARCOUNT[i][0] < ord_VARCOUNT[i][1]) { *VarCond1 = FALSE; if (!*VarCond2) return Weight; } if (ord_VARCOUNT[i][0] > ord_VARCOUNT[i][1]) { *VarCond2 = FALSE; if (!*VarCond1) return Weight; } } return Weight; }