From a8a30458bdf24fc664ed76c5247412bd39fc067e Mon Sep 17 00:00:00 2001 From: pommicket Date: Mon, 10 Jan 2022 12:00:05 -0500 Subject: pre-defined macros --- 05/constants.b | 15 +++++++++++++++ 05/main.c | 8 ++++++++ 05/preprocess.b | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) (limited to '05') diff --git a/05/constants.b b/05/constants.b index aaf5c06..15efa68 100644 --- a/05/constants.b +++ b/05/constants.b @@ -142,3 +142,18 @@ :str_else string else byte 0 +:str___FILE__ + string __FILE__ + byte 0 +:str___LINE__ + string __LINE__ + byte 0 +:str___DATE__ + string __DATE__ + byte 0 +:str___TIME__ + string __TIME__ + byte 0 +:str___STDC__ + string __STDC__ + byte 0 diff --git a/05/main.c b/05/main.c index e69de29..2bf29ec 100644 --- a/05/main.c +++ b/05/main.c @@ -0,0 +1,8 @@ +__TIME__ +__DATE__ +__STDC__ +__LINE__ +__FILE__ +#line 7 "aah.c" +__LINE__ +__FILE__ diff --git a/05/preprocess.b b/05/preprocess.b index ae4e5c5..195890f 100644 --- a/05/preprocess.b +++ b/05/preprocess.b @@ -832,6 +832,17 @@ function macro_replacement :check_banned_objmacros_loop_end :objmacro_replacement + b = str_equals(in, .str___FILE__) + if b != 0 goto handle___FILE__ + b = str_equals(in, .str___LINE__) + if b != 0 goto handle___LINE__ + b = str_equals(in, .str___DATE__) + if b != 0 goto handle___DATE__ + b = str_equals(in, .str___TIME__) + if b != 0 goto handle___TIME__ + b = str_equals(in, .str___STDC__) + if b != 0 goto handle___STDC__ + replacement = look_up_object_macro(in) if replacement == 0 goto no_replacement @@ -1012,6 +1023,51 @@ function macro_replacement :str_empty_fmacro_invocation string No arguments provided to function-like macro. byte 0 + + :handle___FILE__ + pptoken_skip(&in) + *1out = '" + out += 1 + out = strcpy(out, filename) + *1out = '" + out += 1 + *1out = 0 + out += 1 + goto done_replacement + :handle___LINE__ + pptoken_skip(&in) + p = itos(line_number) + out = strcpy(out, p) + out += 1 + goto done_replacement + :handle___DATE__ + pptoken_skip(&in) + out = strcpy(out, .str_compilation_date) + out += 1 + goto done_replacement + :handle___TIME__ + pptoken_skip(&in) + out = strcpy(out, .str_compilation_time) + out += 1 + goto done_replacement + :handle___STDC__ + pptoken_skip(&in) + out = strcpy(out, .str_stdc) + out += 1 + goto done_replacement + :str_compilation_date + ; "If the date of translation is not available, an implementation-defined valid date shall be supplied." C89 § 3.8.8 + string "Jan 01 1970" + byte 0 + :str_compilation_time + ; "If the time of translation is not available, an implementation-defined valid time shall be supplied." C89 § 3.8.8 + string "00:00:00" + byte 0 + :str_stdc + ; (see @NONSTANDARD) a bit of a lie, but oh well + string 1 + byte 0 + function fmacro_get_arg argument filename -- cgit v1.2.3