From: Peep P. <so...@us...> - 2004-03-15 18:54:10
|
Update of /cvsroot/agd/server/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2139 Modified Files: interpret.c Log Message: Cleanup and fixes. Index: interpret.c =================================================================== RCS file: /cvsroot/agd/server/src/interpret.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** interpret.c 12 Mar 2004 13:50:53 -0000 1.9 --- interpret.c 15 Mar 2004 18:44:53 -0000 1.10 *************** *** 18,22 **** #endif - /*variable_t void_ret = {T_VOID, NULL};*/ static int lineno, funcno; --- 18,21 ---- *************** *** 119,128 **** } void push_var(variable_t *v) { if(v) do_assign(sp, v); ! else sp->type = 0; sp++; CHECK_SP() --- 118,130 ---- } + void free_value(variable_t *v); void push_var(variable_t *v) { if(v) do_assign(sp, v); ! else { ! free_value(sp); sp->type = 0; + } sp++; CHECK_SP() *************** *** 147,154 **** } ! #define pop_locals() if(sp - 1 >= fp) \ ! while(sp > fp) { free_value(sp); sp--; } ! void pop_arguments(void) { int i; --- 149,157 ---- } ! /*#define pop_locals() if(sp - 1 >= fp) \ ! while(1) { if(sp == fp) break; free_value(sp); sp--; }*/ ! #define pop_locals() while(sp > fp) { sp--; free_value(sp); } ! /*void pop_arguments(void) { int i; *************** *** 156,169 **** pop_stack(); } ! } void do_assign(variable_t *lval, variable_t *rval) { - /* if(lval->type == T_LVALUE) - lval = lval->u.v;*/ - if(rval->type == T_LVALUE) - rval = rval->u.v; - *lval = *rval; switch(lval->type) { --- 159,167 ---- pop_stack(); } ! }*/ void do_assign(variable_t *lval, variable_t *rval) { *lval = *rval; switch(lval->type) { *************** *** 181,188 **** void do_assign_free(variable_t *lval, variable_t *rval) { ! if(lval->type == T_LVALUE) lval = lval->u.v; if(rval->type == T_LVALUE) ! rval = rval->u.v; free_value(lval); --- 179,186 ---- void do_assign_free(variable_t *lval, variable_t *rval) { ! /* if(lval->type == T_LVALUE) lval = lval->u.v; if(rval->type == T_LVALUE) ! rval = rval->u.v;*/ free_value(lval); *************** *** 327,336 **** case F_PUSH_GVAR: cp++; ! push_var(this_ob->prog->variables.data[*cp]); break; case F_PUSH_GVAR_LVALUE: cp++; sp->type = T_LVALUE; ! sp->u.v = this_ob->prog->variables.data[*cp]; sp++; CHECK_SP() --- 325,334 ---- case F_PUSH_GVAR: cp++; ! push_var(this_ob/*->prog*/->variables.data[*cp]); break; case F_PUSH_GVAR_LVALUE: cp++; sp->type = T_LVALUE; ! sp->u.v = this_ob/*->prog*/->variables.data[*cp]; sp++; CHECK_SP() *************** *** 358,363 **** break; case F_ASSIGN: ! do_assign_free(sp-2, sp-1); ! pop_stack(); break; case F_POSTINC: --- 356,366 ---- break; case F_ASSIGN: ! { ! variable_t tmp; ! do_assign(sp[-2].u.v, sp-1); ! do_assign(&tmp, sp-1); ! pop_stack(); pop_stack(); ! push_var(&tmp); ! } break; case F_POSTINC: *************** *** 485,492 **** name = (char *) *++cp; ++cp; ! ref = sp-1; ! if(ref->type == T_LVALUE) ! ref = ref->u.v; ! ob = ref->u.ob; if(!ob) { runtime("call_other on NULL object"); --- 488,493 ---- name = (char *) *++cp; ++cp; ! sp--; ! ob = sp->u.ob; if(!ob) { runtime("call_other on NULL object"); *************** *** 494,504 **** } - show_stack(); index = get_fun_index(ob, name); push_control_stack(); csp->num_arg = *cp; fp = sp - csp->num_arg; call_function(ob, index); ! eval_instruction(); } break; --- 495,505 ---- } index = get_fun_index(ob, name); + free_value(sp); push_control_stack(); csp->num_arg = *cp; fp = sp - csp->num_arg; call_function(ob, index); ! goto again; } break; *************** *** 507,513 **** variable_t tmp; tmp = sp[-1]; - pop_stack(); - pop_arguments(); - pop_locals(); push_var(&tmp); pop_control_stack(1); --- 508,511 ---- *************** *** 523,530 **** #endif /* We return to the control level where we entered - we have finished. */ ! if(csp == saved_csp /*&control_stack[0]*/ || stop_execution ! || this_ob->flags & O_DESTRUCTED) return; if((int *) ++cp >= (int *) code->data + code->length) { return; } --- 521,539 ---- #endif /* We return to the control level where we entered - we have finished. */ ! if(csp == saved_csp) { /*&control_stack[0]*/ ! debug("interpret", "csp (%d) == saved_csp (%d); returning\n", csp - &control_stack[0], saved_csp - &control_stack[0]); ! return; ! } ! /* Abnormal termination - need to pop unnecessary stuff off the stack. */ ! if(stop_execution || this_ob->flags & O_DESTRUCTED) { ! debug("interpret", "stop_execution(%d) or this_ob destructed (%d); returning\n", stop_execution, this_ob->flags & O_DESTRUCTED); ! /* Should we pop to the bottom? */ ! pop_control_stack(1); ! pop_locals(); return; + } + /* Should only check this with F_JMP. */ if((int *) ++cp >= (int *) code->data + code->length) { + debug("interpret", "Ran over end of array: returning\n"); return; } |