Пример #1
0
void execute_tablegetelem(instruction* instr){
	//printf("exec_tableget\n");
	avm_memcell* lv = avm_translate_operand(&instr->result,(avm_memcell*) 0);
	avm_memcell* t = avm_translate_operand(&instr->arg1,(avm_memcell*) 0);
	avm_memcell* i = avm_translate_operand(&instr->arg2,&ax);
	assert(lv && (&stack[AVM_STACKSIZE-1] >= lv && lv > &stack[top] || lv == &retval));
	assert(t && &stack[AVM_STACKSIZE-1] >= t && t > &stack[top]);
	assert(i);
	avm_memcellclear(lv);
	lv->type = nil_m;
	if(t->type != table_m){
		avm_error("illigal use of type as table!");
	}
	else{
		avm_memcell* content = avm_tablegetelem(t->data.tableVal,i);
		if(content)
			avm_assign(lv,content);
		else{
			char* ts = avm_tostring(t);
			char* is = avm_tostring(i);
			avm_warning("not found!");
			free(ts);
			free(is);
		}
	}
}
Пример #2
0
void execute_tablegetelem (instruction* instr){
	avm_memcell* lv = avm_translate_operand(&instr->result, (avm_memcell*) 0);
	avm_memcell* t = avm_translate_operand(&instr->arg1, (avm_memcell*) 0);
	avm_memcell* i = avm_translate_operand(&instr->result, &ax);

//	assert(lv && &stack[N-1] >= lv && lv > &stack[top] || lv == &retval);
//	assert(t && stack[N-1] >= t && t > &stack[top]);
	assert(i);

	avm_memcellclear(lv);
	lv->type = nil_m;

	if(t->type != table_m)
		{
		avm_error("illegal use of type %s as table!\n", typeStrings[t->type]);
		executionFinished = 1;
		}
	else
		{
		avm_memcell* content = avm_tablegetelem(t->data.tableVal, i);
		if(content)
			{
			avm_assign(lv, content);
			}
		else
			{
			char* ts = avm_tostring(t);
			char* is = avm_tostring(i);
			avm_warning("%s[%s] not found!\n", ts, is);
			free(ts);
			free(is);
			}
		}
}
Пример #3
0
void execute_tablesetelem(instruction* instr){
	//printf("exec_tableset\n");
	avm_memcell* t = avm_translate_operand(&instr->arg1,(avm_memcell*) 0);
	avm_memcell* i = avm_translate_operand(&instr->arg2,&ax);
	avm_memcell* c = avm_translate_operand(&instr->result,&bx);
	assert(t && &stack[AVM_STACKSIZE-1] >= t && t > &stack[top]);
	assert(i && c);
	if(t->type != table_m)
		avm_error("illigal use of type as table!");
	else
		avm_tablesetelem(t->data.tableVal, i, c);
}
Пример #4
0
void execute_call (instruction* instr){
	avm_memcell* func = avm_translate_operand(&instr->result, &ax);
	assert(func);
	avm_callsaveenvironment();

	char* s;
	switch(func->type)
		{
		case userfunc_m:
			pc = func->data.funcVal;
			assert(pc < AVM_ENDING_PC);
			assert(code[pc].opcode == funcenter_v);
			break;
		case string_m:
			avm_calllibfunc(func->data.strVal);
			break;
		case libfunc_m:
			avm_calllibfunc(func->data.libfuncVal);
			break;
		default:
			s = avm_tostring(func);
			avm_error("call: can not bind '%s' to function!\n", s);
			free(s);
			executionFinished = 1;
		}
}
Пример #5
0
void execute_call(instruction* instr){
	//printf("exec_call\n");
	avm_memcell* func = avm_translate_operand(&instr->result, &ax);
	assert(func);
	avm_callsaveenviroment();

	switch (func->type){		
		case userfunc_m: {
			pc = func->data.funcVal;
			assert(pc < AVM_ENDING_PC);
			assert(instr[pc].opcode = funcenter_v);
			break;
		}
		
		case string_m: {
			avm_calllibfunc(func->data.strVal);
			break;
		}
		
		case libfunc_m: {
			avm_calllibfunc(func->data.strVal);
			break;
		}
		
		default: {
			char *s = (char*) malloc(sizeof(char));
			s = avm_tostring(func);
			avm_error("call: cannot bind '%s' to function!");
			free(s);
			executionFinished = 1;
		}
	}
}
Пример #6
0
void execute_pusharg(instruction* instr){
	//printf("exec_pusharg\n");
	avm_memcell* arg = avm_translate_operand(&instr->result, &ax);
	assert(arg);
	avm_assign(&stack[top], arg);
	++totalActuals;
	avm_dec_top();
}
Пример #7
0
void execute_tablesetelem (instruction* instr){
	avm_memcell* t = avm_translate_operand(&instr->result, (avm_memcell*) 0);
	avm_memcell* i = avm_translate_operand(&instr->arg1, &ax);
	avm_memcell* c = avm_translate_operand(&instr->arg2, &bx);

//	assert(t && &stack[N-1] >= t && t > &stack[top]);
	assert(i && c);

	if(t->type != table_m)
		{
		avm_error("illegal use of type %s as table!\n", typeStrings[t->type]);
		executionFinished = 1;
		}
	else
		{
		avm_tablesetelem(t->data.tableVal, i, c);
		}
}
Пример #8
0
void execute_newtable(instruction* instr){
	//printf("exec_newtable\n");
	avm_memcell* lv = avm_translate_operand(&instr->result,(avm_memcell*) 0);
	assert(lv && (&stack[AVM_STACKSIZE-1] >= lv && lv > &stack[top] || lv == &retval));
	avm_memcellclear(lv);
	lv->type = table_m;
	lv->data.tableVal = avm_tablenew();
	avm_tableincrefcounter(lv->data.tableVal);
}
Пример #9
0
void execute_funcenter (instruction* instr){
	avm_memcell* func = avm_translate_operand(&instr->result, &ax);
	assert(func);
	assert(pc == func->data.funcVal);

	totalActuals = 0;
	userfunc* funcInfo = avm_getfuncinfo(pc);
	topsp = top;
	top = top - funcInfo->localSize;
}
Пример #10
0
void execute_arithmetic (instruction* instr) {
    avm_memcell* lv = avm_translate_operand(instr->result,(avm_memcell*)0);
    avm_memcell* rv1= avm_translate_operand(instr->arg1,&ax);
    avm_memcell* rv2= avm_translate_operand(instr->arg2,&bx);

    assert(lv && ( (&stack[AVM_STACKSIZE]>= lv && &stack[top]<lv )|| lv==&retval ));
    assert(rv1 && rv2);

    if (rv1->type !=number_m || rv2->type !=number_m ) {
        avm_error("not a number arithmetic!\n");
        executionFinished=1;
    }
    else {
        arithmetic_func_t op=arithmeticFuncs[instr->opcode - add_v];
        avm_memcellclear(lv);
        lv->type = number_m;
        lv->data.numVal = (*op)(rv1->data.numVal,rv2->data.numVal);
    }
    //printf("DEBUG VALUE:%d\n",(int)lv->data.numVal);
}
Пример #11
0
void execute_pusharg(instruction * instr){
    assert(instr->result);
    avm_memcell *arg = avm_translate_operand(instr->result,&ax);
    assert(arg);


    avm_assign(&stack[top], arg);
    ++totalActuals;
    avm_dec_top();

    return;
}
Пример #12
0
void execute_jne (instruction* instr){
	assert(instr->result.type == label_a);

	avm_memcell* rv1 = avm_translate_operand(&instr->arg1, &ax);
	avm_memcell* rv2 = avm_translate_operand(&instr->arg2, &bx);

	unsigned char result = 0;

	if(rv1->type == undef_m){
                rv1->type=number_m;
        }
        if(rv2->type == undef_m){
                rv1->type=number_m;
        }

	if((rv1->type == undef_m)||(rv2->type == undef_m))
		{
		avm_error("'undef' involved in equality!\n");
		executionFinished = 1;
		}
	else if((rv1->type == nil_m)||(rv2->type == nil_m))
		{
		result = (rv1->type == nil_m) && (rv2->type == nil_m);
		}
	else if((rv1->type == bool_m)||(rv2->type == bool_m))
		{
		result = (avm_tobool(rv1) == avm_tobool(rv2));
		}
	else if(rv1->type != rv2->type)
		{
		avm_error("%s == %s is illegal!\n", typeStrings[rv1->type], typeStrings[rv2->type]);
		executionFinished = 1;
		}
	else if(rv1->type == number_m)
		{
		if(rv1->data.numVal != rv2->data.numVal)
			{
			result = 1;
			}
		}
	else if(rv1->type == string_m)
		{
		if(strcmp(rv1->data.strVal, rv2->data.strVal) != 0)
			{
			result = 1;
			}
		}
	else if(rv1->type == table_m)
		{
		if(rv1->data.tableVal->total != rv2->data.tableVal->total)
			{
			result = 1;
			}
		}
	else if(rv1->type == userfunc_m)
		{
		// ?
		}
	else if(rv1->type == libfunc_m)
		{
		// ?
		}

	if(!executionFinished && result)
		{
		pc = instr->result.val;
		}
}