From: Peep P. <so...@us...> - 2004-06-14 20:56:49
|
Update of /cvsroot/agd/server/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22107 Modified Files: lang.y Log Message: Fixed F_INDEX and F_INDEX_LVALUE; removed xfree; removed commented code Index: lang.y =================================================================== RCS file: /cvsroot/agd/server/src/lang.y,v retrieving revision 1.21 retrieving revision 1.22 diff -u -d -r1.21 -r1.22 --- lang.y 12 Jun 2004 20:51:40 -0000 1.21 +++ lang.y 14 Jun 2004 20:56:38 -0000 1.22 @@ -41,6 +41,7 @@ void do_inc_expr(expr_t *result, expr_t *expr, int op); int add_string_to_table(char *s); +void make_lvalue(int index); %} @@ -108,7 +109,8 @@ %type <expr> optional_expr expr_list expr_list2 %type <expr> assign_expr arith_expr compare_expr inc_expr %type <expr> neg_expr not_expr and_expr or_expr trinary_expr -%type <expr> constant index_expr +%type <expr> constant +%type <expr> expr_open_bracket index_expr %type <expr> fun_call call_other %type <i> block_or_semi @@ -153,7 +155,7 @@ sprintf(buf, "warning: return type defaults to %s", type2str(DEFAULT_FUNCTION_TYPE)); display_error(buf); compile_warnings++; - xfree(buf); + free(buf); } $<id>$ = idp = find_id($2); @@ -186,7 +188,7 @@ char *buf = xmalloc(strlen($2) + 42 /* ;) */); sprintf(buf, "definition doesn't match declaration for %s", $2); comp_error(buf); - xfree(buf); + free(buf); } idp->type = ID_FUN; @@ -224,7 +226,7 @@ char *buf = xmalloc(strlen($2) + 64); sprintf(buf, "warning: repeated prototype for %s; using existing prototype", $2); display_error(buf); - xfree(buf); + free(buf); compile_warnings++; } else { add_function(idp, $<i>7/*, NULL*/); @@ -465,22 +467,30 @@ } ; +expr_open_bracket: + expr '[' + { + $$ = $1; + make_lvalue(curr_fun->codelen - 2); + } + ; + index_expr: /* XXX - first expr must be indexable */ - expr '[' expr ']' + expr_open_bracket expr ']' { - $$.side_effect = $1.side_effect || $3.side_effect; + $$.side_effect = $1.side_effect || $2.side_effect; $$.direct_type = 0; $$.lval = 1; - if($3.type != T_INT && $3.type != T_ANY) { + if($2.type != T_INT && $2.type != T_ANY) { comp_error("index must be integer"); } $$.type = T_INT; add_token(F_INDEX); } - | expr '[' expr L_RANGE expr ']' + | expr_open_bracket expr L_RANGE expr ']' { - $$.side_effect = $1.side_effect || $3.side_effect || $5.side_effect; + $$.side_effect = $1.side_effect || $2.side_effect || $4.side_effect; $$.direct_type = 0; $$.lval = 1; $$.type = T_STRING; @@ -587,8 +597,8 @@ buf = xmalloc(strlen($1) + 25); sprintf(buf, "undeclared identifier '%s'", $1); comp_error(buf); - xfree(buf); - xfree($1); /* WATCH OUT */ + free(buf); + free($1); /* WATCH OUT */ } } ; @@ -620,14 +630,7 @@ statements: /* empty */ - {/* $$ = num_locals_pushed = malloc(sizeof(int)); - *num_locals_pushed = 0; - printf("empty statements. num_locals_pushed: %p (value = %d)\n", num_locals_pushed, *num_locals_pushed);*/ - } - | statements { -/* $$ = $1; - printf("statements and another statement reached. num_locals_pushed: %p (value=%d); $$: %p\n", num_locals_pushed, *num_locals_pushed, $$);*/ - } statement + | statements statement ; arguments: @@ -681,7 +684,7 @@ } $$ = $1; - xfree($2); + free($2); } ; @@ -696,7 +699,7 @@ buf = xmalloc(strlen($1) + 51); sprintf(buf, "warning: declaration of %s shadows function argument", $1); display_error(buf); - xfree(buf); + free(buf); compile_warnings++; } else if(id->type == ID_DFUN) { redeclaration_error(id, ID_LVAR); @@ -769,6 +772,9 @@ string_con2: L_STRING + { + $$ = $1; + } | string_con2 L_STRING { $$ = xmalloc(strlen($1) + strlen($2) + 1); @@ -850,15 +856,6 @@ { add_two_tokens(F_JUMP_IF_FALSE, 3); add_two_tokens(F_JUMP, $<i>2 - curr_fun->codelen - 1); -/* init_array(&$$); - array_push(&$$, (void *) F_JMP); - array_push(&$$, (void *) ($6.arr.length + 3)); - array_concat(&$$, &$6.arr); - array_push(&$$, (void *) F_JMPF); - array_push(&$$, (void *) ($3.length + 3)); - array_concat(&$$, &$3); - array_push(&$$, (void *) F_JMP); - array_push(&$$, (void *) -($3.length + $6.arr.length + 3));*/ break_allowed = continue_allowed = 0; } @@ -895,15 +892,6 @@ } */ -/* init_array(&$$); - array_concat(&$$, &$4.arr); - array_push(&$$, (void *) F_JMPF); - array_push(&$$, (void *) ($6.length + 3)); - array_concat(&$$, &$6); - array_push(&$$, (void *) F_JMP); - array_push(&$$, (void *) -($6.length + $4.arr.length + 3)); - break_allowed = continue_allowed = 0; -*/ } ; @@ -973,21 +961,7 @@ } } - init_array(&$$); - / * first expr. * / - array_concat(&$$, &$3.arr); - / * condition expr. * / - array_concat(&$$, &$5.arr); - array_push(&$$, (void *) F_JMPF); - array_push(&$$, (void *) ($7.arr.length + $10.length + 3)); - - / * Third expression - after every loop. * / - array_concat(&$$, &$7.arr); - / * Statements. * / - array_concat(&$$, &$10); - array_push(&$$, (void *) F_JMP); - array_push(&$$, (void *) -($10.length + $7.arr.length + + $5.arr.length + 3));*/ - break_allowed = continue_allowed = 0; + break_allowed = continue_allowed = 0;*/ } ; @@ -1038,12 +1012,12 @@ buf = xmalloc(strlen($1->name) + 23); sprintf(buf, "too many arguments to %s", $1->name); comp_error(buf); - xfree(buf); + free(buf); } 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); - xfree(buf); + free(buf); } else { for(i=0;i<$1->num_arg;i++) { if($1->args[i] != T_ANY && $3.data[i] != T_ANY @@ -1056,7 +1030,7 @@ sprintf(buf, "argument %d type mismatch for %s - expected %s, got %s", i+1, $1->name, ts1, ts2); comp_error(buf); - xfree(buf); + free(buf); break; } } @@ -1122,7 +1096,7 @@ void make_lvalue(int index) { int replace; - + /* Turn it into a lvalue. */ switch(curr_fun->code[index]) { case F_PUSH_LVAR: @@ -1131,11 +1105,19 @@ case F_PUSH_GVAR: replace = F_PUSH_GVAR_LVALUE; break; - case F_INDEX: - replace = F_INDEX_LVALUE; - break; - case F_SLICE: - replace = F_SLICE_LVALUE; + default: + index++; + switch(curr_fun->code[index]) { + case F_INDEX: + replace = F_INDEX_LVALUE; + break; + case F_SLICE: + replace = F_SLICE_LVALUE; + comp_error("assigning to slices not implemented"); + break; + default: + return; + } break; } curr_fun->code[index] = replace; |