From d718819ee757fcc59480ea3eff8bbac5a129a3a5 Mon Sep 17 00:00:00 2001 From: pommicket Date: Sat, 5 Feb 2022 18:07:42 -0500 Subject: block static variables seem to be working --- 05/main.c | 14 ++++++++++++++ 05/parse.b | 52 +++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 57 insertions(+), 9 deletions(-) (limited to '05') diff --git a/05/main.c b/05/main.c index f706e88..f10dbf9 100644 --- a/05/main.c +++ b/05/main.c @@ -1,10 +1,24 @@ +static int g; + int f(void) { lbl1:break;;goto blah; case -1-3: continue;a:break;return;return 6+3< ; <- token += 16 ; skip semicolon goto parse_statement_ret - + function print_statement argument statement print_statement_with_depth(statement, 0) return + +function print_indents + argument count + :print_indent_loop + if count == 0 goto return_0 + putc(9) + count -= 1 + goto print_indent_loop + function print_statement_with_depth argument statement argument depth @@ -502,13 +519,7 @@ function print_statement_with_depth local dat3 local dat4 - c = depth - :print_stmt_indent_loop - if c == 0 goto print_stmt_indent_loop_end - putc(9) ; tab - c -= 1 - goto print_stmt_indent_loop - :print_stmt_indent_loop_end + print_indents(depth) c = *1statement dat1 = statement + 8 @@ -573,6 +584,8 @@ function print_statement_with_depth dat1 += 40 goto print_block_loop :print_block_loop_end + depth -= 1 + print_indents(depth) putcln('}) return :print_stmt_goto @@ -2221,11 +2234,22 @@ function parse_expression out += 8 return out :not_enumerator - ; @TODO: check if it's a local variable + + n = block_depth + :var_lookup_loop + ; check if it's a block static variable + p = block_static_variables + p += n < 3 + c = ident_list_lookup(*8p, a) + if c != 0 goto found_global_variable + ; @TODO: check if it's a local variable + n -= 1 + if n >= 0 goto var_lookup_loop ; check if it's a global c = ident_list_lookup(global_variables, a) if c == 0 goto not_global + :found_global_variable ; it is a global variable *1out = EXPRESSION_GLOBAL_VARIABLE out += 4 @@ -3169,6 +3193,7 @@ function print_expression :print_expr_skip_type c = *1expression + if c == EXPRESSION_GLOBAL_VARIABLE goto print_global_variable if c == EXPRESSION_CONSTANT_INT goto print_expr_int if c == EXPRESSION_CONSTANT_FLOAT goto print_expr_float if c == EXPRESSION_POST_INCREMENT goto print_post_increment @@ -3195,6 +3220,15 @@ function print_expression string Bad expression passed to print_expression. byte 10 byte 0 + :str_global_at + string global@ + byte 0 + :print_global_variable + puts(.str_global_at) + expression += 8 + putx32(*8expression) + expression += 8 + return expression :print_cast ; we've already printed the type expression += 8 -- cgit v1.2.3