Ejemplo n.º 1
0
int cpu_push(cpu_t* _this, char** ptr_current_byte)
{
    ISNOTNULL(_this);
    int __errnum = 0;

    char* current_byte = *ptr_current_byte;

    if (*current_byte == NUM)
    {
        current_byte++;

        double a = *(double*)current_byte;

        __errnum = stack_Push(_this->stk, a);

        current_byte += sizeof(double);
    }
    else
    {
        if (*current_byte != REG) return ECPUPUSH;
        current_byte++;
        if (*current_byte == AX) __errnum = stack_Push(_this->stk, _this->ax);
        if (*current_byte == BX) __errnum = stack_Push(_this->stk, _this->bx);
        if (*current_byte == CX) __errnum = stack_Push(_this->stk, _this->cx);
        if (*current_byte == DX) __errnum = stack_Push(_this->stk, _this->dx);
        current_byte++;
    }

    ERRHANDLER;

    *ptr_current_byte = current_byte;
    return 0;
}
Ejemplo n.º 2
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);
}
Ejemplo n.º 3
0
int cpu_call(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;

    int addr_func = *(int*)current_byte;
    current_byte += sizeof(int);


    if (addr_func < 0) __errnum = EJMPBADLABEL;

    ERRHANDLER;

    __errnum = stack_Push(_this->call, (double)(int)current_byte);

    ERRHANDLER;

    current_byte = _this->addr + addr_func;

    *ptr_current_byte = current_byte;

    return 0;
}
Ejemplo n.º 4
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);
}
Ejemplo n.º 5
0
static LIST st_TraverseTreeGenPreTest(CONTEXT IndexContext,
				      st_INDEX StIndex,
				      st_MINMAX MinMax)
/**************************************************************
  INPUT:   
  RETURNS: 
  EFFECTS: 
***************************************************************/
{
  int      Save;
  LIST     Result, CurrentList;
  st_INDEX CurrentNode;

  /* PREPARE TRAVERSAL */
  Save = stack_Bottom();

  Result      = list_Nil();
  CurrentList = StIndex->subnodes;

  cont_StartBinding();

  for (;;) {
    
    /* BACKTRACK A BIG STEP */
    if (list_Empty(CurrentList)) {
      cont_StopAndBackTrack();

      if (stack_Empty(Save))
	return Result;

      CurrentList = stack_PopResult();
    }
    
    /* DESCENDING */
    for (CurrentNode = (st_INDEX)list_Car(CurrentList);
	 (MinMax >= st_Min(CurrentNode)) &&
	   subst_Match(IndexContext, CurrentNode->subst);
	 CurrentList = CurrentNode->subnodes,
	 CurrentNode = (st_INDEX)list_Car(CurrentList))
      if (st_IsLeaf(CurrentNode)) {
	Result = list_Append(CurrentNode->entries, Result);
	break;
      } else if (list_Cdr(CurrentList)) {
	stack_Push(list_Cdr(CurrentList));
    	cont_StartBinding();
      } else
	cont_StopAndStartBinding();

    /* BACKTRACK LEAF OR INNER NODE */
    CurrentList = list_Cdr(CurrentList);
    cont_BackTrackAndStart();
  }
}
Ejemplo n.º 6
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);
}
Ejemplo n.º 7
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;

}
Ejemplo n.º 8
0
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;
}
Ejemplo n.º 9
0
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;
}
Ejemplo n.º 10
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;
}
Ejemplo n.º 11
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;
}