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); } } }
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); } } }
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; } }
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; } } }
/******************LIBRARY FUNCTIONS********************/ void libfunc_print(void){ unsigned n = avm_totalactuals(); unsigned i; char* s; for(i = 0; i < n; ++i){ s = (char*)avm_tostring(avm_getactual(i)); puts(s); //free(s); //provlhma me boolean } }
void libfunc_print(void){ unsigned n=avm_totalactuals(); unsigned i; for(i=0;i<n;i++){ avm_memcell* m=avm_getactual(i); char *s=avm_tostring(m); if(!s) continue; printf("%s",s); free(s); if(m->type==string_m || m->type==libfunc_m) continue; } }