void make_operand(expr* e,struct vmarg* arg){ /*if(!e) { arg->type = nil_a; return; }*/ // printf("name:%s and type:%d\n",e->name); switch(e->type){ case var_e:{ arg->val = e->sym->offset; newvar(e->sym->offset,e->sym->name); switch(e->sym->space){ case programvar: arg->type = global_a; break; case functionlocal: arg->type = local_a; break; case formalarg: arg->type = formal_a; break; default: assert(0); } break; /*n from case newtable_e */ } case tableitem_e:{ arg->val = e->sym->offset; switch(e->sym->space){ case programvar: arg->type = global_a; break; case functionlocal: arg->type = local_a; break; case formalarg: arg->type = formal_a; break; default: assert(0); } break; /*n from case newtable_e */ } case boolexpr_e:{ arg->val = e->sym->offset; newvar(e->sym->offset,e->sym->name); switch(e->sym->space){ case programvar: arg->type = global_a; break; case functionlocal: arg->type = local_a; break; case formalarg: arg->type = formal_a; break; default: assert(0); } break; /*n from case newtable_e */ } case assignexpr_e:{ arg->val = e->sym->offset; newvar(e->sym->offset,e->sym->name); switch(e->sym->space){ case programvar: arg->type = global_a; break; case functionlocal: arg->type = local_a; break; case formalarg: arg->type = formal_a; break; default: assert(0); } break; /*n from case newtable_e */ } case newtable_e:{ arg->val = e->sym->offset; switch(e->sym->space){ case programvar: arg->type = global_a; break; case functionlocal: arg->type = local_a; break; case formalarg: arg->type = formal_a; break; default: assert(0); } break; /*n from case newtable_e */ } /* Constants */ case constbool_e:{ unsigned int temp = (unsigned int)e->boolConst; arg->val =e->boolConst; arg->type = bool_a; break; } case conststring_e:{ arg->val = consts_newstring(e->strConst); arg->type = string_a; break; } case constnum_e:{ arg->val = consts_newnumber(e->numConst); arg->type = number_a; break; } case nil_e: arg->type = nil_a; break; /* Functions */ case programfunc_e:{ // printf("in tcode address is:%d\n",e->sym->taddress); arg->val = userfuncs_newfunc(e->sym); arg->type = userfunc_a; break; } case libraryfunc_e:{ arg->type = libfunc_a; arg->val = libfuncs_newused(e->sym->name); break; } default: assert(0); } }
void make_operand(expr1 *e, vmarg *arg) { if(e==NULL) return; switch(e->type) { case var_e: case assignexpr_e: case tableitem_e: case arithmexpr_e: case booleanexpr_e: case newtable_e: { assert(e->sym); //arg->val = e->sym->offset; arg->val = uservars_newvar(e->sym); switch(e->sym->space) { case programVar: arg->type = global_a; break; case functionLocal: arg->type = local_a; break; case formalArg: arg->type = formal_a; break; default : assert(0); } break; } case constbool_e: { arg->val = e->boolConst; arg->type = bool_a; break; } case constchar_e: { arg->val = consts_newstring(e->strConst); arg->type = string_a; break; } case constnum_e: { arg->val = consts_newnumber(e->numConst); arg->type = number_a; break; } case nil_e: { arg->type = nil_a; break; } case programfunc_e: { arg->type = userfunc_a; //arg->val = e->sym->iaddress; arg->val = userfuncs_newfunc(e->sym); break; } case libraryfunc_e: { arg->type = libfunc_a; arg->val = libfuncs_newused(e->sym->value.funcVal->name); break; } default : assert(0); } }