summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--05/constants.b3
-rw-r--r--05/main.c3
-rw-r--r--05/preprocess.b34
3 files changed, 35 insertions, 5 deletions
diff --git a/05/constants.b b/05/constants.b
index 2db55ce..850be2d 100644
--- a/05/constants.b
+++ b/05/constants.b
@@ -115,6 +115,9 @@
:str_define
string define
byte 0
+:str_undef
+ string undef
+ byte 0
:str_include
string include
byte 0
diff --git a/05/main.c b/05/main.c
index f591edc..f332a64 100644
--- a/05/main.c
+++ b/05/main.c
@@ -1,3 +1,6 @@
+#define z sz
+z
+
#define STRINGIFY2(x) # x
#define STRINGIFY(x) STRINGIFY2(x)
#define JOIN2(x,y) x ## y
diff --git a/05/preprocess.b b/05/preprocess.b
index 0f58676..93c7c63 100644
--- a/05/preprocess.b
+++ b/05/preprocess.b
@@ -464,6 +464,7 @@ function translation_phase_4
local p
local c
local b
+ local macro_name
local line_number
output = malloc(16000000)
@@ -503,8 +504,8 @@ function translation_phase_4
if b != 0 goto pp_directive_error
b = str_equals(in, .str_define)
if b != 0 goto pp_directive_define
- puts(in)
- putc(10)
+ b = str_equals(in, .str_undef)
+ if b != 0 goto pp_directive_undef
goto unrecognized_directive
:pp_directive_error
fputs(2, filename)
@@ -512,8 +513,25 @@ function translation_phase_4
fputn(2, line_number)
fputs(2, .str_directive_error)
exit(1)
+ :pp_directive_undef
+ pptoken_skip(&in)
+ pptoken_skip_spaces(&in)
+ macro_name = in
+ pptoken_skip(&in)
+ pptoken_skip_spaces(&in)
+ if *1in != 10 goto bad_undef
+ p = look_up_object_macro(macro_name)
+ if p == 0 goto undef_not_object
+ p -= 2
+ *1p = '@ ; replace last character of macro name with @ to "undefine" it
+ :undef_not_object
+ p = look_up_function_macro(macro_name)
+ if p == 0 goto undef_not_function
+ p -= 2
+ *1p = '@
+ :undef_not_function
+ goto process_pptoken
:pp_directive_define
- local macro_name
pptoken_skip(&in)
pptoken_skip_spaces(&in)
macro_name = in
@@ -604,6 +622,7 @@ function translation_phase_4
function_macros_size = p - function_macros
free(param_names)
goto phase4_next_line
+
:str_directive_error
string : #error
byte 10
@@ -630,6 +649,11 @@ function translation_phase_4
:str_bad_macro_params
string Bad macro parameter list.
byte 0
+ :bad_undef
+ compile_error(filename, line_number, .str_bad_undef)
+ :str_bad_undef
+ string Bad #undef.
+ byte 0
; returns a pointer to the replacement pptokens, or 0 if this macro is not defined
function look_up_macro
@@ -699,11 +723,10 @@ function macro_replacement
p = banned_objmacros
-
:check_banned_objmacros_loop
if *1p == 255 goto check_banned_objmacros_loop_end
b = str_equals(in, p)
- if b != 0 goto done_replacement
+ if b != 0 goto no_replacement
p = memchr(p, 0)
p += 1
goto check_banned_objmacros_loop
@@ -762,6 +785,7 @@ function macro_replacement
in += b ; skip argument
c = *1in
in += 2 ; skip , or )
+ pptoken_skip_spaces(&in)
*1p = 255
p += 1
if c == ', goto fmacro_arg_loop