diff --git a/include/asm/mymath.h b/include/asm/mymath.h index 2bbd0a14..085ba422 100644 --- a/include/asm/mymath.h +++ b/include/asm/mymath.h @@ -11,7 +11,7 @@ #include -void math_DefinePI(void); +int32_t math_Callback_PI(void); void math_Print(int32_t i); int32_t math_Sin(int32_t i); int32_t math_Cos(int32_t i); diff --git a/src/asm/math.c b/src/asm/math.c index 9f827e24..eb19e1fe 100644 --- a/src/asm/math.c +++ b/src/asm/math.c @@ -17,6 +17,7 @@ #include "asm/mymath.h" #include "asm/symbol.h" +#include "asm/warning.h" #define fx2double(i) ((double)((i) / 65536.0)) #define double2fx(d) ((int32_t)((d) * 65536.0)) @@ -26,11 +27,13 @@ #endif /* - * Define the _PI symbol + * Return the _PI symbol value */ -void math_DefinePI(void) +int32_t math_Callback_PI(void) { - sym_AddEqu("_PI", double2fx(M_PI)); + warning(WARNING_OBSOLETE, "`_PI` is deprecated; use 3.14159\n"); + + return double2fx(M_PI); } /* diff --git a/src/asm/symbol.c b/src/asm/symbol.c index 699bbb4d..3f8262ce 100644 --- a/src/asm/symbol.c +++ b/src/asm/symbol.c @@ -720,5 +720,12 @@ void sym_Init(time_t now) labelScope = NULL; anonLabelID = 0; - math_DefinePI(); + /* _PI is deprecated */ + struct Symbol *_PISymbol = createBuiltinSymbol("_PI"); + + _PISymbol->type = SYM_EQU; + _PISymbol->src = NULL; + _PISymbol->fileLine = 0; + _PISymbol->hasCallback = true; + _PISymbol->numCallback = math_Callback_PI; } diff --git a/test/asm/deprecated-pi.asm b/test/asm/deprecated-pi.asm new file mode 100644 index 00000000..77f510e1 --- /dev/null +++ b/test/asm/deprecated-pi.asm @@ -0,0 +1,4 @@ +; Remove this test case when _PI is removed. + PRINTF _PI + PRINTT "\n" + PURGE _PI diff --git a/test/asm/deprecated-pi.err b/test/asm/deprecated-pi.err new file mode 100644 index 00000000..6836ab23 --- /dev/null +++ b/test/asm/deprecated-pi.err @@ -0,0 +1,5 @@ +warning: deprecated-pi.asm(2): [-Wobsolete] + `_PI` is deprecated; use 3.14159 +ERROR: deprecated-pi.asm(4): + Built-in symbol '_PI' cannot be purged +error: Assembly aborted (1 errors)! diff --git a/test/asm/deprecated-pi.out b/test/asm/deprecated-pi.out new file mode 100644 index 00000000..41bec393 --- /dev/null +++ b/test/asm/deprecated-pi.out @@ -0,0 +1 @@ +3.14159 diff --git a/test/asm/strfmt.asm b/test/asm/strfmt.asm index 45f70a5a..c613a9c7 100644 --- a/test/asm/strfmt.asm +++ b/test/asm/strfmt.asm @@ -13,7 +13,7 @@ PRINTT STRFMT(TEMPLATE, "roses", "red") PRINTT STRFMT(TEMPLATE, "violets", "blue") PRINTT STRFMT(TEMPLATE, "void", 0, "extra") -PRINTT STRCAT(STRFMT(STRFMT("%%%s.%d%s", "", 9, "f"), _PI), \ +PRINTT STRCAT(STRFMT(STRFMT("%%%s.%d%s", "", 9, "f"), 3.14159), \ STRFMT(" ~ %s\n", STRFMT("%s%x", "thr", 238))) PRINTT STRFMT("%d eol %", 1) diff --git a/test/asm/string-formatting.asm b/test/asm/string-formatting.asm index 2929e847..04e27b94 100644 --- a/test/asm/string-formatting.asm +++ b/test/asm/string-formatting.asm @@ -1,11 +1,12 @@ n equ 300 m equ -42 f equ -123.0456 +pi equ 3.14159 s equs "hello" printt "<{ -6d:n}> <{+06u:n}> <{5x:n}> <{#16b:n}>\n" printt "<{u:m}> <{+3d:m}> <{#016o:m}>\n" - printt "<{f:_PI}> <{06f:f}> <{.10f:f}>\n" + printt "<{f:pi}> <{06f:f}> <{.10f:f}>\n" printt "<{#-10s:s}> <{10s:s}>\n" foo: macro diff --git a/test/asm/string-formatting.err b/test/asm/string-formatting.err index 341a4971..76a85473 100644 --- a/test/asm/string-formatting.err +++ b/test/asm/string-formatting.err @@ -1,3 +1,3 @@ -ERROR: string-formatting.asm(9): +ERROR: string-formatting.asm(10): Formatting string with prefix flag '#' error: Assembly aborted (1 errors)!