diff options
author | pommicket <pommicket@gmail.com> | 2022-02-02 13:43:20 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2022-02-02 13:43:20 -0500 |
commit | 6ccef91d521fc077fa297a1d692eb829c1926a81 (patch) | |
tree | 5e97569e79f36f1569d0c3b79250fae0ce41ac54 /05 | |
parent | f4a83337517c7f95adea7bc470a0dd9696597df8 (diff) |
array initializers more or less working
Diffstat (limited to '05')
-rw-r--r-- | 05/main.c | 4 | ||||
-rw-r--r-- | 05/parse.b | 25 |
2 files changed, 26 insertions, 3 deletions
@@ -36,4 +36,6 @@ static char w[] = "friendly"; static char x_[] = "hi"; typedef int A[sizeof x_ + sizeof u]; -static int a[3] = {1,2,3}; +static int a[5] = {1,2,3}; +static char b[6][7] = {{'a'},{'b'},{'c'},{'d'},{'e'}}; +static int _u = 0x12345678; @@ -345,17 +345,38 @@ function parse_constant_initializer token += 16 :array_init_no_lbrace addr0 = rwdata_end_addr + + local len + len = types + type + len += 1 ; skip TYPE_ARRAY + len = *8len + subtype = type + 9 ; skip TYPE_ARRAY and size :array_init_loop if *1token == TOKEN_EOF goto array_init_eof parse_constant_initializer(&token, subtype) + len -= 1 + if len == 0 goto array_init_loop_end if *1token == SYMBOL_RBRACE goto array_init_loop_end if *1token != SYMBOL_COMMA goto bad_array_initializer token += 16 ; skip comma goto array_init_loop :array_init_loop_end - putcln('*) - + + if *1token == SYMBOL_COMMA goto array_init_skip + p = *8p_token + if *1p != SYMBOL_LBRACE goto array_init_noskip ; we don't want to skip the closing } because it doesn't belong to us. + :array_init_skip + token += 16 ; skip } or , + :array_init_noskip + p = types + type + p += 1 ; skip TYPE_ARRAY + if *8p == 0 goto sizeless_array_initializer + rwdata_end_addr = addr0 + c = type_sizeof(subtype) + rwdata_end_addr += *8p * c ; e.g. int x[50] = {1,2}; advance rwdata_end_addr by 50*sizeof(int) + goto const_init_ret + :sizeless_array_initializer byte 0xcc ; @TODO :array_init_eof token_error(token, .str_array_init_eof) |