diff options
author | pommicket <pommicket@gmail.com> | 2022-02-05 19:22:47 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2022-02-05 19:22:47 -0500 |
commit | 41f122f01e3017df1611fb556b7b236216373e51 (patch) | |
tree | d545cbbffe6c42d70af4b8a79f18b7f418ca65ca | |
parent | ebe96b9e856f907dac7a89cf13c900c94fb8e1e1 (diff) |
braced initializers in local declarations
-rw-r--r-- | 05/main.c | 7 | ||||
-rw-r--r-- | 05/parse.b | 32 |
2 files changed, 31 insertions, 8 deletions
@@ -15,7 +15,12 @@ int h(void) { int y, r[3], s; char d, e[5], f, g, *p; int z = 3, R=12+459834-g; - return g; + int x[] = {1,2,3,4,5}; + struct { + char a,b; + } P[] = {1,2,3,4,5}; + static int marker = 0x12345678; + return 5; } /* typedef int AA[sizeof x]; */ @@ -392,25 +392,31 @@ function parse_statement write_statement_header(out, STATEMENT_LOCAL_DECLARATION, token) out += 8 *8out = local_var_next_rbp_offset - out += 8 - *8out = type_sizeof(l_type) - out += 24 + out += 32 p = local_variables p += block_depth < 3 l_offset = local_var_next_rbp_offset + c = ident_list_lookup(*8p, l_name) + if c != 0 goto local_redeclaration c = l_offset c |= l_type < 32 ident_list_add(*8p, l_name, c) + + token = l_suffix_end + :local_decl_continue + ; we need to calculate the size of the type here, because of stuff like + ; int x[] = {1,2,3}; + n = type_sizeof(l_type) + out -= 24 + *8out = n + out += 24 ; advance local_var_next_rbp_offset += type_sizeof(l_type) ; align local_var_next_rbp_offset += 7 local_var_next_rbp_offset >= 3 local_var_next_rbp_offset <= 3 - - token = l_suffix_end - :local_decl_continue if *1token == SYMBOL_SEMICOLON goto local_decl_loop_end if *1token == SYMBOL_EQ goto local_decl_initializer if *1token != SYMBOL_COMMA goto local_decl_badsuffix @@ -429,12 +435,24 @@ function parse_statement token = n goto local_decl_continue :local_init_lbrace - byte 0xcc ; @TODO + rwdata_end_addr += 7 + rwdata_end_addr >= 3 + rwdata_end_addr <= 3 + out -= 8 + *8out = rwdata_end_addr + out += 8 + parse_constant_initializer(&token, l_type) + goto local_decl_continue :local_decl_badsuffix token_error(token, .str_local_decl_badsuffix) :str_local_decl_badsuffix string Expected equals, comma, or semicolon after variable declaration. byte 0 + :local_redeclaration + token_error(token, .str_local_redeclaration) + :str_local_redeclaration + string Redeclaration of local variable. + byte 0 :local_decl_loop_end token += 16 ; skip semicolon goto parse_statement_ret |