You can subscribe to this list here.
| 2004 |
Jan
|
Feb
|
Mar
(180) |
Apr
(20) |
May
|
Jun
(91) |
Jul
(78) |
Aug
(18) |
Sep
|
Oct
|
Nov
|
Dec
|
|---|
|
From: Peep P. <so...@us...> - 2004-07-24 18:05:23
|
Update of /cvsroot/agd/server In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv905 Modified Files: TODO NEWS ExitValues ChangeLog Log Message: More changes! Index: ExitValues =================================================================== RCS file: /cvsroot/agd/server/ExitValues,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- ExitValues 21 Mar 2004 13:43:50 -0000 1.2 +++ ExitValues 24 Jul 2004 18:05:13 -0000 1.3 @@ -1,7 +1,8 @@ -0: Normal program termination +-1: Don't bother starting the driver again because it won't bootstrap - + for use by scripts that automatically run the driver +0: Normal termination 1: Out of memory 2: Network error -3: Script problems (for example, master doesn't load) +3: LPC-related error (for example, master doesn't load) 4: Exit due to a signal (this indicates a crash) -5: Configuration error (syntax error in the configuration file, - incorrect arguments, running AGD as root, etc.) +5: Configuration error (syntax error in the configuration file, incorrect arguments, running AGD as root, etc.) Index: NEWS =================================================================== RCS file: /cvsroot/agd/server/NEWS,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- NEWS 23 Jul 2004 17:23:20 -0000 1.14 +++ NEWS 24 Jul 2004 18:05:13 -0000 1.15 @@ -1,11 +1,15 @@ Changes in 0.0.3: * Arrays! * Renamed interactivep() to interactive() + * query_ip() renamed to query_ip_number(), query_hostname() renamed to query_ip_name() * Locals can now be defined in the middle of code. * dfun platform() changed to a preprocessor macro __ARCH__, version() to __VERSION__. - * New dfuns: throw(), users(), sizeof() + * New dfuns: throw(), users(), sizeof(), add_command(), query_verb(), + do_command(), write_file(), master(), shutdown(), get_dir(), this_player(), + find_player(), explode(), implode() * Bitwise operators + * Array slices! Features in 0.0.2-3: * Real string ranges like string[0..4] Index: TODO =================================================================== RCS file: /cvsroot/agd/server/TODO,v retrieving revision 1.25 retrieving revision 1.26 diff -u -d -r1.25 -r1.26 --- TODO 23 Jul 2004 17:21:18 -0000 1.25 +++ TODO 24 Jul 2004 18:05:13 -0000 1.26 @@ -1,69 +1,22 @@ Not necessarily in order of importance. -'!' means first-priority, -'?' means trivial and/or not really important. -'<' means low priority +'!' - first-priority, +'?' - trivial and/or not really important. - - Runtime token positions (aka line number information). - How to do it. Just like in LPMUD. program_t->line_numbers is - an array with the same length as there are lines. Each - element contains the index into the code array at which - the line begins. To find a line number using cp: - get offset into code (cp - code), loop through line_numbers - while our offset is bigger than the element in line_numbers. - If offset is smaller or equal, it means that it must be on - the current index. - - profiling memory usage - find out if variables are really freed and if they're - being overduplicated or something. - - everything to do with arrays, notably: - - operators: - & &= + - lang.y: + - allow 'int *a, int *b' - call_other on an array - foreach() - - dfuns: - delete - member_array - explode, implode - save_object, restore_object - crypt - - allow 'string foo; foo[0]="a";' - - sprintf and printf - - Interpreter. - ? F_PUSH_NUM_INT <constant> <number> - - runtime() for dfuns (doesn't display line numbers) - - lang.y: - ! break, continue - ! fix L_SLICE_LVALUE - - compile.c::compile_prog() should show global vars - - debug.c::print_code() should show functions' arguments - - Do something about compile.c::pop_scope() - it's slow (well, algorithmically speaking, at least). - - In config, for lib: option - if it doesn't end in /, add it. - - Build system. - * make maintainer-clean - should also remove src/dfparse.output and src/lang.output - shouldn't delete src/dfparse.h and src/lang.h - - documentation: - * Small textbook about AGD's dialect of LPC - * Short text describing main differences between LPC and C - * Short text describing AGD and it's purposes, mainly for people coming - from the AGI community. - - syntax highlighting scripts for AGD's LPC (vim, emacs) - - the famous host lookup daemon, so gethostbyaddr() won't block. - Or maybe a separate thread with libpthread? - - keep interactive objects in a separate linked list, and make shout act on that list - - switch() - - all of the operators (/doc/lpc/operators) - - ',' - this takes some serious grammar-hacking, because - comma as a function call argument is a separator for expressions. - - mixed type - - string slices - ! assigning to slices (F_SLICE_LVALUE etc.) - - Check if assigning too long a string. - - m.. - - ..n - - m..n,o..p - - !n - - m..<n - - inheritance + - break, continue + - goto + - string slices + - assigning to slices (F_SLICE_LVALUE etc.) + - Check if assigning too long a string. + - m.. + - ..n + - m..n,o..p + - !n + - m..<n + - switch() - lexer: - preprocessor (read flex(1)) an {IDENTIFIER} rule first up in the rule list which goes through all of the macro @@ -91,12 +44,47 @@ blah FOO"; Or however it's done elsewhere. - ? Better function lookup table (prog->nametable)? O(1) would be nice. - - warn about unused variables - initialization of global variables + - check for lib root with access() and exit gracefully if it fails. + - comma operator (',') + - the famous host lookup daemon, so gethostbyaddr() won't block. + Or maybe a separate thread with libpthread? + + - Runtime token positions (aka line number information). + How to do it. Just like in LPMUD. program_t->line_numbers is + an array with the same length as there are lines. Each + element contains the index into the code array at which + the line begins. To find a line number using cp: + get offset into code (cp - code), loop through line_numbers + while our offset is bigger than the element in line_numbers. + If offset is smaller or equal, it means that it must be on + the current index. + - profiling memory usage - find out if variables are really freed and if they're + being overduplicated or something. + - dfuns: + delete, member_array, save_object, restore_object, crypt, sprintf, printf + - keep interactive objects in a separate linked list, and make shout, find_player etc act on that list + - allow 'string foo; foo[0]="a";' + - Interpreter. + ? F_PUSH_NUM_INT <constant> <number> + - Do something about compile.c::pop_scope() - it's slow (well, algorithmically speaking, at least). + - Build system. + * make maintainer-clean + should also remove src/dfparse.output and src/lang.output + shouldn't delete src/dfparse.h and src/lang.h + - documentation: + * Small textbook about AGD's dialect of LPC + * Short text describing main differences between LPC and C + * Short text describing AGD and its purposes, mainly for people coming + from the AGI community. + - syntax highlighting scripts for AGD's LPC (vim, emacs) + - mixed type + - inheritance - dfun overrides, :: operator - - check for lib root and folder of debug log with access() and exit gracefully if it fails. - - if we crash while running apply(master::crash), then we should rerun with debugging on + - mapping type + - environments, inventories and related dfuns + ? Better function lookup table (prog->nametable)? O(1) would be nice. + - warn about unused variables ? IPv6 support? ? Some work could be done on i18n. For example, allow for multilingual yyerror-messages. Index: ChangeLog =================================================================== RCS file: /cvsroot/agd/server/ChangeLog,v retrieving revision 1.24 retrieving revision 1.25 diff -u -d -r1.24 -r1.25 --- ChangeLog 23 Jul 2004 17:21:18 -0000 1.24 +++ ChangeLog 24 Jul 2004 18:05:13 -0000 1.25 @@ -1,5 +1,8 @@ 0.0.3: ---------------------------------------------------------------------------- +2004-07-24 + * array.c: working intersect_arrays + * dfdecl.in,dfuns.c: get_dir() dfun 2004-07-23 * dflex.l,lex.l,compile.c: added manual 'extern YYLTYPE yylloc' declarations, which seem to be necessary with older version of bison. @@ -210,7 +213,7 @@ * A bit more efficient eval_instruction (read: a couple of microseconds faster) - not checking if jumped too far at every loop cycle, only when doing F_JMP or F_JMPF. - * F_{POST,PRE}{DEC,INC} now call free_value() on it's argument. + * F_{POST,PRE}{DEC,INC} now call free_value() on its argument. * Disabled redefining of dfuns * Fixed crash: unref_prog checks for NULL. * Fixed compilation of do..while. :) @@ -232,7 +235,7 @@ * fixed small bug on array_remove() * fun_table is built during compilation, not after it - neatly sorted and more efficient - * F_CALL_*FUN doesn't need an empty variable on the stack for it's + * F_CALL_*FUN doesn't need an empty variable on the stack for its return value anymore * all locals are now automatically popped off the stack when the function completes (so code like while(1) { int i; } won't overflow |
|
From: Peep P. <so...@us...> - 2004-07-24 18:04:35
|
Update of /cvsroot/agd/server In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv809 Modified Files: configure.ac Log Message: libm is long gone. Index: configure.ac =================================================================== RCS file: /cvsroot/agd/server/configure.ac,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- configure.ac 7 Jun 2004 15:32:59 -0000 1.9 +++ configure.ac 24 Jul 2004 18:04:26 -0000 1.10 @@ -67,9 +67,6 @@ fi # Checks for libraries. -##AC_CHECK_LIB(m, floor) # This was needed by bytes_string, - # which was needed by memory statistics, - # which doesn't exist anymore. ##AC_CHECK_LIB(resolv, accept) AC_CHECK_LIB(nsl, gethostbyaddr) AC_CHECK_LIB(socket, socket) |
|
From: Peep P. <so...@us...> - 2004-07-24 18:04:19
|
Update of /cvsroot/agd/server/doc/dfuns In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv780 Modified Files: load_object clone_object Log Message: Some spelling fixes Index: load_object =================================================================== RCS file: /cvsroot/agd/server/doc/dfuns/load_object,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- load_object 28 Mar 2004 18:42:29 -0000 1.2 +++ load_object 24 Jul 2004 18:04:06 -0000 1.3 @@ -1,7 +1,7 @@ object load_object(string) Tries to load object from path as given by argument. If the object already -exists, it's code will be recompiled; if it succeeds, the code for the object +exists, its code will be recompiled; if it succeeds, the code for the object will be updated, otherwise nothing is changed. See also Index: clone_object =================================================================== RCS file: /cvsroot/agd/server/doc/dfuns/clone_object,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- clone_object 28 Mar 2004 18:42:29 -0000 1.2 +++ clone_object 24 Jul 2004 18:04:06 -0000 1.3 @@ -1,7 +1,7 @@ object clone_object(string|object ob) Clones the object ob and returns the new object. The new object -will share the same code as the master object, it will only have it's +will share the same code as the master object, it will only have its own set of global variables. See also |
|
From: Peep P. <so...@us...> - 2004-07-24 18:03:54
|
Update of /cvsroot/agd/server/doc/lpc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv693 Modified Files: operators Log Message: Binary intersection is done; added :: operator to list Index: operators =================================================================== RCS file: /cvsroot/agd/server/doc/lpc/operators,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- operators 23 Jul 2004 17:22:07 -0000 1.7 +++ operators 24 Jul 2004 18:03:41 -0000 1.8 @@ -31,6 +31,7 @@ , binary comma - left and right side are evaluated, then right side discarded. * [] + :: call inherited function * arithmetic: + binary addition @@ -42,7 +43,7 @@ ** binary power array operators: - & binary intersection * + & binary intersection bitwise operators: & binary AND |
|
From: Peep P. <so...@us...> - 2004-07-24 18:03:11
|
Update of /cvsroot/agd/server/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv635 Modified Files: array.c Log Message: Removed unused code; working intersect_arrays; add_arrays Index: array.c =================================================================== RCS file: /cvsroot/agd/server/src/array.c,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- array.c 23 Jul 2004 17:19:58 -0000 1.17 +++ array.c 24 Jul 2004 18:03:02 -0000 1.18 @@ -15,6 +15,7 @@ #include "sys.h" #include "lpc.h" #include "array.h" +#include "vars.h" void init_array(array_t *a) { @@ -23,117 +24,45 @@ a->data = NULL; } -void free_array(array_t *a, void (*freefun)(variable_t)) +void free_array(array_t *a, void (*freefun)(variable_t*)) { int i; if(!freefun) - freefun = (void(*)(variable_t))free; /* free_var? */ + freefun = free_var; for(i=0;i<a->length;i++) - freefun(a->data[i]); + freefun(&a->data[i]); if(a->length) free(a->data); - init_array(a); + init_array(a); } -#if 0 -void array_push(array_t *a, variable_t *data) -{ - if(!a) - return; - a->length++; - a->data = xrealloc(a->data, sizeof(void *) * a->length); - a->data[a->length-1] = data; -} -#endif -#if 0 -void array_insert(array_t *a, void *data, int index) +void unref_array(array_t *a) { - int i; - -#ifdef DEBUG - if(index > a->length) { - printf("array_insert(): illegal index %d!\n", index); - return; - } -#endif - - a->length++; - a->data = realloc(a->data, sizeof(void *) * a->length); - for(i=a->length-1;i>index;i--) { - a->data[i] = a->data[i-1]; + a->ref--; + if(a->ref < 0) + printf("Warning: array[%p] ref < 0\n", a); + if(a->ref <= 0) { + free_array(a, NULL); } - a->data[index] = data; } -void array_remove(array_t *a, int index) +array_t *add_arrays(array_t *a1, array_t *a2) { int i; - if(index == a->length - 1) { - a->length--; - a->data = realloc(a->data, sizeof(void *) * a->length); - return; - } + array_t *ret; + ret = xmalloc(sizeof(array_t)); + ret->ref = 0; + ret->length = a1->length + a2->length; + ret->data = xmalloc(sizeof(variable_t) * ret->length); - for(i=index;i<a->length;i++) { - a->data[i] = a->data[i+1]; - } - a->length--; - a->data = realloc(a->data, sizeof(void *) * a->length); -/* a->data[++i] = NULL;*/ -} - -void array_remove_by_data(array_t *a, void *data) -{ - int i; - for(i=0;i<a->length;i++) { - if(a->data[i] == data) { - array_remove(a, i); - return; - } - } -} - -array_t *copy_array(array_t *a, void *(*copyfun)(void *)) -{ - array_t *p; - int i; - - p = type_xmalloc(array_t); - p->length = a->length; - p->data = malloc(sizeof(void *) * p->length); - - for(i = 0; i < p->length; i++) - if(copyfun) - p->data[i] = copyfun(a->data[i]); + for(i=0;i<ret->length;i++) { + /* use do_assign? */ + if(i < a1->length) + ret->data[i] = a1->data[i]; else - p->data[i] = a->data[i]; - - return p; -} - -array_t *array_concat(array_t *a1, array_t *a2) -{ - int oldlen, i; - - oldlen = a1->length; - a1->length += a2->length; - a1->data = realloc(a1->data, sizeof(void *) * a1->length); - - for(i = oldlen; i < a1->length; i++) - a1->data[i] = a2->data[i - oldlen]; - - return a1; -} -#endif - -void unref_array(array_t *a) -{ - a->ref--; - if(a->ref < 0) - printf("Warning: array[%p] ref < 0\n", a); - if(a->ref <= 0) { - free_array(a, NULL); + ret->data[i] = a2->data[i - a1->length]; } + return ret; } array_t *sub_arrays(array_t *a1, array_t *a2) { @@ -142,9 +71,7 @@ int appears_in; ret = xmalloc(sizeof(array_t)); - ret->ref = 1; - ret->length = 0; - ret->data = NULL; + init_array(ret); for(i=0;i<a1->length;i++) { appears_in = 0; @@ -167,5 +94,22 @@ } array_t *intersect_arrays(array_t *a1, array_t *a2) { - return a1; + int i, j; + array_t *ret; + + ret = xmalloc(sizeof(array_t)); + init_array(ret); + + for(i=0;i<a1->length;i++) { + for(j=0;j<a2->length;j++) { + if(!compare_vars(&a1->data[i], &a2->data[j])) { + ret->length++; + ret->data = xrealloc(ret->data, sizeof(variable_t) * ret->length); + ret->data[ret->length-1] = a1->data[i]; + break; + } + } + } + + return ret; } |
|
From: Peep P. <so...@us...> - 2004-07-24 18:02:36
|
Update of /cvsroot/agd/server/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv529 Modified Files: array.h Log Message: add_arrays Index: array.h =================================================================== RCS file: /cvsroot/agd/server/src/array.h,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- array.h 23 Jul 2004 17:19:48 -0000 1.10 +++ array.h 24 Jul 2004 18:02:27 -0000 1.11 @@ -8,8 +8,10 @@ } array_t; void init_array(array_t *a); -void free_array(array_t *a, void (*freefun)(variable_t)); +void free_array(array_t *a, void (*freefun)(variable_t*)); #define ref_array(a) a->ref++ + +array_t *add_arrays(array_t *a1, array_t *a2); array_t *sub_arrays(array_t *a1, array_t *a2); array_t *intersect_arrays(array_t *a1, array_t *a2); |
|
From: Peep P. <so...@us...> - 2004-07-24 18:02:14
|
Update of /cvsroot/agd/server/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv450 Modified Files: compile.c Log Message: Removed debugging code; compile error handler (apply in master); some fixes to check_operand Index: compile.c =================================================================== RCS file: /cvsroot/agd/server/src/compile.c,v retrieving revision 1.30 retrieving revision 1.31 diff -u -d -r1.30 -r1.31 --- compile.c 23 Jul 2004 17:19:27 -0000 1.30 +++ compile.c 24 Jul 2004 18:02:05 -0000 1.31 @@ -17,8 +17,8 @@ #include "lang.h" extern YYLTYPE yylloc; - extern object_t *this_ob; +extern object_t *master; program_t *this_prog; function_t *curr_fun; @@ -109,6 +109,9 @@ case ID_GVAR: buf2 = "global variable"; break; + case ID_DFUN: + buf2 = "driver function"; + break; default: buf2 = "idontknowwhat!"; break; @@ -120,10 +123,16 @@ int redeclaration_allowed(def_id_t *target, int type) { + if(target->type == ID_DFUN) + if(type == ID_DFUN) + return 1; + else + return 0; + if(target->base_scope >= scope_level) return 0; - if(target->type == ID_FUN_PROT || target->type == ID_DFUN) + if(target->type == ID_FUN_PROT) return 0; return 1; @@ -382,6 +391,31 @@ return op->valid_types & x; } +int valid_check(operator_t *op, int opr1, int opr2) +{ + if(opr1 == T_ANY || opr2 == T_ANY) + return 1; + + if(op->num_operand == 2) { + if(op->both_same_type) { + if(opr1 != opr2) + return 0; + } else { + int oa1 = opr1 & T_ARRAY; + int oa2 = opr2 & T_ARRAY; + /* Can't have you mixing array and non-array operands. */ + if(oa1 != oa2) + return 0; + } + } + + if(!is_operand_valid(opr1, op)) + return 0; + if(op->num_operand == 2 && opr2 && !is_operand_valid(opr2, op)) + return 0; + return 1; +} + /* Checks if opr1 and opr2 are valid operands to operator. * Returns 0 if not. */ /* Operand 0 means don't do any checking. */ @@ -403,31 +437,28 @@ op = &operator_table[operator-F_ADD]; - /* Urgh. */ - if((opr1 != T_ANY && opr2 != T_ANY) && - (!is_operand_valid(opr1, op) || - (op->num_operand == 2 && opr2 - && !is_operand_valid(opr2, op)) - || (op->both_same_type && opr1 != opr2))) { - switch(op->num_operand) { - case 1: - sprintf(buf, "wrong type argument to unary "); - break; - case 2: - sprintf(buf, "invalid operands to binary "); - break; - case 3: - sprintf(buf, "invalid operands to trinary "); - break; - default: - comp_error("invalid num_operand in check_operand()"); - return; - } - sprintf(buf, "%s%s", buf, op->name); - comp_error(buf); - return 0; + if(valid_check(op, opr1, opr2)) + return 1; + + printf("opr1: %d; opr2: %d\n", opr1, opr2); + + switch(op->num_operand) { + case 1: + sprintf(buf, "wrong type argument to unary "); + break; + case 2: + sprintf(buf, "invalid operands to binary "); + break; + case 3: + sprintf(buf, "invalid operands to trinary "); + break; + default: + comp_error("invalid num_operand in check_operand()"); + return; } - return 1; + sprintf(buf, "%s%s", buf, op->name); + comp_error(buf); + return 0; } /* Post-compilation functions. */ @@ -442,7 +473,7 @@ } } -void add_function(def_id_t *idp, int lineno) +void add_function(def_id_t *idp) { if(idp->index < this_prog->numfunc) { /* Adding a definition for a prototype. */ @@ -455,7 +486,6 @@ f->args = xmalloc(sizeof(int) * f->num_arg); memcpy(f->args, idp->args, f->num_arg * sizeof(int)); #endif - f->lineno = lineno; f->line_numbers = NULL; f->codelen = curr_fun->codelen; f->code = xmalloc(sizeof(int) * f->codelen); @@ -464,9 +494,10 @@ curr_fun_check(); curr_fun->type = idp->lpc_type; curr_fun->num_arg = idp->num_arg; - curr_fun->args = xmalloc(sizeof(int) * curr_fun->num_arg); - memcpy(curr_fun->args, idp->args, curr_fun->num_arg); - curr_fun->lineno = lineno; + if(curr_fun->num_arg) { + curr_fun->args = xmalloc(sizeof(int) * curr_fun->num_arg); + memcpy(curr_fun->args, idp->args, curr_fun->num_arg * sizeof(int)); + } this_prog->numfunc++; this_prog->functions = xrealloc(this_prog->functions, this_prog->numfunc * sizeof(function_t *)); @@ -527,27 +558,32 @@ return define_id(name, type, lpc_type, NULL, 0); } -/* This does the actual formatting. */ -void display_error(char *s) +void do_error(char *s) { + char *buf; + buf = xmalloc(strlen(s) + 50); + sprintf(buf, "%d:%d: %s\n", yylloc.first_line, yylloc.first_column, s); + if(master) { + extern variable_t *fp, *sp; + fp = sp; + apply(master, "compile_error", "ss", this_file, buf); + } else { + printf("%s:%s", this_file, buf); + } + free(buf); +#if 0 if(start_with_newline) { putchar('\n'); start_with_newline = 0; } - printf("%s:%d:%d: %s\n", this_file, yylloc.first_line, yylloc.first_column, s); +#endif } -/* This is the function called by bison, probably with the argument "parse error" - * (I haven't seen anything else). We like to use "syntax error", though. */ int yyerror(char *s) { - if(strcmp(s, "parse error") == 0) - display_error("syntax error"); - else - display_error(s); - compile_errors++; + comp_error(s); return 0; } @@ -602,24 +638,31 @@ program_t *prog; int ret; -#ifdef DEBUG - struct timeval tm, tm2; -#endif + path = add_extension(path); + this_file = path; + if(!legal_path(path)) { + char *buf = xmalloc(strlen(path) + 50); + sprintf(buf, "illegal path '%s'", path); + do_error(buf); + free(buf); + return NULL; + } + + real_path = absolute_path(path); - path = add_extension(path); - #ifdef DEBUG - if(conf.debuglevel) - gettimeofday(&tm, NULL); + if(conf.debuglevel) { + printf("compiling %s... ", path); + start_with_newline = 1; + } #endif - - real_path = absolute_path(path); - printf("compiling %s... ", path); - start_with_newline = 1; yyin = fopen(real_path, "r"); if(!yyin) { - printf("failed (can't open %s: %s)\n", real_path, strerror(errno)); +#ifdef DEBUG + if(conf.debuglevel) + printf("failed (can't open %s: %s)\n", real_path, strerror(errno)); +#endif prog = NULL; goto out; } @@ -629,7 +672,6 @@ this_prog = prog; parse_init(); - this_file = path; #if defined(DEBUG) && YYDEBUG if(conf.debuglevel > 4) { @@ -640,16 +682,19 @@ ret = yyparse(); pop_scope(); /* Go to scope level 0 and free all identifiers. */ - if(ret > 0 || compile_errors) { - if(compile_errors) { - printf("%d error%s", compile_errors, - compile_errors == 1 ? "" : "s"); - if(compile_warnings) - printf(" and %d warning%s", compile_warnings, - compile_warnings == 1 ? "": "s"); +#ifdef DEBUG + if(conf.debuglevel) { + if(compile_errors) { + printf("%d error%s", compile_errors, + compile_errors == 1 ? "" : "s"); + if(compile_warnings) + printf(" and %d warning%s", compile_warnings, + compile_warnings == 1 ? "": "s"); + } + printf(" - failed\n"); } - printf(" - failed\n"); +#endif free(prog); prog = NULL; goto out; @@ -663,24 +708,16 @@ ref_prog(prog); - printf("done"); - #ifdef DEBUG - if(conf.debuglevel) { - gettimeofday(&tm2, NULL); - printf(" in %d microseconds\n", abs(tm2.tv_usec - tm.tv_usec)); - } else { - putchar('\n'); - } + if(conf.debuglevel) + printf("done\n"); if(conf.debuglevel > 1) { printf("Printing code for program %s:\n", path); printf("Globals: \n"); -/* print_var_arr(&this_ob->globals);*/ + print_variables(this_ob->globals, this_ob->numglobals); printf("\n"); print_code(prog); } -#else - putchar('\n'); #endif out: @@ -690,4 +727,3 @@ start_with_newline = 0; return prog; } - |
|
From: Peep P. <so...@us...> - 2004-07-24 18:01:08
|
Update of /cvsroot/agd/server/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32739 Modified Files: compile.h Log Message: Renamed display_error to do_error Index: compile.h =================================================================== RCS file: /cvsroot/agd/server/src/compile.h,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- compile.h 8 Jun 2004 20:24:10 -0000 1.14 +++ compile.h 24 Jul 2004 18:00:59 -0000 1.15 @@ -35,7 +35,6 @@ int check_operand(int operator, int opr1, int opr2); /*int get_fun_index(object_t *ob, char *fun);*/ -void add_function(def_id_t *idp, int lineno); void add_token(int t); void add_two_tokens(int t1, int t2); def_id_t *add_variable(char *name, int lpc_type, int type); @@ -44,10 +43,10 @@ /* Warnings and errors. */ extern int compile_errors, compile_warnings; -void display_error(char *s); +void do_error(char *s); int yyerror(char *s); -#define comp_error(s) display_error(s); compile_errors++ -#define comp_warning(s) display_error("warning: "s); compile_warnings++ +#define comp_error(s) do_error(s); compile_errors++ +#define comp_warning(s) do_error("warning: "s); compile_warnings++ #endif |
|
From: Peep P. <so...@us...> - 2004-07-24 18:00:48
|
Update of /cvsroot/agd/server/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32667 Modified Files: debug.c Log Message: Bitwise operators; showing global variables and function arguments Index: debug.c =================================================================== RCS file: /cvsroot/agd/server/src/debug.c,v retrieving revision 1.19 retrieving revision 1.20 diff -u -d -r1.19 -r1.20 --- debug.c 21 Jul 2004 12:09:15 -0000 1.19 +++ debug.c 24 Jul 2004 18:00:40 -0000 1.20 @@ -133,9 +133,26 @@ case F_DIV_EQ: return "F_DIV_EQ"; case F_MOD: return "F_MOD"; case F_MOD_EQ: return "F_MOD_EQ"; + case F_POW: return "F_POW"; + case F_POW_EQ: return "F_POW_EQ"; + + case F_BAND: return "F_BAND"; + case F_BAND_EQ: return "F_BAND_EQ"; + case F_BOR: return "F_BOR"; + case F_BOR_EQ: return "F_BOR_EQ"; + case F_BXOR: return "F_XOR"; + case F_BXOR_EQ: return "F_BXOR_EQ"; + case F_BNOT: return "F_BNOT"; + case F_BNOT_EQ: return "F_BNOT_EQ"; + case F_BSL: return "F_BSL"; + case F_BSL_EQ: return "F_BSL_EQ"; + case F_BSR: return "F_BSR"; + case F_BSR_EQ: return "F_BSR_EQ"; + case F_ASSIGN: return "F_ASSIGN"; case F_POP: return "F_POP"; case F_POP_N: return "F_POP_N"; + case F_POP_PENUL: return "F_POP_PENUL"; case F_CALL_LFUN: return "F_CALL_LFUN"; case F_CALL_DFUN: return "F_CALL_DFUN"; case F_CALL_OTHER: return "F_CALL_OTHER"; @@ -164,53 +181,18 @@ } } -#if 0 -void print_array(array_t *a) -{ - int i; - printf("data: %p; ", (void *) a->data); - printf("({"); - if(!a->data) { - printf(" })"); - return; - } - for(i = 0; i < a->length; i++) { - printf("%ld/%p", i, a->data[i]); - if(i + 1 < a->length) - printf(", "); - } - if(!i) printf(" "); - printf("})"); -} - -void print_var_arr(array_t *a) +void print_variables(variable_t *a, int num) { int i; - printf("({"); - for(i = 0; i < a->length; i++) { - print_var((variable_t *) a->data[i], 1); - if(i + 1 < a->length) - printf(","); - } - printf("})"); -} - -void print_vmt_arr(array_t *a) -{ - int j; printf("({ "); - if(a) { - for(j=0;j<a->length;j++) { - print_vm_token(a, &j); - if(j+1<a->length) - printf(", "); - } + for(i=0;i<num;i++) { + print_var(&a[i]); + if(i+1<num) + printf(", "); } - printf(" }) "); + printf(" })"); } -#endif - void print_instr(program_t *prog, function_t *f) { int i; @@ -286,17 +268,25 @@ void print_code(program_t *p) { - int i; + int i, j; function_t *f; printf("Functions: \n"); for(i = 0; i < p->numfunc; i++) { f = p->functions[i]; - printf("Function %d:\n", i); - printf(" Type %s\n", type2str(f->type)); - printf(" Arguments: "); -/* print_var_arr(&f->args);*/ - printf("\n"); + printf("Function %d (%s):\n", i, p->fun_table[i]); + printf(" Type: %s\n", type2str(f->type)); + if(!f->num_arg) + printf(" No arguments\n"); + else { + printf(" %d argument%s: ({ ", f->num_arg, f->num_arg!=1?"s":""); + for(j=0;j<f->num_arg;j++) { + printf("%s", type2str(f->args[j])); + if(j+1<f->num_arg) + printf(", "); + } + printf(" })\n"); + } printf(" Code:\n"); print_instr(p, f); printf("\n"); @@ -304,5 +294,4 @@ if(i == 0) printf("({ })\n"); } -#endif /* ifdef DEBUG */ - +#endif /* #ifdef DEBUG */ |
|
From: Peep P. <so...@us...> - 2004-07-24 18:00:32
|
Update of /cvsroot/agd/server/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32590 Modified Files: dfdecl.in Log Message: shutdown, master, get_dir, write_file, implode, explode, do_command, query_verb, add_command, this_player, find_player; rearranged order Index: dfdecl.in =================================================================== RCS file: /cvsroot/agd/server/src/dfdecl.in,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- dfdecl.in 21 Jul 2004 12:08:43 -0000 1.14 +++ dfdecl.in 24 Jul 2004 18:00:07 -0000 1.15 @@ -20,43 +20,57 @@ int interactive(object) void input_to(string) int query_idle(object) -string query_ip(object) -string query_hostname(object) +string query_ip_number(object) +string query_ip_name(object) +object *users() +object this_player() +object find_player(string) -# Time. -int time() -string asctime(int) -string strftime(int, string) -int uptime() +varargs void add_command(string, string) +string query_verb() +void do_command(string) -# Filesystem. -string read_file(string) +# Objects. +void destruct() +object find_object(string) +object load_object(string) +object clone_object(string) +object this_object() +object previous_object() +void exec(object) +string file_name(object) # Numbers. int random(int) int atoi(string) +# Time. +int time() +string asctime(int) +string strftime(int, string) +int uptime() + # Strings. int strlen(string) string capitalize(string) string lower_case(string) +string *explode(string, string) +string implode(string*, string) # Arrays. int sizeof(*) -# Objects. -void destruct(object) -object find_object(string) -object clone_object(string) -object this_object() -object previous_object() -object load_object(string) -void exec(object) -string file_name(object) -object *users() +# Filesystem. +string read_file(string) +varargs int write_file(string, string, int) +string *get_dir(string) # Misc. void throw(string) +# System. +object master() +varargs void shutdown(int) + # Debugging. void debug_info(int) |
|
From: Peep P. <so...@us...> - 2004-07-24 17:59:26
|
Update of /cvsroot/agd/server/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32411 Modified Files: dfparse.y dfparse.h dflex.l Log Message: varargs functions Index: dfparse.h =================================================================== RCS file: /cvsroot/agd/server/src/dfparse.h,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- dfparse.h 8 Jun 2004 20:20:48 -0000 1.7 +++ dfparse.h 24 Jul 2004 17:59:15 -0000 1.8 @@ -30,17 +30,19 @@ know about them. */ enum yytokentype { L_IDENTIFIER = 258, - L_DATA_TYPE = 259 + L_DATA_TYPE = 259, + L_VARARGS = 260 }; #endif #define L_IDENTIFIER 258 #define L_DATA_TYPE 259 +#define L_VARARGS 260 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED) -#line 66 "dfparse.y" +#line 69 "dfparse.y" typedef union YYSTYPE { char *s; int i; @@ -50,7 +52,7 @@ } a; } YYSTYPE; /* Line 1240 of yacc.c. */ -#line 54 "dfparse.h" +#line 56 "dfparse.h" # define yystype YYSTYPE /* obsolescent; will be withdrawn */ # define YYSTYPE_IS_DECLARED 1 # define YYSTYPE_IS_TRIVIAL 1 Index: dflex.l =================================================================== RCS file: /cvsroot/agd/server/src/dflex.l,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- dflex.l 23 Jul 2004 17:19:05 -0000 1.6 +++ dflex.l 24 Jul 2004 17:59:15 -0000 1.7 @@ -4,6 +4,7 @@ #include "sys.h" #include "lpc.h" #include "dfparse.h" + extern YYLTYPE yylloc; #define pos yylloc.first_column #define line yylloc.first_line @@ -44,6 +45,10 @@ pos += 6; return L_DATA_TYPE; } +varargs { + return L_VARARGS; +} + {IDENTIFIER} { char *s = xstrdup(yytext); yylval.s = s; Index: dfparse.y =================================================================== RCS file: /cvsroot/agd/server/src/dfparse.y,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- dfparse.y 23 Jul 2004 14:22:43 -0000 1.12 +++ dfparse.y 24 Jul 2004 17:59:15 -0000 1.13 @@ -4,6 +4,8 @@ NOTE: Maybe we could put the prototypes in dfuns.h or in dfuns.c? Changelog: + 0.10: + * varargs type modifier 0.09: * Not using argument variants any more. * Prints out return type as a string. @@ -41,7 +43,7 @@ #include "sys.h" /* xmalloc */ #include "lpc.h" -#define DFVERSION "0.09" +#define DFVERSION "0.10" #define DFDECL_T "typedef struct {\n\tint ret;\n\tchar *name;\n\tvoid (*fun)(void);\n\t"\ "int num_arg;\n\tint args[%d];\n} dfdecl_t;\n" @@ -75,8 +77,9 @@ %token <s> L_IDENTIFIER %token <i> L_DATA_TYPE +%token L_VARARGS -%type <i> type arg_type optional_star +%type <i> type fun_type_mod arg_type optional_star %type <a> arguments argument_and_another %% @@ -87,16 +90,16 @@ ; dfdecl: - type L_IDENTIFIER '(' arguments ')' + fun_type_mod type L_IDENTIFIER '(' arguments ')' { dfdecl_t decl; - decl.ret = $1; - decl.name = $2; - decl.num_arg = $4.len; + decl.ret = $1 | $2; + decl.name = $3; + decl.num_arg = $5.len; if(decl.num_arg > greatest_num_arg) greatest_num_arg = decl.num_arg; if(decl.num_arg) - decl.args = $4.data; + decl.args = $5.data; dfdecl = xrealloc(dfdecl, sizeof(dfdecl_t) * ++numdecl); dfdecl[numdecl-1] = decl; @@ -113,6 +116,11 @@ { $$ = $1|$2; } ; +fun_type_mod: + L_VARARGS { $$ = MOD_VARARGS; } + | /* empty */ { $$ = 0; } + ; + arg_type: type | '*' { $$ = T_ARRAY; } |
|
From: Peep P. <so...@us...> - 2004-07-24 17:58:59
|
Update of /cvsroot/agd/server/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32302 Modified Files: dfuns.c Log Message: New dfuns: shutdown, master, get_dir, write_file, implode, explode, do_command, query_verb, add_command, find_player, this_player; rearranged order into categories Index: dfuns.c =================================================================== RCS file: /cvsroot/agd/server/src/dfuns.c,v retrieving revision 1.25 retrieving revision 1.26 diff -u -d -r1.25 -r1.26 --- dfuns.c 23 Jul 2004 17:18:35 -0000 1.25 +++ dfuns.c 24 Jul 2004 17:58:50 -0000 1.26 @@ -2,6 +2,9 @@ #include <stdio.h> #include <time.h> #include <errno.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <dirent.h> #include <netdb.h> /* for gethostbyaddr() */ #include "arch.h" @@ -17,6 +20,7 @@ extern player_t *this_player; extern object_t *this_ob, *previous_ob; +extern object_t *master; extern list_t players; extern list_t all_objects; @@ -37,7 +41,8 @@ dfptr[i] = decl[i].fun; num_arg = decl[i].num_arg; - args = xmalloc(sizeof(int) * num_arg); + if(num_arg) + args = xmalloc(sizeof(int) * num_arg); for(j=0;j<num_arg;j++) { args[j] = decl[i].args[j]; @@ -46,6 +51,7 @@ } } +/* Interactives. */ void do_write(char *s) { if(this_player) @@ -63,7 +69,7 @@ for(p = &all_objects; p; p = p->next) { object_t *ob = p->data; - if(ob->iaob && ob != this_player->ob) { + if(ob->iaob/* && ob != this_player->ob*/) { tell_object(ob, s); } } @@ -76,6 +82,28 @@ push_void(); } +void df_shout(void) +{ + shout(fp[0].u.s); + pop_stack(); + push_void(); +} + +void df_tell_object(void) +{ + tell_object(fp[0].u.ob, fp[1].u.s); + pop_stack(); pop_stack(); + push_void(); +} + +void df_interactive(void) +{ + object_t *ob = fp->u.ob; + int ret = ob && ob->iaob; + pop_stack(); + push_int(ret); +} + void df_input_to(void) { if(this_player) { @@ -92,6 +120,17 @@ push_void(); } +void df_query_idle(void) +{ + int ret; + if(!fp->u.ob->iaob) + ret = -1; + else + ret = time(NULL) - fp->u.ob->iaob->conn.last_active; + pop_stack(); + push_int(ret); +} + char *get_ip(object_t *ob) { if(!ob->iaob) @@ -99,7 +138,7 @@ return inet_ntoa(ob->iaob->conn.addr.sin_addr); } -void df_query_ip(void) +void df_query_ip_number(void) { char *s; s = get_ip(fp->u.ob); @@ -107,7 +146,7 @@ push_string(s, ST_STATIC); } -void df_query_hostname(void) +void df_query_ip_name(void) { char *s; struct hostent *he; @@ -125,17 +164,117 @@ push_string(s, ST_STATIC); } -void df_shout(void) +void df_users(void) { - shout(fp[0].u.s); + list_t *l; + array_t *ret; + ret = xmalloc(sizeof(array_t)); + init_array(ret); + for(l=&players;l;l=l->next) { + player_t *pl = l->data; + ret->length++; + ret->data = xrealloc(ret->data, ret->length * sizeof(variable_t)); + ret->data[ret->length-1].type = T_OBJECT; + ret->data[ret->length-1].u.ob = pl->ob; +#ifdef DEBUG + ret->data[ret->length-1].name = NULL; +#endif + } + push_array(ret, T_OBJECT); +} + +void df_this_player(void) +{ + push_object(this_player->ob); +} + +void df_find_player(void) +{ + char *name; + object_t *ret = NULL; + list_t *l; + + name = fp->u.s; + if(!name) { + goto out; + } + + for(l=&players;l;l=l->next) { + player_t *pl; + variable_t *var; + pl = l->data; + push_control_stack(); + fp = sp; + var = apply(pl->ob, "query_name", ""); + if(strcmp(var->u.s, name) == 0) { + ret = pl->ob; + pop_control_stack(1); + goto out; + } else { + pop_control_stack(1); + } + } + +out: pop_stack(); - push_void(); + push_object(ret); } -void df_destruct(void) +void df_add_command(void) { - destruct(fp->u.ob); + int num_arg = sp - fp; + player_t *p; + command_t *cmd; + + if(num_arg < 1) { + runtime("add_command() needs a verb"); + return; + } + if(!this_player) + return; + + p = this_player; + p->num_cmd++; + p->cmds = xrealloc(p->cmds, p->num_cmd * sizeof(command_t)); + cmd = &p->cmds[p->num_cmd-1]; + cmd->verb = xstrdup(fp->u.s); + if(num_arg >= 2) + cmd->fun = xstrdup(fp[1].u.s); + else { + cmd->fun = xmalloc(strlen(cmd->verb) + 4); + sprintf(cmd->fun, "do_%s", cmd->verb); + } +} + +void df_query_verb(void) +{ + command_t *cmd; + + if(!this_player || this_player->this_verb == 0) { + push_string(NULL, ST_MALLOC); + return; + } + + cmd = &this_player->cmds[this_player->this_verb-1]; + push_string(xstrdup(cmd->verb), ST_MALLOC); +} + +void df_do_command(void) +{ + char *cmd = fp->u.s; + + push_control_stack(); + fp++; + do_command(this_player, cmd); + pop_control_stack(1); + pop_stack(); +} + +/* Objects. */ +void df_destruct(void) +{ + destruct(this_ob); push_void(); } @@ -155,42 +294,27 @@ push_object(ret); } -void df_this_object(void) -{ - push_object(this_ob); -} - -void df_previous_object(void) -{ - push_object(previous_ob); -} - void df_clone_object(void) { object_t *ret; push_control_stack(); fp++; - ret = clone_object(csp[/*-1*/0].fp->u.s); + ret = clone_object(csp->fp->u.s); pop_control_stack(1); pop_stack(); push_object(ret); } -void df_interactive(void) +void df_this_object(void) { - object_t *ob = fp->u.ob; - int ret = ob && ob->iaob; - pop_stack(); - push_int(ret); + push_object(this_ob); } -void df_tell_object(void) +void df_previous_object(void) { - tell_object(fp[0].u.ob, fp[1].u.s); - pop_stack(); pop_stack(); - push_void(); + push_object(previous_ob); } void df_exec(void) @@ -221,33 +345,6 @@ push_string(ret, ST_STATIC); } -void df_query_idle(void) -{ - int ret; - if(!fp->u.ob->iaob) - ret = -1; - else - ret = time(NULL) - fp->u.ob->iaob->conn.last_active; - pop_stack(); - push_int(ret); -} - -void df_users(void) -{ - list_t *l; - array_t *ret; - ret = xmalloc(sizeof(array_t)); - init_array(ret); - for(l=&players;l;l=l->next) { - player_t *pl = l->data; - ret->length++; - ret->data = xrealloc(ret->data, ret->length * sizeof(variable_t)); - ret->data[ret->length-1].type = T_OBJECT; - ret->data[ret->length-1].u.ob = pl->ob; - } - push_array(ret, T_OBJECT); -} - /* Numbers. */ void df_random(void) { @@ -267,13 +364,6 @@ } /* Time. */ -void df_uptime(void) -{ - time_t t; - time(&t); - push_int(t - startup_time); -} - void df_time(void) { push_int(time(NULL)); @@ -306,6 +396,13 @@ push_string(buf, ST_STATIC); } +void df_uptime(void) +{ + time_t t; + time(&t); + push_int(t - startup_time); +} + /* Strings. */ void df_strlen(void) { @@ -338,6 +435,75 @@ push_string(s, ST_MALLOC); } +void df_explode(void) +{ + char *str, *delim; + char *bgn, *end; + array_t *ret; + variable_t *tmpv; + int len; + + str = fp->u.s; + delim = fp[1].u.s; + ret = xmalloc(sizeof(array_t)); + init_array(ret); + + bgn = str; + while(1) { + if(!bgn) + break; + + end = strstr(bgn, delim); + if(end) + len = end - bgn; + else + len = strlen(bgn); + + ret->length++; + ret->data = xrealloc(ret->data, ret->length * sizeof(variable_t)); + tmpv = &ret->data[ret->length-1]; + tmpv->type = T_STRING; +#ifdef DEBUG + tmpv->name = NULL; +#endif + tmpv->u.s = xmalloc(len + 1); + strncpy(tmpv->u.s, bgn, len); + tmpv->u.s[len] = '\0'; + + if(!end) + break; + bgn = end + 1; + } + +out: + pop_stack(); pop_stack(); + push_array(ret, ST_MALLOC); +} + +void df_implode(void) +{ + array_t *args; + char *del; + char *ret, *retp; + int i; + + args = fp->u.a; + del = fp[1].u.s; + + ret = xmalloc(1); + ret[0] = '\0'; + retp = ret; + for(i=0;i<args->length;i++) { + char *s = args->data[i].u.s; + ret = xrealloc(ret, strlen(ret) + 1 + strlen(s) + strlen(del)); + retp = ret + strlen(ret); + sprintf(retp, "%s%s", s, (i+1<args->length)?del:""); + } + + pop_stack(); pop_stack(); + push_string(ret, ST_MALLOC); +} + /* Arrays. */ void df_sizeof(void) { @@ -351,17 +517,28 @@ void df_read_file(void) { FILE *f; - char *path; + char *path, *real_path; int file_size; char *file_str, *p; char buf[256]; - path = absolute_path(fp->u.s); - f = fopen(path, "r"); + path = fp->u.s; + if(!legal_path(path)) { + char *buf = xmalloc(strlen(path) + 50); + sprintf(buf, "illegal filename '%s'!", path); + runtime(buf); + free(buf); + return; + } + + real_path = absolute_path(path); + f = fopen(real_path, "r"); if(!f) { char *buf = xmalloc(strlen(path) + 50); sprintf(buf, "can't open '%s' for reading!", path); - runtime_dyn(buf); + runtime(buf); + free(buf); + return; } file_str = NULL; @@ -379,6 +556,121 @@ push_string(file_str, ST_MALLOC); } +void df_write_file(void) +{ + int num_arg; + int ret; + FILE *f; + char *path, *real_path; + char *mode; + + num_arg = sp - fp; + if(num_arg < 1) { + runtime("write_file() needs a filename"); + push_int(1); + return; + } + if(num_arg < 2) { + runtime("write_file() needs a string"); + pop_stack(); + push_int(1); + return; + } + + if(num_arg >= 3 && fp[2].u.i) + mode = "w"; + else + mode = "a"; + + path = fp->u.s; + if(!legal_path(path)) { + char *buf = xmalloc(strlen(path) + 50); + sprintf(buf, "illegal filename '%s'!", path); + runtime(buf); + free(buf); + ret = 1; + goto out; + } + + real_path = absolute_path(path); + f = fopen(real_path, mode); + if(!f) { + char *buf = xmalloc(strlen(path) + 50); + sprintf(buf, "can't open '%s' for %sing!", path, + mode[0] == 'w' ? "writ" : "append"); + runtime(buf); + free(buf); + ret = 1; + goto out; + } + + ret = fprintf(f, "%s", fp[1].u.s); + fclose(f); + +out: + pop_stack(); pop_stack(); + push_int(ret ? 1 : 0); +} + +void df_get_dir(void) +{ + array_t *ret; + char *path, *real_path; + DIR *d; + struct dirent *entry; + + path = fp->u.s; + add_slash(path); + if(!legal_path(path)) { + char *buf; + buf = xmalloc(strlen(path) + 50); + sprintf(buf, "invalid path '%s'", path); + runtime(buf); + free(buf); + return; + } + + ret = xmalloc(sizeof(array_t)); + init_array(ret); + + real_path = absolute_path(path); + d = opendir(real_path); + while(entry = readdir(d)) { + struct stat st; + char *filename; + + if(entry->d_name[0] == '.') + continue; + + filename = xmalloc(strlen(entry->d_name) + strlen(real_path) + 1); + sprintf(filename, "%s%s", real_path, entry->d_name); + if(stat(filename, &st) < 0) { + char *buf; + buf = xmalloc(strlen(path) + strlen(entry->d_name) + 50); + sprintf(buf, "can't stat '%s%s'", path, entry->d_name); + runtime(buf); + ret = NULL; + goto out; + } + if(S_ISDIR(st.st_mode)) + continue; + + ret->length++; + ret->data = xrealloc(ret->data, sizeof(variable_t) * ret->length); + ret->data[ret->length-1].type = T_STRING; + ret->data[ret->length-1].u.s = xstrdup(entry->d_name); +#ifdef DEBUG + ret->data[ret->length-1].name = NULL; +#endif + } + +out: + closedir(d); + + pop_stack(); + push_array(ret, T_STRING); +} + /* Misc. */ void df_throw(void) { @@ -387,6 +679,20 @@ push_void(); } +/* System. */ +void df_master(void) +{ + push_object(master); +} + +void df_shutdown(void) { + if(sp > fp && fp->u.i) + exit(EXIT_DONTBOTHER); + else + exit(EXIT_NORMAL); +} + +/* Debugging. */ void show_all_obj(void) { list_t *p; @@ -400,7 +706,6 @@ puts("----------------------------------------"); } -/* Debugging. */ void df_debug_info(void) { switch(fp->u.i) { |
|
From: Peep P. <so...@us...> - 2004-07-24 17:57:20
|
Update of /cvsroot/agd/server/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32102 Modified Files: interpret.c Log Message: Aesthetic stack traces; handling runtime errors which happen during loading an object (in create()); F_SLICE and F_SLICE_LVALUE work on arrays; removed some debugging code Index: interpret.c =================================================================== RCS file: /cvsroot/agd/server/src/interpret.c,v retrieving revision 1.27 retrieving revision 1.28 diff -u -d -r1.27 -r1.28 --- interpret.c 23 Jul 2004 17:17:01 -0000 1.27 +++ interpret.c 24 Jul 2004 17:57:11 -0000 1.28 @@ -41,13 +41,13 @@ void call_function(object_t *ob, int index); extern char *opc_name(int i); +extern int doing_load; + unsigned get_line_number(control_stack_t *p) { return 42; } char *get_fun_name(int num, control_stack_t *csp) { - if(num < 0) - return "*DFUN"; if(csp->this_ob) { if(csp->this_ob->prog) return csp->this_ob->prog->fun_table[num]; @@ -57,54 +57,80 @@ return this_ob->prog->fun_table[num]; } +char *make_errmsg(control_stack_t *p, char *s) +{ + char *buf, *bufp; + buf = xmalloc(1024); + memset(buf, 0, 1024); + + bufp = buf; + sprintf(bufp, "%s: ", p->this_ob ? p->this_ob->name : "unknown"); + bufp += strlen(bufp); + + if(s) { + sprintf(bufp, "%s in ", s); + bufp += strlen(bufp); + } + + if(p->fun >= 0) { + sprintf(bufp, "function %d (%s) on line %d\n", p->fun, + get_fun_name(p->fun, p), get_line_number(p)); + } else { + sprintf(bufp, "dfun %d\n", -p->fun); + } + return buf; +} + void stack_trace(void) { int i, len; len = csp - &control_stack[0]; printf("Stack trace:\n"); - for(i=len;i>0;i--) { - control_stack_t *p = &control_stack[i]; - printf("%d %s: function %d (%s) on line %d\n", - i, p->this_ob?p->this_ob->name:"unknown", - p->fun, get_fun_name(p->fun, p), - get_line_number(p)); + for(i=1;i<=len;i++) { + char *buf; + buf = make_errmsg(&control_stack[i], NULL); + printf("%d %s", i, buf); + free(buf); } } /* free_str: whether to free the string passed to it before * doing longjmp() or not - for dynamically allocated strings */ -void _runtime(char *s, int free_str) +void runtime(char *s) { char *buf; if(!this_ob) { - printf("%s on line %d (function %s)\n", s, - get_line_number(csp), - get_fun_name(csp->fun, csp)); + buf = make_errmsg(csp, s); + printf("%s", buf); + free(buf); goto out; } - buf = xmalloc(strlen(this_ob->name) + strlen(s) + 64); - sprintf(buf, "%s: %s on line %d function %d (%s)\n", this_ob->name, s, +/* sprintf(buf, "%s: %s on line %d function %d (%s)\n", this_ob->name, s, get_line_number(csp-1), - csp->fun, get_fun_name(csp->fun, csp)); + csp->fun, get_fun_name(csp->fun, csp));*/ + buf = make_errmsg(csp, s); + if(doing_load) + printf("While loading object "); printf(buf); - if(this_player) { + if(this_player) do_write(buf); - } free(buf); - if(free_str) - free(s); - stack_trace(); out: + if(doing_load) { + doing_load = 0; + return; + } + fp = value_stack; pop_locals(); csp = &control_stack[2]; pop_control_stack(0); - + longjmp(error_context, 1); } @@ -112,7 +138,7 @@ { sp->type = T_OBJECT; sp->u.ob = ob; - ref_ob(ob, sp); + ref_ob(ob, NULL); sp++; CHECK_SP() } @@ -332,6 +358,8 @@ GET_ARGS(); v = sp[-1].u.v; + index_check(v, arg); +#if 0 if(!v->u.s) runtime("taking substring of null string"); if(arg[0] > arg[1]) @@ -339,6 +367,7 @@ if(arg[0] < 0 || arg[1] > strlen(v->u.s)) { runtime("substring out of range"); } +#endif return v; } @@ -701,20 +730,21 @@ } break; case F_SLICE: - tmpvp = take_slice(arg); - tmps = xmalloc(arg[1] - arg[0] + 2); - for(tmpi=arg[0];tmpi<=arg[1];tmpi++) - tmps[tmpi-arg[0]] = tmpvp->u.s[tmpi]; - tmps[arg[1] - arg[0] + 1] = '\0'; + tmpvp = slice_var(take_slice(arg), arg[0], arg[1]); pop_stack(); - push_string(tmps, ST_MALLOC); + push_var(tmpvp); break; case F_SLICE_LVALUE: - tmpvp = take_slice(arg); - tmps = tmpvp->u.s + arg[1]; /* begin */ - tmpi = tmpvp->string_type; - pop_stack(); - push_string(tmps, tmpi); + tmpvp = slice_var(take_slice(arg), arg[0], arg[1]); + if(tmpvp->type & T_ARRAY) { + pop_stack(); + push_var(tmpvp); + } else { + tmps = tmpvp->u.s + arg[1]; /* begin */ + tmpi = tmpvp->string_type; + pop_stack(); + push_string(tmps, tmpi); + } push_lvalue(sp-1); break; case F_JUMP_IF_FALSE: @@ -848,8 +878,9 @@ /* Abnormal termination - need to pop unnecessary stuff off the stack. */ if(this_ob->flags & O_DESTRUCTED) { - while(csp->this_ob == this_ob) + while(csp->this_ob == this_ob) { pop_control_stack(1); + } pop_locals(); return; } @@ -863,9 +894,8 @@ int i; function_t *f = ob->prog->functions[index]; if(!f) { - char *buf = xmalloc(512); - sprintf(buf, "function %d doesn't exist in object \"%s\"", index, ob->name); - runtime_dyn(buf); + /* Shouldn't happen. */ + return; } csp->fun = index; @@ -932,19 +962,11 @@ char *p; int i, j; -#ifdef DEBUG - struct timeval tm, tm2; -#endif - index = get_fun_index(ob, fun); if(index == -1) return NULL; #ifdef DEBUG - gettimeofday(&tm, NULL); -#endif - -#ifdef DEBUG if(conf.debuglevel) printf("[lpc] apply \"%s\" on \"%s\"\n", fun, ob->name); #endif @@ -965,7 +987,7 @@ case 's': /* We duplicate the string, so we can be sure it's not static and can free() it. */ - push_string(xstrdup(va_arg(va, char*)), ST_MALLOC); + push_string(xstrdup(va_arg(va, char *)), ST_MALLOC); csp->num_arg++; break; default: @@ -998,9 +1020,8 @@ eval_instruction(); #ifdef DEBUG - gettimeofday(&tm2, NULL); if(conf.debuglevel) - printf("[lpc] apply \"%s\" done in %d microseconds\n", fun, tm2.tv_usec - tm.tv_usec); + printf("[lpc] apply \"%s\" done\n", fun); #endif have_error_context = 0; |
|
From: Peep P. <so...@us...> - 2004-07-24 17:56:17
|
Update of /cvsroot/agd/server/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31978 Modified Files: interpret.h Log Message: Removed runtime_dyn. Index: interpret.h =================================================================== RCS file: /cvsroot/agd/server/src/interpret.h,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- interpret.h 21 Jul 2004 12:02:37 -0000 1.17 +++ interpret.h 24 Jul 2004 17:56:08 -0000 1.18 @@ -7,9 +7,6 @@ #define pop_stack() sp--; free_var(sp) #define pop_locals() while(sp > fp) { sp--; free_var(sp); } -#define runtime(msg) _runtime(msg, 0) -#define runtime_dyn(msg) _runtime(msg, 1) - typedef struct { variable_t *sp, *fp; int num_arg; |
|
From: Peep P. <so...@us...> - 2004-07-24 17:54:40
|
Update of /cvsroot/agd/server/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31709 Modified Files: lang.y Log Message: Fixed some problems with T_ANY; no num_arg checking for varargs functions Index: lang.y =================================================================== RCS file: /cvsroot/agd/server/src/lang.y,v retrieving revision 1.26 retrieving revision 1.27 diff -u -d -r1.26 -r1.27 --- lang.y 23 Jul 2004 17:03:56 -0000 1.26 +++ lang.y 24 Jul 2004 17:54:30 -0000 1.27 @@ -19,7 +19,7 @@ /* Used during compilation, replaced with F_JMP. Need to use two separate numbers for both, because one - could easily appear on it's own in code. */ + could easily appear on its own in code. */ /* These are unnecessary with the add_token() system. */ #define L_BREAK_MAGIC1 -1 #define L_BREAK_MAGIC2 -2 @@ -48,6 +48,7 @@ int add_string_to_table(char *s); void make_lvalue(int index); +extern void add_function(def_id_t *idp); %} /* Makes bison define YYLTYPE */ @@ -150,7 +151,7 @@ str = type2str(DEFAULT_FUNCTION_TYPE); buf = xmalloc(strlen(str) + 34); sprintf(buf, "warning: return type defaults to %s", type2str(DEFAULT_FUNCTION_TYPE)); - display_error(buf); + do_error(buf); compile_warnings++; free(buf); } @@ -215,18 +216,18 @@ } } - add_function(idp, @$.first_line); + add_function(idp/*, @$.first_line*/); curr_fun_type = 0; } else { def_id_t *idp = $<id>3; if(idp->type == ID_FUN_PROT && !is_new_declaration) { char *buf = xmalloc(strlen($2) + 64); sprintf(buf, "warning: repeated prototype for %s; using existing prototype", $2); - display_error(buf); + do_error(buf); free(buf); compile_warnings++; } else { - add_function(idp, @$.first_line); + add_function(idp/*, @$.first_line*/); } } pop_scope(); @@ -278,8 +279,8 @@ $$.direct_type = 1; $$.lval = 0; -/* $$.type = $1 ? T_INT : T_ANY;*/ - $$.type = T_INT; + $$.type = $1 ? T_INT : T_ANY; +/* $$.type = T_INT;*/ add_two_tokens(F_PUSH_INT, $1); } | defined_name /* This should not be a constant. */ @@ -582,12 +583,15 @@ if(!dont_add_pop) { num = num_locals_pushed; num += block_history[scope_level - 1]; - if(num) + if(num == 1) + add_token(F_POP); + else if(num > 1) add_two_tokens(F_POP_N, num); } else dont_add_pop = 0; num_locals_pushed = 0; + block_history[scope_level-1] = 0; /* XXX */ pop_scope(); } ; @@ -719,7 +723,7 @@ char *buf; buf = xmalloc(strlen($1) + 51); sprintf(buf, "warning: declaration of %s shadows function argument", $1); - display_error(buf); + do_error(buf); free(buf); compile_warnings++; } else if(id->type == ID_DFUN) { @@ -855,7 +859,7 @@ if($2.type) { comp_error("return from a void function with a value"); } - } else if($2.type != curr_fun_type) { + } else if($2.type != curr_fun_type && $2.type != T_ANY) { comp_error("improper return type"); } @@ -1047,6 +1051,7 @@ int i; char *buf; def_id_t *idp; + int type_mods; $$.side_effect = 1; $$.direct_type = 0; @@ -1055,39 +1060,43 @@ break; $$.type = $1->lpc_type; + type_mods = $$.type & MOD_ALL; + $$.type &= ~MOD_ALL; - if($3.len > $1->num_arg) { - buf = xmalloc(strlen($1->name) + 23); - sprintf(buf, "too many arguments to %s", $1->name); - comp_error(buf); - free(buf); - goto clean_up; - } else if($3.len < $1->num_arg) { - buf = xmalloc(strlen($1->name) + 22); - sprintf(buf, "too few arguments to %s", $1->name); - comp_error(buf); - free(buf); - goto clean_up; - } else { - for(i=0;i<$1->num_arg;i++) { - if(($1->args[i] == T_ARRAY && ($3.data[i] & T_ARRAY)) || - ($3.data[i] == T_ARRAY && ($1->args[i] & T_ARRAY))) - continue; + if(!(type_mods & MOD_VARARGS)) { + if($3.len > $1->num_arg) { + buf = xmalloc(strlen($1->name) + 23); + sprintf(buf, "too many arguments to %s", $1->name); + comp_error(buf); + free(buf); + goto clean_up; + } else if($3.len < $1->num_arg) { + buf = xmalloc(strlen($1->name) + 22); + sprintf(buf, "too few arguments to %s", $1->name); + comp_error(buf); + free(buf); + goto clean_up; + } + } + + for(i=0;i</*$1->num_arg*/$3.len;i++) { + if(($1->args[i] == T_ARRAY && ($3.data[i] & T_ARRAY)) || + ($3.data[i] == T_ARRAY && ($1->args[i] & T_ARRAY))) + continue; - if($1->args[i] != T_ANY && $3.data[i] != T_ANY - && $1->args[i] != $3.data[i]) { - char *ts1, *ts2; + if($1->args[i] != T_ANY && $3.data[i] != T_ANY + && $1->args[i] != $3.data[i]) { + char *ts1, *ts2; - ts1 = type2str($1->args[i]); - ts2 = type2str($3.data[i]); - buf = xmalloc(strlen($1->name) + strlen(ts1) + strlen(ts2) + 64); - sprintf(buf, "argument %d type mismatch for %s - expected %s, got %s", - i+1, $1->name, ts1, ts2); - comp_error(buf); - free(buf); - goto clean_up; - break; - } + ts1 = type2str($1->args[i]); + ts2 = type2str($3.data[i]); + buf = xmalloc(strlen($1->name) + strlen(ts1) + strlen(ts2) + 64); + sprintf(buf, "argument %d type mismatch for %s - expected %s, got %s", + i+1, $1->name, ts1, ts2); + comp_error(buf); + free(buf); + goto clean_up; + break; } } @@ -1204,7 +1213,7 @@ result->lval = 0; - if(left->type && type2 && left->type != type2) { + if(left->type && type2 && left->type != type2 && type2 != T_ANY) { comp_error("type mismatch"); } check_operand(op, left->type, type2); |
|
From: Peep P. <so...@us...> - 2004-07-24 17:53:45
|
Update of /cvsroot/agd/server/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31568 Modified Files: lpc.h Log Message: Type modifiers. Index: lpc.h =================================================================== RCS file: /cvsroot/agd/server/src/lpc.h,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- lpc.h 21 Jul 2004 11:57:57 -0000 1.12 +++ lpc.h 24 Jul 2004 17:53:36 -0000 1.13 @@ -6,25 +6,23 @@ /* Each one of these types can be an array. We use the highest bit (1000 0000) to indicate an array, so make sure to never - go over 0x80 with normal data types. */ + go over 0x7F with normal data types. */ #define T_INT 0x01 #define T_STRING 0x02 #define T_VOID 0x03 #define T_OBJECT 0x04 #define T_MIXED 0x05 -#define T_ANY 0x06 - -/* Used by interpret.c. I'd rather not have it here, - but as it also needs an union member, it would be - too cluttered otherwise. */ +#define T_ANY 0x08 #define T_LVALUE 0x10 - /* Used by F_INDEX_LVALUE. */ #define T_CHAR_PTR 0x20 - #define T_ARRAY 0x80 +/* type modifiers */ +#define MOD_VARARGS 0x100 +#define MOD_ALL 0x100 + /* string_types */ #define ST_MALLOC 1 #define ST_STATIC 2 |
|
From: Peep P. <so...@us...> - 2004-07-24 17:53:25
|
Update of /cvsroot/agd/server/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31519 Modified Files: main.c Log Message: preloading objects; crash() doesn't take sig argument Index: main.c =================================================================== RCS file: /cvsroot/agd/server/src/main.c,v retrieving revision 1.23 retrieving revision 1.24 diff -u -d -r1.23 -r1.24 --- main.c 23 Jul 2004 17:07:59 -0000 1.23 +++ main.c 24 Jul 2004 17:53:16 -0000 1.24 @@ -30,6 +30,9 @@ #include "list.h" #include "lpc.h" #include "object.h" +#include "net.h" +#include "interpret.h" +#include "array.h" extern object_t *master; static char *conf_file; @@ -39,13 +42,13 @@ { switch(num) { case SIGINT: - crash(SIGINT, "Interrupted", 4); + crash("Interrupted", 4); break; case SIGSEGV: - crash(SIGSEGV, "Segmentation fault", 4); + crash("Segmentation fault", 4); break; case SIGPIPE: - crash(SIGPIPE, "Broken pipe", 4); + crash("Broken pipe", 4); break; } } @@ -64,7 +67,7 @@ signal(SIGPIPE, SIG_IGN); } -void crash(int sig, char *reason, int retval) +void crash(char *reason, int retval) { extern variable_t *fp, *sp; @@ -72,14 +75,15 @@ stop_signals(); if(master) { - int ret; + variable_t *ret; fp = sp; - ret = apply(master, "crash", "is", sig, reason); + ret = apply(master, "crash", "s", reason); if(!ret) fprintf(stderr, "master::crash() failed.\n"); else fprintf(stderr, "master::crash() called successfully.\n"); } + exit(retval); } @@ -88,7 +92,7 @@ printf("Usage: %s [options] <configuration file>\n", s); printf("Options:\n" "\t-d: Increase debug level\n" - "\t-f<text>: pass flag to master object\n" + "\t-f<text>: pass flag to master object\n" "\t-? or -h: Show this text\n" "\t-v: Show version and quit\n"); exit(5); @@ -123,6 +127,24 @@ } } +void do_preload(void) +{ + variable_t *tmpv; + array_t *arr; + int i; + + tmpv = apply(master, "preload_list", ""); + if(!tmpv || !tmpv->u.a || !tmpv->u.a->length) + return; + + arr = tmpv->u.a; + for(i=0;i<arr->length;i++) { + tmpv = &arr->data[i]; + if(tmpv->type == T_STRING && tmpv->u.s) + apply(master, "preload", "s", tmpv->u.s); + } +} + #define NEXTARG() { i++; if(i<argc) goto next_i; else return; } void parse_args(int argc, char **argv) { @@ -223,10 +245,11 @@ master = load_object(conf.master); if(!master) - crash(0, "Master object doesn't load", 3); -/* master->numref++; Is this really necessary? */ + crash("Master object doesn't load", 3); + master->numref++; do_flag(NULL); /* Apply flags. */ + do_preload(); net_listen(conf.port); |
|
From: Peep P. <so...@us...> - 2004-07-24 17:51:35
|
Update of /cvsroot/agd/server/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31282 Modified Files: net.h net.c Log Message: The add_command() system. Index: net.c =================================================================== RCS file: /cvsroot/agd/server/src/net.c,v retrieving revision 1.20 retrieving revision 1.21 diff -u -d -r1.20 -r1.21 --- net.c 23 Jul 2004 17:06:43 -0000 1.20 +++ net.c 24 Jul 2004 17:51:25 -0000 1.21 @@ -95,8 +95,6 @@ if(p->conn.socket > greatest_sockfd) greatest_sockfd = p->conn.socket; -/* p->conn.state = DEFAULT;*/ - this_player = p; player_ob = xmalloc(sizeof(object_t)); player_ob->iaob = p; @@ -107,7 +105,7 @@ login_ob = apply(master, "connect", NULL); if(!login_ob || login_ob->type != T_OBJECT) - crash(0, "master::connect() is not working", 3); + crash("master::connect() is not working", 3); if(!login_ob->u.ob) { fprintf(stderr, "Warning: master::connect() didn't return an object.\n"); @@ -157,18 +155,63 @@ send(p->conn.socket, buf, siz, 0); } -void net_read(player_t *p) +void do_command(player_t *p, char *str) { - char *c; + char *verb, *c; + int len, i; + int found_cmd; + variable_t *ret; + + if(!p || !str) + return; + + ret = apply(p->ob, "process_input", "s", str); + if(ret && ret->type == T_INT && ret->u.i) { + /* Don't do any further processing. */ + return; + } - if(!p->input_to) { + c = strchr(str, ' '); + if(c) + len = c - str + 1; + else + len = strlen(str) + 1; + + verb = xmalloc(len + 1); + strncpy(verb, str, len); + verb[len - 1] = '\0'; + #ifdef DEBUG - if(conf.debuglevel) - printf("[net] player %p (with iaob %s) doesn't have input_to set\n", p->ob? p->ob->name :NULL, p); + if(conf.debuglevel) { + printf("verb: %s", verb); + if(c) + printf("; args: %s\n", c+1); + putchar('\n'); + } #endif - goto out; + + found_cmd = 0; + for(i=0;i<p->num_cmd;i++) { + command_t *cmd = &p->cmds[i]; + if(strcmp(cmd->verb, verb) == 0) { + found_cmd = 1; + p->this_verb = i + 1; + if(c) + apply(p->ob, cmd->fun, "s", c+1); + else + apply(p->ob, cmd->fun, ""); + } } + if(!found_cmd) { + net_send("What?\n", 7, p); + } +} + +void net_read(player_t *p) +{ + char *c; + if(!p->ob) { net_send("Oops, looks like you don't have an interactive object!\n", 55, p); net_disconnect(p); @@ -176,14 +219,17 @@ } c = strchr(p->conn.recvbuf, '\r'); - if(c) { - *c = '\0'; - } else if(c = strchr(p->conn.recvbuf, '\n')) + if(c || (c = strchr(p->conn.recvbuf, '\n'))) *c = '\0'; - p->input_to_called = 1; - apply(p->ob, p->input_to, "s", p->conn.recvbuf); - if(p->input_to_called) { /* input_to wasn't called again */ - p->input_to = NULL; + + if(p->input_to) { + p->input_to_called = 1; + apply(p->ob, p->input_to, "s", p->conn.recvbuf); + if(p->input_to_called) { /* input_to wasn't called again */ + p->input_to = NULL; + } + } else { + do_command(p, p->conn.recvbuf); } /* The previous apply() might have destructed p->ob */ @@ -200,11 +246,11 @@ switch(ret) { case -1: fprintf(stderr, "Error reading from player!\n"); - /* fall through, and make them netdead */ + /* Fall through, and make them netdead. */ case 0: apply(pl->ob, "net_dead", "o", pl->ob); if(pl->ob) { - /* the login object will have to restore this object's iaob */ + /* The login object will have to restore this object's iaob. */ pl->ob->iaob = NULL; } net_disconnect(pl); @@ -234,6 +280,7 @@ p->data = NULL; } + list_remove(&to_be_dested, ob); actual_destruct(ob); } } Index: net.h =================================================================== RCS file: /cvsroot/agd/server/src/net.h,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- net.h 8 Jun 2004 20:44:53 -0000 1.12 +++ net.h 24 Jul 2004 17:51:25 -0000 1.13 @@ -27,12 +27,19 @@ time_t last_active; } player_connection_t; +typedef struct { + char *verb, *fun; +} command_t; + typedef struct player { player_connection_t conn; object_t *ob; char *input_to; int input_to_called; + + command_t *cmds; + int num_cmd, this_verb; } player_t; void net_loop(void); |
|
From: Peep P. <so...@us...> - 2004-07-24 17:50:40
|
Update of /cvsroot/agd/server/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31140 Modified Files: object.c Log Message: apply_create() Index: object.c =================================================================== RCS file: /cvsroot/agd/server/src/object.c,v retrieving revision 1.19 retrieving revision 1.20 diff -u -d -r1.19 -r1.20 --- object.c 23 Jul 2004 17:06:43 -0000 1.19 +++ object.c 24 Jul 2004 17:50:31 -0000 1.20 @@ -20,6 +20,8 @@ player_t *this_player; object_t *this_ob, *previous_ob; +int doing_load; + extern program_t *compile_prog(char *path); void free_fun(void *p) @@ -52,7 +54,12 @@ for(p=&ob->refs;p->next;p=p->next) { variable_t *v = p->data; - v->u.ob = NULL; + if(v->u.ob == ob) + v->u.ob = NULL; + else { + if(conf.debuglevel) + printf("object's ref is not to object!\n"); + } } list_remove(&all_objects, ob); @@ -102,8 +109,11 @@ list_remove(&ob->refs, v); ob->numref--; if(ob->numref <= 0) { + /* Here we swap them out. */ +#if 0 printf("refs for %s = 0\n", ob->name); destruct(ob); +#endif } } @@ -160,6 +170,21 @@ return NULL; } +void apply_create(object_t **ob, int already_in) +{ + doing_load = 1; + apply(*ob, "create", NULL); + if(doing_load) { + doing_load = 0; + } else { + /* A runtime error happened in create(). */ + if(already_in) + list_remove(&all_objects, *ob); + free(*ob); + *ob = NULL; + } +} + object_t *load_object(char *path) { object_t *ob, @@ -167,10 +192,12 @@ *saved_prev_ob; player_t *saved_tp; +#if 0 if(!legal_path(path)) { printf("load_object(): illegal path name \"%s\"!\n", path); return NULL; } +#endif saved_this_ob = this_ob; saved_prev_ob = previous_ob; @@ -193,7 +220,8 @@ saved_tp = this_player; this_player = NULL; - apply(ob, "create", NULL); + doing_load = 1; + apply_create(&ob, 1); goto out; } } @@ -212,11 +240,11 @@ goto out; } - list_push(&all_objects, ob); - saved_tp = this_player; this_player = NULL; - apply(ob, "create", NULL); + apply_create(&ob, 0); + if(ob) + list_push(&all_objects, ob); out: this_player = saved_tp; @@ -249,7 +277,8 @@ ref_prog(new_ob->prog); new_ob->numglobals = base_ob->numglobals; - new_ob->globals = xmalloc(sizeof(variable_t) * new_ob->numglobals); + if(new_ob->numglobals) + new_ob->globals = xmalloc(sizeof(variable_t) * new_ob->numglobals); for(i=0;i<new_ob->numglobals;i++) { variable_t *v = &new_ob->globals[i]; *v = base_ob->globals[i]; @@ -257,9 +286,9 @@ v->name = xstrdup(v->name); } - apply(new_ob, "create", NULL); - list_push(&all_objects, new_ob); - + apply_create(&new_ob, 0); + if(new_ob) + list_push(&all_objects, new_ob); return new_ob; } |
|
From: Peep P. <so...@us...> - 2004-07-24 17:50:18
|
Update of /cvsroot/agd/server/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31057 Modified Files: object.h Log Message: MOD_VARARGS define Index: object.h =================================================================== RCS file: /cvsroot/agd/server/src/object.h,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- object.h 21 Jul 2004 11:55:58 -0000 1.11 +++ object.h 24 Jul 2004 17:50:03 -0000 1.12 @@ -1,6 +1,9 @@ #ifndef _OBJECT_H #define _OBJECT_H +/* 0x80 is for T_ARRAY */ +#define MOD_VARARGS 0x100 + typedef struct { int type; @@ -10,7 +13,7 @@ int *code; int codelen; - unsigned int lineno; +/* unsigned int lineno;*/ unsigned *line_numbers; } function_t; |
|
From: Peep P. <so...@us...> - 2004-07-24 17:49:45
|
Update of /cvsroot/agd/server/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30935 Modified Files: sys.h Log Message: Defines for exit codes. Index: sys.h =================================================================== RCS file: /cvsroot/agd/server/src/sys.h,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- sys.h 23 Jul 2004 17:05:40 -0000 1.12 +++ sys.h 24 Jul 2004 17:49:36 -0000 1.13 @@ -22,6 +22,14 @@ char *add_extension(char *str); char *absolute_path(char *path); -void crash(int sig, char *reason, int retval); +void crash(char *reason, int retval); + +#define EXIT_DONTBOTHER -1 +#define EXIT_NORMAL 0 +#define EXIT_OUTOFMEM 1 +#define EXIT_NETERR 2 +#define EXIT_LPCERR 3 +#define EXIT_DUESIGNAL 4 +#define EXIT_CONFERR 5 #endif |
|
From: Peep P. <so...@us...> - 2004-07-24 17:49:30
|
Update of /cvsroot/agd/server/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30902 Modified Files: sys.c Log Message: add_slash() Index: sys.c =================================================================== RCS file: /cvsroot/agd/server/src/sys.c,v retrieving revision 1.19 retrieving revision 1.20 diff -u -d -r1.19 -r1.20 --- sys.c 23 Jul 2004 17:05:40 -0000 1.19 +++ sys.c 24 Jul 2004 17:49:21 -0000 1.20 @@ -56,7 +56,13 @@ } if(strncmp(buf, "lib:", 4) == 0) { + int len; fscanf(f, "%s\n", buf); + len = strlen(buf); + if(buf[len-1] != '/') { + buf[len] = '/'; + buf[len+1] = '\0'; + } conf.lib_root = xstrdup(buf); continue; } @@ -110,13 +116,6 @@ return p; } -int legal_path(char *fn) -{ - char *p; - p = strstr(fn, ".."); - return !p; -} - /* strdup() isn't ANSI, so we need this replacement. */ char *xstrdup(char *s) { @@ -125,6 +124,15 @@ return p; } +int legal_path(char *fn) +{ + char *p; + p = strstr(fn, ".."); + if(p) + return 0; + return 1; +} + /* This makes a copy of str, and adds ".lpc" to the end. */ char *add_extension(char *str) { @@ -149,6 +157,17 @@ return s; } +void add_slash(char *path) +{ + int len; + len = strlen(path); + if(path[len-1] != '/') { + path = xrealloc(path, len + 2); + path[len] = '/'; + path[len+1] = '\0'; + } +} + int to_power(int base, int pow) { int i, ret; |
|
From: Peep P. <so...@us...> - 2004-07-24 17:49:16
|
Update of /cvsroot/agd/server/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30796 Modified Files: vars.c vars.h Log Message: slice_var(); adding of arrays moved to array.c Index: vars.c =================================================================== RCS file: /cvsroot/agd/server/src/vars.c,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- vars.c 23 Jul 2004 17:04:36 -0000 1.17 +++ vars.c 24 Jul 2004 17:49:04 -0000 1.18 @@ -53,13 +53,18 @@ int test_var(variable_t *v) { - switch(v->type) { + if(v->type & T_ARRAY) { + return v->u.a?1:0; + } else switch(v->type) { case T_INT: return v->u.i?1:0; case T_STRING: return v->u.s && strlen(v->u.s); case T_OBJECT: return v->u.ob?1:0; + case T_VOID: + printf("test_var() on T_VOID\n"); + return 0; default: printf("test_var(): unknown datatype %d, returning false\n", v->type); return 0; @@ -141,20 +146,8 @@ #endif if(v1->type & T_ARRAY && v2->type & T_ARRAY) { - int i; ret->type = v1->type; - ret->u.a = xmalloc(sizeof(array_t)); - ret->u.a->ref = 1; - ret->u.a->length = v1->u.a->length + v2->u.a->length; - ret->u.a->data = xmalloc(sizeof(variable_t) * ret->u.a->length); - - for(i=0;i<ret->u.a->length;i++) { - /* use do_assign? */ - if(i < v1->u.a->length) - ret->u.a->data[i] = v1->u.a->data[i]; - else - ret->u.a->data[i] = v2->u.a->data[i - v1->u.a->length]; - } + ret->u.a = add_arrays(v1->u.a, v2->u.a); return ret; } @@ -271,6 +264,36 @@ return ret; } +variable_t *slice_var(variable_t *var, int i1, int i2) +{ + int i; + variable_t *ret; + + ret = xmalloc(sizeof(variable_t)); + + if(var->type & T_ARRAY) { + array_t *arr; + ret->type = var->type; + ret->u.a = xmalloc(sizeof(array_t)); + arr = ret->u.a; + arr->length = i2 - i1 + 1; + arr->data = xmalloc(arr->length * sizeof(variable_t)); + for(i=i1;i<=i2;i++) { + do_assign(&arr->data[i-i1], &var->u.a->data[i]); + } + } else { + char *s; + + ret->type = T_STRING; + s = xmalloc(i2 - i1 + 2); + for(i=i1;i<=i2;i++) + s[i-i1] = var->u.s[i]; + s[i2 - i1 + 1] = '\0'; + ret->u.s = s; + } + return ret; +} + char *type2str(int t) { if(t & T_ARRAY) { @@ -285,6 +308,8 @@ return "array of object"; case T_LVALUE: return "array of lvalue"; + case 0: + return "array"; default: return "array of unknown"; } Index: vars.h =================================================================== RCS file: /cvsroot/agd/server/src/vars.h,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- vars.h 23 Jul 2004 17:03:56 -0000 1.10 +++ vars.h 24 Jul 2004 17:49:04 -0000 1.11 @@ -9,6 +9,7 @@ variable_t *add_vars(variable_t *v1, variable_t *v2); variable_t *sub_vars(variable_t *v1, variable_t *v2); variable_t *band_vars(variable_t *v1, variable_t *v2); +variable_t *slice_var(variable_t *v1, int i1, int i2); char *type2str(int t); #endif |
|
From: Peep P. <so...@us...> - 2004-07-23 17:23:29
|
Update of /cvsroot/agd/server In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16758 Modified Files: NEWS Log Message: Bing, changes again Index: NEWS =================================================================== RCS file: /cvsroot/agd/server/NEWS,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- NEWS 21 Jul 2004 12:13:09 -0000 1.13 +++ NEWS 23 Jul 2004 17:23:20 -0000 1.14 @@ -4,7 +4,8 @@ * Locals can now be defined in the middle of code. * dfun platform() changed to a preprocessor macro __ARCH__, version() to __VERSION__. - * New dfuns: throw(), users() + * New dfuns: throw(), users(), sizeof() + * Bitwise operators Features in 0.0.2-3: * Real string ranges like string[0..4] |
|
From: Peep P. <so...@us...> - 2004-07-23 17:22:16
|
Update of /cvsroot/agd/server/doc/lpc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16586 Modified Files: operators Log Message: Cleanup; bitwise operators Index: operators =================================================================== RCS file: /cvsroot/agd/server/doc/lpc/operators,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- operators 1 Apr 2004 19:07:19 -0000 1.6 +++ operators 23 Jul 2004 17:22:07 -0000 1.7 @@ -1,61 +1,60 @@ Operators of the LPC language. -Star (*) marks that it's implemented in AGD. +Star (*) marks that it's NOT implemented in AGD. with side effects: - = binary assign * (F_ASSIGN) - -- unary decrement * (F_POSTDEC, F_PREDEC) - ++ unary increment * (F_POSTINC, F_PREINC) + = binary assign + -- unary decrement + ++ unary increment ('a x= b' is equal to 'a = a x b') - += binary self-increment * - -= binary self-decrement * - /= binary self-division * - *= binary self-multiplication * - %= binary self-modulo * - **= binary self-power * + += binary self-increment + -= binary self-decrement + /= binary self-division + *= binary self-multiplication + %= binary self-modulo + **= binary self-power comparison: - == binary equal * (F_EQ) - > binary greater than * (F_GT) - < binary less than * (F_LT) - <= binary less or equal than * (F_LE) - >= binary greater or equal than * (F_GE) - != binary not equal * (F_NE) + == binary equal + > binary greater than + < binary less than + <= binary less or equal than + >= binary greater or equal than + != binary not equal logic: - && binary AND * - || binary OR * - ! unary NOT * (F_NOT) + && binary AND + || binary OR + ! unary NOT misc: - -> binary call_other * (F_CALL_OTHER) - note: This is different from C's ->. - in LPC it calls a function in an object other than - the current object; i.e. ob->call() would execute - the function call() in object ob. - ?: trinary conditional (if-then-else) * + -> binary call_other + ?: trinary conditional (if-then-else) , binary comma - left and right side are evaluated, - then right side discarded. - [] * (F_SLICE and F_INDEX) + then right side discarded. * + [] arithmetic: - + binary addition * (F_ADD) - - binary substraction *(F_SUB) - - unary negation *(F_NEG) - / binary division *(F_DIV) - * binary multiplication *(F_MUL) - % binary modulo * (F_MOD) - ** binary power * + + binary addition + - binary substraction + - unary negation + / binary division + * binary multiplication + % binary modulo + ** binary power - binary: - & - | - ~ - ^ - << - >> + array operators: + & binary intersection * - &= - |= - ~= - ^= - <<= - >>= + bitwise operators: + & binary AND + | binary OR + ~ binary NOT + ^ binary XOT + << binary shift left + >> binary shift right + + &= binary self-AND + |= binary self-OR + ~= binary self-NOT + ^= binary self-XOR + <<= binary self-shift left + >>= binary self-shift right |