|
From: Peep P. <so...@us...> - 2004-07-23 17:17:16
|
Update of /cvsroot/agd/server/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15530 Modified Files: interpret.c Log Message: Renamed stringdup to xstrdup; removed log.c and debug(); bitwise operators; pop excessive function arguments off the stack Index: interpret.c =================================================================== RCS file: /cvsroot/agd/server/src/interpret.c,v retrieving revision 1.26 retrieving revision 1.27 diff -u -d -r1.26 -r1.27 --- interpret.c 21 Jul 2004 12:05:59 -0000 1.26 +++ interpret.c 23 Jul 2004 17:17:01 -0000 1.27 @@ -19,10 +19,6 @@ jmp_buf error_context; int have_error_context; -#ifdef DEBUG -int dont_debug_interpreter; -#endif - /* This is the stack containing all local variables, function arguments and function return values. */ variable_t value_stack[VALUE_STACK_SIZE]; @@ -95,7 +91,6 @@ printf(buf); if(this_player) { do_write(buf); -/* net_disconnect(this_player);*/ } free(buf); @@ -190,7 +185,7 @@ case T_STRING: lval->string_type = rval->string_type; if(rval->string_type != ST_STATIC && rval->u.s) { - lval->u.s = stringdup(rval->u.s); + lval->u.s = xstrdup(rval->u.s); } else { lval->u.s = rval->u.s; } @@ -277,6 +272,7 @@ csp->cp = cp; csp->code = code; csp->codelen = codelen; + csp->num_arg = 0; } void pop_control_stack(int pop_sp) @@ -300,9 +296,7 @@ } /* Used by F_JUMP and F_JUMP_IF_FALSE to check if they jumped too far. */ -#define CHECK_OVERRUN() do { if(cp >= code + codelen) {\ - debug("interpret", "Ran over end of array: returning\n"); return; \ - } } while(0) +#define CHECK_OVERRUN() do { if(cp >= code + codelen) { return; } } while(0) #define GET_ARGS() \ arg[1] = sp[-1].u.i; pop_stack(); \ @@ -358,7 +352,7 @@ saved_csp = csp - 1; again: #ifdef DEBUG - if(!dont_debug_interpreter && conf.debuglevel > 0) + if(conf.debuglevel > 0) printf("[interpret] executing %s at %d\n", opc_name(*cp), cp - code); #endif switch(*cp) { @@ -371,7 +365,7 @@ if(*cp == -1) tmps = NULL; else - tmps = stringdup(this_ob->prog->str_tbl[*cp]); + tmps = xstrdup(this_ob->prog->str_tbl[*cp]); push_string(tmps, ST_MALLOC); break; case F_PUSH_VOID: @@ -465,8 +459,6 @@ tmpvp = sub_vars(sp-2, sp-1); pop_stack(); pop_stack(); push_var(tmpvp); -/* GET_ARGS(); - push_int(arg[0] - arg[1]);*/ break; case F_SUB_EQ: if(sp[-2].type == T_CHAR_PTR) { @@ -540,6 +532,90 @@ pop_stack(); pop_stack(); push_int(tmpi); break; + case F_POW: + GET_ARGS(); + push_int(to_power(arg[0], arg[1])); + break; + case F_POW_EQ: + tmpv = *sp[-2].u.v; + tmpi = to_power(tmpv.u.i, sp[-1].u.i); + sp[-2].u.v->u.i = tmpi; + pop_stack(); pop_stack(); + push_int(tmpi); + break; + case F_BAND: + tmpvp = band_vars(sp-2, sp-1); + pop_stack(); pop_stack(); + push_var(tmpvp); + break; + case F_BAND_EQ: + tmpv = *sp[-2].u.v; + if(tmpv.type & T_ARRAY) { + tmpvp = band_vars(&tmpv, sp-1); + do_assign(sp[-2].u.v, tmpvp); + pop_stack(); pop_stack(); + push_var(tmpvp); + } else { + tmpi = tmpv.u.i & sp[-1].u.i; + sp[-2].u.v->u.i = tmpi; + pop_stack(); pop_stack(); + push_int(tmpi); + } + break; + case F_BOR: + tmpi = sp[-2].u.i | sp[-1].u.i; + pop_stack(); pop_stack(); + push_int(tmpi); + break; + case F_BOR_EQ: + tmpvp = sp[-2].u.v; + tmpi = tmpvp->u.i | sp[-1].u.i; + tmpvp->u.i = tmpi; + pop_stack(); pop_stack(); + push_int(tmpi); + break; + case F_BNOT: + tmpi = sp[-1].u.i; + pop_stack(); + push_int(~tmpi); + break; + /* case F_BNOT_EQ: */ + case F_BXOR: + tmpi = sp[-2].u.i ^ sp[-1].u.i; + pop_stack(); pop_stack(); + push_int(tmpi); + break; + case F_BXOR_EQ: + tmpvp = sp[-2].u.v; + tmpi = tmpvp->u.i ^ sp[-1].u.i; + tmpvp->u.i = tmpi; + pop_stack(); pop_stack(); + push_int(tmpi); + break; + case F_BSL: + tmpi = sp[-2].u.i << sp[-1].u.i; + pop_stack(); pop_stack(); + push_int(tmpi); + break; + case F_BSL_EQ: + tmpvp = sp[-2].u.v; + tmpi = tmpvp->u.i << sp[-1].u.i; + tmpvp->u.i = tmpi; + pop_stack(); pop_stack(); + push_int(tmpi); + break; + case F_BSR: + tmpi = sp[-2].u.i >> sp[-1].u.i; + pop_stack(); pop_stack(); + push_int(tmpi); + break; + case F_BSR_EQ: + tmpvp = sp[-2].u.v; + tmpi = tmpvp->u.i >> sp[-1].u.i; + tmpvp->u.i = tmpi; + pop_stack(); pop_stack(); + push_int(tmpi); + break; case F_ASSIGN: if(sp[-2].type == T_CHAR_PTR) { /* Work of F_INDEX_LVALUE. */ @@ -680,9 +756,8 @@ } break; case F_NOT: - sp--; - tmpi = test_var(sp); - free_var(sp); + tmpi = test_var(sp-1); + pop_stack(); push_int(!tmpi); break; case F_GT: @@ -763,7 +838,7 @@ } #ifdef DEBUG - if(conf.debuglevel > 2 && !dont_debug_interpreter) + if(conf.debuglevel > 2) show_stack(); #endif @@ -785,7 +860,7 @@ void call_function(object_t *ob, int index) { - int i, j; + int i; function_t *f = ob->prog->functions[index]; if(!f) { char *buf = xmalloc(512); @@ -793,11 +868,12 @@ runtime_dyn(buf); } -/* csp->line = f->lineno;*/ csp->fun = index; i = f->num_arg - csp->num_arg; if(i > 0) { + /* Not enough arguments. */ + int j; for(j=0;j<i;j++) { switch(f->args[j]) { case T_INT: @@ -811,11 +887,14 @@ break; } } + } else if(i < 0) { + /* Too much arguments. */ + int j; + for(j=i;j<0;j++) { + pop_stack(); + } } -#ifdef DEBUG - debug("interpret", "call_function %d on %s\n", index, ob->name); -#endif previous_ob = this_ob; this_ob = ob; if(this_ob->iaob) @@ -886,7 +965,7 @@ case 's': /* We duplicate the string, so we can be sure it's not static and can free() it. */ - push_string(stringdup(va_arg(va, char*)), ST_MALLOC); + push_string(xstrdup(va_arg(va, char*)), ST_MALLOC); csp->num_arg++; break; default: |