summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--05/idents.b15
-rw-r--r--05/main.c7
-rw-r--r--05/parse.b7
3 files changed, 21 insertions, 8 deletions
diff --git a/05/idents.b b/05/idents.b
index 3f9d309..0deaf35 100644
--- a/05/idents.b
+++ b/05/idents.b
@@ -12,7 +12,14 @@ function ident_list_add
argument ident
argument value
- list = memchr(list, 255)
+ ; note: we can't just do list = memchr(list, 255) because values
+ ; might have a 255 byte.
+ :ilist_add_go_to_end_loop
+ if *1list == 255 goto ilist_add_found_end
+ list = memchr(list, 0)
+ list += 9 ; skip null byte and value
+ goto ilist_add_go_to_end_loop
+ :ilist_add_found_end
list = strcpy(list, ident)
list += 1
*8list = value ; UNALIGNED
@@ -30,8 +37,9 @@ function ident_list_lookup
if *1list == 255 goto return_0
b = str_equals(list, ident)
list = memchr(list, 0)
- list += 1
+ list += 9 ; skip null byte and value
if b == 0 goto ilist_lookup_loop
+ list -= 8 ; backtrack to value
return *8list ; UNALIGNED
; if identifier in list, sets *pvalue to its value (if pvalue is not null) and returns 1
@@ -45,9 +53,10 @@ function ident_list_lookup_check
if *1list == 255 goto return_0
b = str_equals(list, ident)
list = memchr(list, 0)
- list += 1
+ list += 9 ; skip null byte and value
if b == 0 goto ilist_lookcheck_loop
if pvalue == 0 goto return_1
+ list -= 8 ; backtrack to value
*8pvalue = *8list
return 1
diff --git a/05/main.c b/05/main.c
index 7dc9a0a..23a25c3 100644
--- a/05/main.c
+++ b/05/main.c
@@ -8,6 +8,9 @@ typedef enum {
HELLO,
THERE,
TEST = 1-3,
- EEE
+ EEE = TEST+4,
+ ASDFASDF,
+ FFF,
+ HELLO2
} y;
-typedef int Bar[EEE];
+typedef int Bar[FFF];
diff --git a/05/parse.b b/05/parse.b
index 20970f5..f962e2a 100644
--- a/05/parse.b
+++ b/05/parse.b
@@ -489,7 +489,8 @@ function parse_type_to
p += 16
depth = 0 ; parenthesis depth
q = p
- ; find matching comma -- yes, a comma can appear in an enumerator expression, e.g.
+ ; find matching comma/right brace
+ ; -- yes, a comma can appear in an enumerator expression, e.g.
; enum { X = sizeof(struct{int x, y;}) };
; or enum { X = (enum {A,B})3 };
@@ -1090,7 +1091,7 @@ function parse_expression
*4out = TYPE_INT
out += 4
*8out = n
- out += 16
+ out += 8
return out
:not_enumerator
in -= 16
@@ -1914,7 +1915,7 @@ function print_expression
return expression
:print_expr_int
expression += 8
- putn(*8expression)
+ putn_signed(*8expression)
expression += 8
return expression
:print_expr_float