summaryrefslogtreecommitdiff
path: root/05
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-01-24 14:54:16 -0500
committerpommicket <pommicket@gmail.com>2022-01-24 14:54:16 -0500
commit466de9358310c4d291c480577efc972705df787d (patch)
treeaaaaf2dc5b73610ae0629f083f5545f4e567e56f /05
parent448a1ec4b56468937da463ac87afc5fd6ddec483 (diff)
#if
Diffstat (limited to '05')
-rw-r--r--05/main.c4
-rw-r--r--05/preprocess.b39
2 files changed, 34 insertions, 9 deletions
diff --git a/05/main.c b/05/main.c
index 1b1b981..09707e4 100644
--- a/05/main.c
+++ b/05/main.c
@@ -3,6 +3,10 @@
long double d;
} (*x)(void);
*/
+#if 5+FLURGE==5
typedef long int unsigned Foo[sizeof"hello"+sizeof(double[sizeof(int) * sizeof 3])];
typedef int (*x)(Foo);
+#else
+typedef aaa x;
+#endif
/* */
diff --git a/05/preprocess.b b/05/preprocess.b
index 56e552a..5b4e6d7 100644
--- a/05/preprocess.b
+++ b/05/preprocess.b
@@ -835,21 +835,42 @@ function translation_phase_4
goto process_pptoken
:pp_directive_if
local if_pptokens
+ local if_tokens
+ local if_expr
pptoken_skip(&in)
pptoken_skip_spaces(&in)
- if_pptokens = malloc(4000)
+ if_pptokens = malloc(8000)
+ if_tokens = if_pptokens + 2500
+ if_expr = if_tokens + 2500
+
p = if_pptokens
macro_replacement_to_terminator(filename, line_number, &in, &p, 10)
- ;@TODO: there's no point in doing this until we have parsing
- ; we'll have to evaluate constant expressions anyways for array declarations
+ tokenize(if_pptokens, if_tokens, filename, line_number)
+ ; replace all identifiers with 0
+ p = if_tokens
+ :pp_if_idents0_loop
+ if *1p == TOKEN_EOF goto pp_if_idents0_done
+ if *1p == TOKEN_IDENTIFIER goto pp_if_replace_ident
+ p += 16
+ goto pp_if_idents0_loop
+ :pp_if_replace_ident
+ *1p = TOKEN_CONSTANT_INT
+ p += 8
+ *8p = 0
+ p += 8
+ goto pp_if_idents0_loop
+ :pp_if_idents0_done
+ parse_expression(if_tokens, p, if_expr)
+ evaluate_constant_expression(if_expr, &b)
+ if b == 0 goto pp_directive_if0
+ goto pp_if_done
+ :pp_directive_if0
+ preprocessor_skip_if(filename, &line_number, &in, &out)
+ goto pp_if_done
+ :pp_if_done
free(if_pptokens)
- fputs(2, .str_if_not_implemented)
- byte 0xcc
- :str_if_not_implemented
- string #if not implemented.
- byte 10
- byte 0
+ goto process_pptoken
:unrecognized_directive
compile_error(filename, line_number, .str_unrecognized_directive)
:str_unrecognized_directive