From: Peep P. <so...@us...> - 2004-06-14 20:55:52
|
Update of /cvsroot/agd/server/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21421 Modified Files: interpret.c Log Message: F_INDEX and F_INDEX_LVALUE work, and with all operators; removed xfree Index: interpret.c =================================================================== RCS file: /cvsroot/agd/server/src/interpret.c,v retrieving revision 1.23 retrieving revision 1.24 diff -u -d -r1.23 -r1.24 --- interpret.c 12 Jun 2004 20:51:40 -0000 1.23 +++ interpret.c 14 Jun 2004 20:55:42 -0000 1.24 @@ -83,10 +83,10 @@ do_write(buf); net_disconnect(this_player); } - xfree(buf); + free(buf); if(free_str) - xfree(s); + free(s); /* stack_trace();*/ @@ -277,7 +277,7 @@ #define GET_ARGS() arg[0] = sp[-1].u.i; pop_stack(); arg[1] = sp[-1].u.i; pop_stack(); #define TAKE_SLICE() GET_ARGS() if(!sp[-1].u.s) runtime("taking substring of null string", 0); \ - if(arg[1] >= strlen(sp[-1].u.s) || arg[1] < 0 || arg[1] > arg[0]) runtime("substring out of range", 0); \ + if(arg[1] >= strlen(sp[-1].u.s)+1 || arg[1] < 0 || arg[1] > arg[0]) runtime("substring out of range", 0); \ #define SETUP_FRAME() push_control_stack(); csp->num_arg = *cp; fp = sp - csp->num_arg; @@ -302,8 +302,13 @@ break; case F_PUSH_STRING: cp++; - tmps = this_ob->prog->str_tbl[*cp]; - push_string(tmps, ST_STATIC); + if(*cp == -1) + tmps = NULL; + else + tmps = this_ob->prog->str_tbl[*cp]; + if(tmps) + tmps = stringdup(tmps); + push_string(tmps, ST_MALLOC); break; case F_PUSH_VOID: push_void(); @@ -358,20 +363,31 @@ push_var(tmpvp); break; case F_ADD_EQ: - tmpv = *sp[-2].u.v; - tmpvp = add_vars(&tmpv, sp-1); - do_assign(sp[-2].u.v, tmpvp); - pop_stack(); pop_stack(); - push_var(tmpvp); + if(sp[-2].type == T_CHAR_PTR) { + tmpvp = sp-2; + tmpvp->u.s[0] += sp[-1].u.i; + pop_stack(); pop_stack(); + push_int(*tmpvp->u.s); + } else { + tmpv = *sp[-2].u.v; + tmpvp = add_vars(&tmpv, sp-1); + do_assign(sp[-2].u.v, tmpvp); + pop_stack(); pop_stack(); + push_var(tmpvp); + } break; case F_SUB: GET_ARGS() push_int(arg[1] - arg[0]); break; case F_SUB_EQ: - tmpv = *sp[-2].u.v; - tmpi = tmpv.u.i - sp[-1].u.i; - sp[-2].u.v->u.i = tmpi; + if(sp[-2].type == T_CHAR_PTR) { + tmpi = sp[-2].u.s[0] - sp[-1].u.i; + } else { + tmpv = *sp[-2].u.v; + tmpi = tmpv.u.i - sp[-1].u.i; + sp[-2].u.v->u.i = tmpi; + } pop_stack(); pop_stack(); push_int(tmpi); break; @@ -380,9 +396,13 @@ push_int(arg[1] * arg[0]); break; case F_MUL_EQ: - tmpv = *sp[-2].u.v; - tmpi = tmpv.u.i * sp[-1].u.i; - sp[-2].u.v->u.i = tmpi; + if(sp[-2].type == T_CHAR_PTR) { + tmpi = sp[-2].u.s[0] * sp[-1].u.i; + } else { + tmpv = *sp[-2].u.v; + tmpi = tmpv.u.i * sp[-1].u.i; + sp[-2].u.v->u.i = tmpi; + } pop_stack(); pop_stack(); push_int(tmpi); break; @@ -393,11 +413,16 @@ push_int(arg[1] / arg[0]); break; case F_DIV_EQ: - tmpv = *sp[-2].u.v; if(!sp[-1].u.i) runtime("division by zero", 0); - tmpi = tmpv.u.i / sp[-1].u.i; - sp[-2].u.v->u.i = tmpi; + + if(sp[-2].type == T_CHAR_PTR) { + tmpi = sp[-2].u.s[0] / sp[-1].u.i; + } else { + tmpv = *sp[-2].u.v; + tmpi = tmpv.u.i / sp[-1].u.i; + sp[-2].u.v->u.i = tmpi; + } pop_stack(); pop_stack(); push_int(tmpi); break; @@ -408,62 +433,92 @@ push_int(arg[1] % arg[0]); break; case F_MOD_EQ: - tmpv = *sp[-2].u.v; if(!sp[-1].u.i) runtime("divison by zero", 0); - tmpi = tmpv.u.i % sp[-1].u.i; - sp[-2].u.v->u.i = tmpi; + if(sp[-2].type == T_CHAR_PTR) { + tmpi = sp[-2].u.s[0] % sp[-1].u.i; + } else { + tmpv = *sp[-2].u.v; + 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_ASSIGN: - do_assign(sp[-2].u.v, sp-1); + if(sp[-2].type == T_CHAR_PTR) { + /* Work of F_INDEX_LVALUE. */ + *sp[-2].u.s = sp[-1].u.i; + } else { + do_assign(sp[-2].u.v, sp-1); + } do_assign(&tmpv, sp-1); pop_stack(); pop_stack(); push_var(&tmpv); break; case F_POSTINC: - tmpvp = sp[-1].u.v; - tmpi = tmpvp->u.i++; + if(sp[-1].type == T_CHAR_PTR) { + tmpi = *sp[-1].u.s; + ++*sp[-1].u.s; + } else { + tmpvp = sp[-1].u.v; + tmpi = tmpvp->u.i++; + } pop_stack(); push_int(tmpi); break; case F_PREINC: - tmpvp = sp[-1].u.v; - tmpi = ++tmpvp->u.i; + if(sp[-1].type == T_CHAR_PTR) { + tmpi = ++*sp[-1].u.s; + } else { + tmpvp = sp[-1].u.v; + tmpi = ++tmpvp->u.i; + } pop_stack(); push_int(tmpi); break; case F_POSTDEC: - tmpvp = sp[-1].u.v; - tmpi = tmpvp->u.i--; + if(sp[-1].type == T_CHAR_PTR) { + tmpi = *sp[-1].u.s; + --*sp[-1].u.s; + } else { + tmpvp = sp[-1].u.v; + tmpi = tmpvp->u.i--; + } push_int(tmpi); break; case F_PREDEC: - tmpvp = sp[-1].u.v; - tmpi = --tmpvp->u.i; + if(sp[-1].type == T_CHAR_PTR) { + tmpi = --*sp[-2].u.s; + } else { + tmpvp = sp[-1].u.v; + tmpi = --tmpvp->u.i; + } push_int(tmpi); break; case F_INDEX: arg[0] = sp[-1].u.i; pop_stack(); + tmpvp = sp[-1].u.v; + pop_stack(); - if(sp[-1].type & T_ARRAY) { - if(!sp[-1].u.a) { + if(tmpvp->type & T_ARRAY) { + if(!tmpvp->u.a) { runtime("taking element of null array", 0); } - if(arg[0] >= sp[-1].u.a->length || arg[0] < 0) { + if(arg[0] < 0 || arg[0] >= tmpvp->u.a->length) { runtime("index out of range", 0); } - tmpvp = sp[-1].u.a->data[arg[0]]; - pop_stack(); + tmpvp = tmpvp->u.a->data[arg[0]]; push_var(tmpvp); } else { - if(!sp[-1].u.s) { + if(!tmpvp->u.s) { runtime("taking element of null string", 0); } - arg[1] = sp[-1].u.s[arg[0]]; - pop_stack(); + if(arg[0] < 0 || arg[0] > strlen(tmpvp->u.s)+1) { + runtime("index out of range", 0); + } + arg[1] = tmpvp->u.s[arg[0]]; push_int(arg[1]); } break; @@ -471,14 +526,26 @@ /* A bit hacky. */ arg[0] = sp[-1].u.i; pop_stack(); - if(!sp[-1].u.s) { + tmpvp = sp[-1].u.v; + pop_stack(); + + tmps = tmpvp->u.s; + if(!tmps) { runtime("taking element of null string", 0); } - do_assign(sp, &sp[-1]); + if(arg[0] < 0 || arg[0] > strlen(tmps)+1) { + runtime("index out of range", 0); + } + + sp->type = T_CHAR_PTR; + sp->u.s = tmps + arg[0]; + sp++; + CHECK_SP() +/* do_assign(sp, &sp[-1]); sp->u.s += arg[0]; pop_stack(); push_var(sp+1); - push_lvalue(sp-1); + push_lvalue(sp-1);*/ break; case F_SLICE: TAKE_SLICE() @@ -598,7 +665,6 @@ SETUP_FRAME(); fp = sp + 1; sp = fp + 1; - show_stack(); call_function(tmpv.u.ob, tmpi); goto again; break; |