summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--05/main.c4
-rw-r--r--05/parse.b25
2 files changed, 26 insertions, 3 deletions
diff --git a/05/main.c b/05/main.c
index fb2283e..6fb4a76 100644
--- a/05/main.c
+++ b/05/main.c
@@ -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;
diff --git a/05/parse.b b/05/parse.b
index 5925078..b1675f6 100644
--- a/05/parse.b
+++ b/05/parse.b
@@ -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)