From: Peep P. <so...@us...> - 2004-03-18 20:58:36
|
Update of /cvsroot/agd/server/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2355 Modified Files: compile.c Log Message: Cleanups, fixes. Index: compile.c =================================================================== RCS file: /cvsroot/agd/server/src/compile.c,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- compile.c 15 Mar 2004 18:46:59 -0000 1.12 +++ compile.c 18 Mar 2004 20:48:52 -0000 1.13 @@ -15,13 +15,13 @@ numdfuns, numlfuns; array_t local_ids, global_ids; -static int locals_level; +/*static int locals_level;*/ static array_t *curr_block; static array_t block_history; -#ifdef YYDEBUG +/*#ifdef YYDEBUG*/ extern int yydebug; -#endif +/*#endif*/ static int start_with_newline; @@ -111,10 +111,12 @@ /* free_id(id);*/ numlvars--; array_remove(&local_ids, i); + i--; /* Element was removed, so don't increase index. */ } else if(id->type == ID_GVAR && id->base_scope > scope_level) { /* free_id(id);*/ numgvars--; array_remove(&local_ids, i); + i--; } } } @@ -127,8 +129,7 @@ int both_same_type; /* For binary operators - must both operands be of the same type? */ } operator_t; -#define NUM_OPERATORS F_PREDEC - F_SUB -static operator_t operator_table[NUM_OPERATORS]; +static operator_t operator_table[F_HIGHEST-F_ADD]; #define SET_OPERATOR(op_name, num, bothsame, int_valid, str_valid, ob_valid) \ operator_table[i].name = op_name;\ @@ -141,7 +142,7 @@ void generate_operator_table(void) { int i; - for(i=0;i<NUM_OPERATORS;i++) { + for(i=0;i<=F_HIGHEST;i++) { /* 4 - T_INT, T_STRING, T_VOID(unused), T_OBJECT */ switch(i + F_ADD) { case F_ADD: SET_OPERATOR("+", 2, 0, 1, 1, 0); break; @@ -173,6 +174,8 @@ case F_NE: SET_OPERATOR("!=", 2, 1, 1, 1, 1); break; case F_AND: SET_OPERATOR("&&", 2, 0, 1, 1, 1); break; case F_OR: SET_OPERATOR("||", 2, 0, 1, 1, 1); break; + + case F_RANGE: SET_OPERATOR("[]", 1, 0, 0, 1, 0); break; } } } @@ -194,6 +197,8 @@ if(!opr1) return; + memset(buf, 0, sizeof buf); + op = &operator_table[operator-F_ADD]; if(op->valid[opr1-1] == 0 || (op->num_operand == 2 && opr2 @@ -208,6 +213,9 @@ case 3: sprintf(buf, "invalid operands to trinary "); break; + default: + sprintf(buf, "KALA\n"); + break; } sprintf(buf, "%s%s", buf, op->name); comp_error(buf); @@ -301,33 +309,13 @@ curr_f = NULL; } -#if 0 - if((index = nametable_find(TYPE_FUN | SCOPE_LOCAL, name, &cob->prog->nametable)) > -1) { - /* The function already exists - we're giving a definition for a declaration. */ - if(index >= fun_has_definition.allocated) - array_push(&fun_has_definition, (void *) index); - fun_has_definition.data[index] = (void *) 1; - fun_has_definition.length = index + 1; - cob->prog->functions.data[index] = curr_f; - } else { - array_push(&cob->prog->functions, curr_f); - nametable_add(TYPE_FUN | SCOPE_LOCAL, name, - cob->prog->functions.length-1, &cob->prog->nametable); - nametable_sort(&cob->prog->nametable); - } -#endif } void add_variable(array_t *vars, int type) { int i, numvars, num; -/* int global;*/ array_t *target; -/* global = scope & SCOPE_GLOBAL; - target = global ? &cob->prog->nametable : &temp_nametable; - numvars = target->length;*/ - for(i=0;i<vars->length;i++) { variable_t *var = vars->data[i]; array_t *assign = NULL; @@ -345,7 +333,7 @@ init_var(var); if(type == ID_GVAR) { - array_push(&cob/*->prog*/->variables, var); + array_push(&cob->variables, var); } else /* LVAR */{ switch(var->type) { case T_INT: @@ -365,14 +353,6 @@ } } -#if 0 - num = find_variable(var->name); - if(num == -1) - num = numvars++; - nametable_add(TYPE_VAR | scope, var->name, num, target); - define_name(TYPE_VAR | scope, var->name, var->type, NULL, 0); - nametable_sort(target); -#endif define_id(var->name, type, var->type, NULL); /* Only for locals right now. But watch out! */ @@ -380,9 +360,7 @@ def_id_t *id; /* Could use numlocals, since we just defined it. */ id = find_id(var->name); -/* int index; - index = nametable_find(TYPE_VAR | SCOPE_LOCAL, var->name, &temp_nametable);*/ - array_push(curr_block, (void *) F_PUSH_LVAR); + array_push(curr_block, (void *) F_PUSH_LVAR_LVALUE); array_push(curr_block, (void *) id->index); array_concat(curr_block, assign); array_push(curr_block, (void *) F_ASSIGN); @@ -399,8 +377,8 @@ init_array(curr_block); /* if(!locals_level) { free_array(&temp_variables, (void (*)(void*))free_var); - }*/ - locals_level++; + } + locals_level++;*/ } array_t add_block(array_t *stmt) @@ -416,31 +394,13 @@ { pop_scope(); curr_block = array_pop(&block_history); - if(locals_level > 0) +/* if(locals_level > 0) locals_level--; -/* if(!locals_level) { + if(!locals_level) { free_array(&temp_nametable, (void (*)(void*))free_ntentry NULL); }*/ } -#if 0 -/* This generates a table for function name lookups. */ -void generate_fun_table(void) -{ - int i; - init_array(&cob->prog->fun_table); - for(i=0;i<local_ids.length;i++) { - id_t *id = local_ids.data[i]; - printf("id: %s type %d index %d\n", id->name, id->type, id->index); - if(id->type == ID_FUN) { - array_push(&cob->prog->fun_table, id->name); - array_push(&cob->prog->fun_table, (void *) id->index); - printf("pushed\n"); - } - } -} -#endif - int compare_args(array_t *arg1, array_t *arg2) { int i; @@ -483,16 +443,17 @@ /* This does the actual formatting. */ void display_error(char *s) { - char *buf; +/* char *buf;*/ if(start_with_newline) { - do_write("\n"); +/* do_write("\n");*/ + putchar('\n'); start_with_newline = 0; } - buf = xmalloc(strlen(s) + 256); - sprintf(buf, "%s:%d:%d: %s\n", curr_fn, yylloc.line, yylloc.pos, s); - do_write(buf); - xfree(buf); +/* buf = xmalloc(strlen(s) + 256); + s*/printf(/*buf, */"%s:%d:%d: %s\n", curr_fn, yylloc.line, yylloc.pos, s); +/* do_write(buf); + xfree(buf);*/ } /* This is the function called by bison, probably with the argument "parse error" @@ -513,7 +474,7 @@ init_array(&cob->prog->functions); init_array(&cob->prog->fun_table); - init_array(&cob/*->prog*/->variables); + init_array(&cob->variables); numlvars = numgvars = 0; numdfuns = numlfuns = 0; @@ -550,9 +511,8 @@ return 0; } -/*#define FREE_LOCALS() xfree(file_name); xfree(ob->name); xfree(ob)*/ #define END_COMPILE() cob = NULL; start_with_newline = 0; actual_destruct(ob); xfree(file_name); return NULL -object_t *int_load_object(char *fn) +object_t *load_object(char *fn) { char *file_name, *our_fn; object_t *ob; @@ -592,12 +552,6 @@ start_with_newline = 1; -#if 0 - if(!dir_exists(file_name, 0)) { - printf("failed (dir doesn't exist)\n"); - END_COMPILE(); - } -#endif if(access(file_name, R_OK)) { printf("failed (file not accessable)\n"); END_COMPILE(); @@ -614,9 +568,10 @@ parse_init(); curr_fn = ob->name; -#if defined(DEBUG) && defined(YYDEBUG) - if(conf.debuglevel > 3) +#if defined(DEBUG)/* && defined(YYDEBUG)*/ + if(conf.debuglevel > 4) { yydebug = 1; + } #endif if(yyparse() > 0 || compile_errors) { @@ -629,16 +584,12 @@ } printf(" - failed\n"); END_COMPILE(); -/* FREE_LOCALS();*/ } if(check_fun_definitions()) { END_COMPILE(); } -/* generate_fun_table();*/ - - /*nametable_sort(&cob->prog->nametable);*/ ref_prog(ob->prog); list_push(&all_objects, ob); |