From: Peep P. <so...@us...> - 2004-03-21 10:45:59
|
Update of /cvsroot/agd/server/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27597 Modified Files: log.c lang.y interpret.c dfuns.c Log Message: Reformatting. Index: dfuns.c =================================================================== RCS file: /cvsroot/agd/server/src/dfuns.c,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- dfuns.c 21 Mar 2004 08:52:29 -0000 1.14 +++ dfuns.c 21 Mar 2004 10:35:53 -0000 1.15 @@ -72,39 +72,46 @@ list_t *p; for(p = &all_objects; p; p = p->next) { - if(p->data != exclude) - tell_object(p->data, s); + object_t *ob = p->data; + if(ob != exclude) { + tell_object(ob, s); + } } } -void df_write(void) { +void df_write(void) +{ int ret; ret = do_write(fp->u.s); pop_stack(); push_int(ret); } -void df_input_to(void) { +void df_input_to(void) +{ this_player->input_to = fp->u.s; this_player->input_to_called = 0; pop_stack(); push_void(); } -char *get_ip(object_t *ob) { +char *get_ip(object_t *ob) +{ if(!ob->iaob) return NULL; return inet_ntoa(ob->iaob->conn.addr.sin_addr); } -void df_query_ip(void) { +void df_query_ip(void) +{ char *s; s = get_ip(fp->u.ob); pop_stack(); push_string(s, ST_STATIC); } -void df_query_hostname(void) { +void df_query_hostname(void) +{ char *s; struct hostent *he; @@ -121,11 +128,13 @@ push_string(s, ST_STATIC); } -void df_time(void) { +void df_time(void) +{ push_int(time(NULL)); } -void df_asctime(void) { +void df_asctime(void) +{ time_t t; char *s; @@ -136,17 +145,20 @@ push_string(s, ST_STATIC); } -void df_shout(void) { +void df_shout(void) +{ shout(fp[0].u.s, fp[1].u.ob); pop_stack(); pop_stack(); push_void(); } -void df_platform(void) { +void df_platform(void) +{ push_string(PLATFORM, ST_STATIC); } -void df_version(void) { +void df_version(void) +{ push_string(PACKAGE_VERSION, ST_STATIC); } @@ -157,60 +169,60 @@ push_void(); } -void df_find_object(void) { +void df_find_object(void) +{ object_t *ret; ret = find_object(fp->u.s); pop_stack(); push_object(ret); } -void df_load_object(void) { +void df_load_object(void) +{ object_t *ret; ret = load_object(fp->u.s); pop_stack(); push_object(ret); } -void df_this_object(void) { +void df_this_object(void) +{ push_object(this_ob); } -void df_previous_object(void) { +void df_previous_object(void) +{ push_object(previous_ob); } -void df_clone_object(void) { +void df_clone_object(void) +{ object_t *ret; -/* variable_t *saved_fp;*/ push_control_stack(); -/* saved_fp = fp; - fp++;*/ ret = clone_object(/*saved_*/fp->u.s); - /* clone_object() might, or might not call create() and therefore decrease fp. - * We have to decrement manually if needed. */ -/* if(fp > saved_fp) { - fp--; - }*/ pop_control_stack(1); pop_stack(); push_object(ret); } -void df_interactivep(void) { +void df_interactivep(void) +{ int ret = interactivep(fp->u.ob); pop_stack(); push_int(ret); } -void df_tell_object(void) { +void df_tell_object(void) +{ tell_object(fp[0].u.ob, fp[1].u.s); pop_stack(); pop_stack(); push_void(); } -void df_exec(void) { +void df_exec(void) +{ object_t *ob = fp->u.ob; player_t *p; if(!ob) @@ -226,7 +238,8 @@ push_void(); } -void df_file_name(void) { +void df_file_name(void) +{ char *ret; if(fp->u.ob && fp->u.ob->name) ret = fp->u.ob->name; @@ -236,7 +249,8 @@ push_string(ret, ST_STATIC); } -void df_uptime(void) { +void df_uptime(void) +{ time_t t; time(&t); push_int(t - startup_time); @@ -294,3 +308,7 @@ push_string(s, ST_MALLOC); } +void df_report_obs(void) +{ + report_obs(); +} Index: interpret.c =================================================================== RCS file: /cvsroot/agd/server/src/interpret.c,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- interpret.c 21 Mar 2004 09:00:03 -0000 1.14 +++ interpret.c 21 Mar 2004 10:35:53 -0000 1.15 @@ -246,18 +246,6 @@ this_player = /*this_ob->iaob*/ csp->this_player; } -/* Is this necessary? */ -void remove_lvalues(void) { - int i; - for(i=0;i<csp->num_arg;i++) { - if(fp[i].type == T_LVALUE) { - variable_t v = *fp[i].u.v; - do_assign(&fp[i], &v); - } - } -} - - /* Used by F_JMP and F_JMPF to check if they jumped too far. */ #define CHECK_OVERRUN() if((int *) cp >= (int *) code->data + code->length) {\ debug("interpret", "Ran over end of array: returning\n"); return; } @@ -266,6 +254,9 @@ tmp = --sp; if(tmp->type == T_LVALUE) tmp = tmp->u.v;\ arg[tmpi] = tmp->u.i; tmpi++; free_value(sp); } +#define SETUP_CALL_FRAME() tmpi = *++cp; cp++; push_control_stack(); \ + csp->num_arg = *cp; fp = sp - csp->num_arg + void eval_instruction(void) { variable_t *tmp; @@ -443,23 +434,12 @@ push_int(arg[1] <= arg[0] ? 1 : 0); break; case F_CALL_LFUN: - tmpi = *++cp; - /* tmpi is the index of the fun */ - cp++; - push_control_stack(); - csp->num_arg = *cp; - fp = sp - csp->num_arg; - remove_lvalues(); + SETUP_CALL_FRAME(); call_function(this_ob, tmpi); goto again; break; case F_CALL_DFUN: - tmpi = *++cp; - cp++; - push_control_stack(); - csp->num_arg = *cp; - fp = sp - csp->num_arg; - remove_lvalues(); + SETUP_CALL_FRAME(); dfptr[tmpi](); pop_control_stack(0); break; @@ -520,12 +500,16 @@ #endif /* We return to the control level where we entered - we have finished. */ if(csp == saved_csp) { +#ifdef DEBUG debug("interpret", "csp (%d) == saved_csp (%d); returning\n", csp - &control_stack[0], saved_csp - &control_stack[0]); +#endif return; } /* Abnormal termination - need to pop unnecessary stuff off the stack. */ if(this_ob->flags & O_DESTRUCTED) { +#ifdef DEBUG debug("interpret", "this_ob destructed; returning\n"); +#endif /* Should we pop to the bottom? */ pop_control_stack(1); pop_locals(); Index: log.c =================================================================== RCS file: /cvsroot/agd/server/src/log.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- log.c 12 Mar 2004 08:40:10 -0000 1.4 +++ log.c 21 Mar 2004 10:35:53 -0000 1.5 @@ -44,6 +44,7 @@ return 1; } +#if 0 /* If we are compiling the dfparse binary, dfuns.o is not linked and thus we don't get do_time(). */ #ifdef _DFUNS_H @@ -51,6 +52,9 @@ #else #define WRITELOG(x) fprintf(x, "[%s] %s", prefix, str) #endif +#endif + +#define WRITELOG(x) fprintf(x, "%s [%s] %s", ctime(time(NULL)), prefix, str) /* this currently writes the errors into a generic error log, maybe we should write them into separate files */ @@ -66,7 +70,7 @@ str[strlen(str)+1] = '\0'; - if(!strcmp(prefix, "crash") || conf.debuglevel > 1) + if(/*!strcmp(prefix, "crash") ||*/ conf.debuglevel > 1) WRITELOG(stderr); if(!logfile && !check_logfile()) Index: lang.y =================================================================== RCS file: /cvsroot/agd/server/src/lang.y,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- lang.y 20 Mar 2004 20:26:52 -0000 1.9 +++ lang.y 21 Mar 2004 10:35:53 -0000 1.10 @@ -409,20 +409,20 @@ array_push(&$$, (void *) F_RETURN); } | if - { + { init_array(&$$); array_concat(&$$, &$1); - } + } | do_while - { + { init_array(&$$); array_concat(&$$, &$1); - } + } | while - { + { init_array(&$$); array_concat(&$$, &$1); - } + } | expr ';' { init_array(&$$); @@ -438,7 +438,7 @@ { init_array(&$$); } -; + ; statements: /* empty */ @@ -451,7 +451,7 @@ array_concat(&$$, &$1); array_concat(&$$, &$2); } -; + ; arguments: L_DATA_TYPE @@ -616,7 +616,10 @@ } } else if($3.type == T_STRING) { array_push(&$$.arr, (void *) F_PUSH_STRING); - array_push(&$$.arr, strcat($1.arr.data[1], $3.arr.data[1])); + s = xmalloc(strlen($1.arr.data[1]) + strlen($3.arr.data[1]) + 1); + strcpy(s, $1.arr.data[1]); + s = strcat(s, $3.arr.data[1]); + array_push(&$$.arr, s); } else { char buf[256], *buf2; s = $1.arr.data[1]; @@ -1186,7 +1189,9 @@ string_con2 | string_con1 L_PLUS string_con1 { - $$ = strcat($1, $3); + $$ = xmalloc(strlen($1) + strlen($3) + 1); + $$ = strcpy($$, $1); + $$ = strcat($$, $3); } ;*/ @@ -1197,7 +1202,7 @@ } | string_con2 L_STRING { - $$ = malloc(strlen($1) + strlen($2) + 1); + $$ = xmalloc(strlen($1) + strlen($2) + 1); strcpy($$, $1); $$ = strcat($$, $2); } @@ -1271,29 +1276,25 @@ L_DO statement L_WHILE '(' expr ')' { init_array(&$$); -/* if($2.length) {*/ - array_push(&$$, (void *) F_JMP); - array_push(&$$, (void *) ($5.arr.length + 3)); - array_concat(&$$, &$5.arr); - array_push(&$$, (void *) F_JMPF); - array_push(&$$, (void *) ($2.length + 3)); - array_concat(&$$, &$2); - array_push(&$$, (void *) F_JMP); - array_push(&$$, (void *) -($2.length + $5.arr.length + 3)); -/* }*/ + array_push(&$$, (void *) F_JMP); + array_push(&$$, (void *) ($5.arr.length + 3)); + array_concat(&$$, &$5.arr); + array_push(&$$, (void *) F_JMPF); + array_push(&$$, (void *) ($2.length + 3)); + array_concat(&$$, &$2); + array_push(&$$, (void *) F_JMP); + array_push(&$$, (void *) -($2.length + $5.arr.length + 3)); } while: L_WHILE '(' expr ')' statement { init_array(&$$); -/* if($5.length) {*/ - array_concat(&$$, &$3.arr); - array_push(&$$, (void *) F_JMPF); - array_push(&$$, (void *) ($5.length + 3)); - array_concat(&$$, &$5); - array_push(&$$, (void *) F_JMP); - array_push(&$$, (void *) -($5.length + $3.arr.length + 3)); -/* }*/ + array_concat(&$$, &$3.arr); + array_push(&$$, (void *) F_JMPF); + array_push(&$$, (void *) ($5.length + 3)); + array_concat(&$$, &$5); + array_push(&$$, (void *) F_JMP); + array_push(&$$, (void *) -($5.length + $3.arr.length + 3)); } ; @@ -1329,8 +1330,9 @@ /* went okay */ break; default: /* > 0 */ - sprintf(buf, "Argument %d type mismatch for %s - expected %d, got %d", - i, $1->name, $1->args->data[i], tempargs.data[i]); + sprintf(buf, "Argument %d type mismatch for %s - expected %s, got %s", + i, $1->name, type2str($1->args->data[i]), + type2str(tempargs.data[i])); comp_error(buf); break; } |