From: Peep P. <so...@us...> - 2004-06-07 15:54:43
|
Update of /cvsroot/agd/server/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11188 Modified Files: interpret.c Log Message: Temporary interpreter, doesn't work yet. Index: interpret.c =================================================================== RCS file: /cvsroot/agd/server/src/interpret.c,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- interpret.c 3 Apr 2004 20:19:08 -0000 1.18 +++ interpret.c 7 Jun 2004 15:54:34 -0000 1.19 @@ -1,9 +1,32 @@ +#include "compile_options.h" +#include "lpc.h" +#include "list.h" +#include "object.h" + +#include "net.h" +#include "interpret.h" +variable_t *sp, *fp; +control_stack_t control_stack[CONTROL_STACK_SIZE]; +control_stack_t *csp = control_stack; + + +void push_int(int i) { } +void push_void() { } +void push_string(char *s, int i) { } +void push_object(object_t *i) { } +void pop_control_stack(int i) { } +void push_control_stack() { } +void runtime(char *s) { } +variable_t* apply(object_t *ob, char *s, char *fmt, ...) { } +void init_interpreter() { } +int dont_debug_interpreter; +#if 0 #include <stdlib.h> #include <stdarg.h> #include <setjmp.h> #include "compile_options.h" #include "sys.h" -#include "array.h" +/*#include "array.h"*/ #include "lpc.h" #include "object.h" #include "net.h" @@ -151,8 +174,11 @@ void push_array(array_t *a, int type) { + printf("a.data[0]: "); print_var(a->data[0]); putchar('\n'); sp->type = T_ARRAY | type; sp->u.a = a; + printf("a: %p; sp->u.a: %p\n", a, sp->u.a); + printf("a.data[0]: "); print_var(sp->u.a->data[0]); putchar('\n'); /*ref_array(sp->u.a);*/ sp++; CHECK_SP() @@ -160,16 +186,26 @@ void do_assign(variable_t *lval, variable_t *rval) { - *lval = *rval; - switch(lval->type) { + lval->type = rval->type; + if(rval->type & T_ARRAY) { + lval->u.a = rval->u.a; + /*ref_array(lval->u.a);*/ + } else switch(rval->type & ~T_ARRAY) { case T_OBJECT: + lval->u.ob = rval->u.ob; ref_ob(lval->u.ob, lval); break; 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); + } else { + lval->u.s = rval->u.s; } break; + case T_INT: + lval->u.i = rval->u.i; + break; } } @@ -259,7 +295,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"); \ +#define TAKE_SLICE() GET_ARGS() if(!sp[-1].u.s) runtime("taking substring of null string"); \ if(arg[1] >= strlen(sp[-1].u.s) || arg[1] < 0 || arg[1] > arg[0]) runtime("substring out of range"); \ #define SETUP_FRAME() push_control_stack(); csp->num_arg = *cp; fp = sp - csp->num_arg; @@ -285,7 +321,8 @@ break; case F_PUSH_STRING: cp++; - push_string((char *)*cp, ST_STATIC); + tmps = this_prog->str_tbl[*cp]; + push_string(tmps, ST_STATIC); break; case F_PUSH_VOID: push_void(); @@ -296,12 +333,18 @@ case F_PUSH_ARRAY: { array_t *a = type_xmalloc(array_t); - init_array(a); arg[0] = *++cp; arg[1] = *++cp; + a->length = arg[1]; + a->data = calloc(arg[1], sizeof(variable_t*)); for(tmpi=0;tmpi<arg[1];tmpi++) { - array_push(a, --sp); + do_assign(&a->data[tmpi], --sp); + /* Note that we're not freeing the arguments, + * as they go into the array. */ } + printf("a0: "); print_var(a->data[0]); putchar('\n'); + sp -= arg[1]; + printf("a.data[0]: "); print_var(a->data[0]); putchar('\n'); push_array(a, arg[0]); } break; @@ -378,21 +421,34 @@ push_int(tmpi); break; case F_INDEX: - if(!sp[-2].u.s) { - runtime("taking element of NULL string"); - } arg[0] = sp[-1].u.i; pop_stack(); - arg[1] = sp[-1].u.s[arg[0]]; - pop_stack(); - push_int(arg[1]); + + if(sp[-1].type & T_ARRAY) { + if(!sp[-1].u.a) { + runtime("taking element of null array"); + } + if(arg[0] >= sp[-1].u.a->length || arg[0] < 0) { + runtime("index out of range"); + } + tmpvp = sp[-1].u.a->data[arg[0]]; + pop_stack(); + push_var(tmpvp); + } else { + if(!sp[-1].u.s) { + runtime("taking element of null string"); + } + arg[1] = sp[-1].u.s[arg[0]]; + pop_stack(); + push_int(arg[1]); + } break; case F_INDEX_LVALUE: /* A bit hacky. */ arg[0] = sp[-1].u.i; pop_stack(); if(!sp[-1].u.s) { - runtime("taking element of NULL string"); + runtime("taking element of null string"); } do_assign(sp, &sp[-1]); sp->u.s += arg[0]; @@ -508,7 +564,7 @@ } if(!tmpv.u.ob) { - runtime("call_other on NULL object"); + runtime("call_other on null object"); } tmpi = get_fun_index(tmpv.u.ob, tmps); @@ -691,4 +747,4 @@ have_error_context = 0; return fp; } - +#endif |