Skip to content

Commit

Permalink
Deprecate DEF-less definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
Rangi42 committed Nov 1, 2023
1 parent ab42eb2 commit e3e9ae4
Show file tree
Hide file tree
Showing 56 changed files with 258 additions and 180 deletions.
37 changes: 33 additions & 4 deletions src/asm/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -956,29 +956,58 @@ compoundeq : T_POP_ADDEQ { $$ = RPN_ADD; }
| T_POP_SHREQ { $$ = RPN_SHR; }
;

equ : T_LABEL T_POP_EQU const { sym_AddEqu($1, $3); }
equ : T_LABEL T_POP_EQU const {
warning(WARNING_OBSOLETE, "`%s EQU` is deprecated; use `DEF %s EQU`\n", $1, $1);
sym_AddEqu($1, $3);
}
;

assignment : T_LABEL T_POP_EQUAL const { sym_AddVar($1, $3); }
| T_LABEL compoundeq const { compoundAssignment($1, $2, $3); }
assignment : T_LABEL T_POP_EQUAL const {
warning(WARNING_OBSOLETE, "`%s =` is deprecated; use `DEF %s =`\n", $1, $1);
sym_AddVar($1, $3);
}
| T_LABEL compoundeq const {
static const char *compoundEqOperators[] = {
[RPN_ADD] = "+=",
[RPN_SUB] = "-=",
[RPN_MUL] = "*=",
[RPN_DIV] = "/=",
[RPN_MOD] = "%=",
[RPN_XOR] = "^=",
[RPN_OR] = "|=",
[RPN_AND] = "&=",
[RPN_SHL] = "<<=",
[RPN_SHR] = ">>=",
};

warning(WARNING_OBSOLETE, "`%s %s` is deprecated; use `DEF %s %s`\n",
$1, compoundEqOperators[$2], $1, compoundEqOperators[$2]);
compoundAssignment($1, $2, $3);
}
;

equs : T_LABEL T_POP_EQUS string { sym_AddString($1, $3); }
equs : T_LABEL T_POP_EQUS string {
warning(WARNING_OBSOLETE, "`%s EQUS` is deprecated; use `DEF %s EQUS`\n", $1, $1);
sym_AddString($1, $3);
}
;

rb : T_LABEL T_POP_RB rs_uconst {
warning(WARNING_OBSOLETE, "`%s RB` is deprecated; use `DEF %s RB`\n", $1, $1);
sym_AddEqu($1, sym_GetConstantValue("_RS"));
sym_AddVar("_RS", sym_GetConstantValue("_RS") + $3);
}
;

rw : T_LABEL T_POP_RW rs_uconst {
warning(WARNING_OBSOLETE, "`%s RW` is deprecated; use `DEF %s RW`\n", $1, $1);
sym_AddEqu($1, sym_GetConstantValue("_RS"));
sym_AddVar("_RS", sym_GetConstantValue("_RS") + 2 * $3);
}
;

rl : T_LABEL T_Z80_RL rs_uconst {
warning(WARNING_OBSOLETE, "`%s RL` is deprecated; use `DEF %s RL`\n", $1, $1);
sym_AddEqu($1, sym_GetConstantValue("_RS"));
sym_AddVar("_RS", sym_GetConstantValue("_RS") + 4 * $3);
}
Expand Down
4 changes: 2 additions & 2 deletions test/asm/bracketed-macro-args.asm
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ ENDM

MACRO mac
println \<2__> + \<1_2> + \<\1>
x = 2
def x = 2
println \<{d:x}> + \<1_{d:x}> + \<\<\<13>>>
y equs "NARG"
def y equs "NARG"
println \<x> + \<1_{d:x}_> + \<\<\<_{y}>>>
ENDM

Expand Down
8 changes: 4 additions & 4 deletions test/asm/bracketed-symbols.asm
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
X = 42
DEF X = 42
PRINTLN "{X}"
PRINTLN "{x:X}"
PRINTLN "{X:X}"
PRINTLN "{d:X}"
PRINTLN "{b:X}"

Y equ 1337
DEF Y EQU 1337
PRINTLN "{b:Y}"

rsreset
R rb 0
DEF R RB 0
PRINTLN "{d:R}"

S equs "You can't format me!"
DEF S EQUS "You can't format me!"
PRINTLN "{X:S}"

SECTION "Test", ROM0
Expand Down
2 changes: 1 addition & 1 deletion test/asm/charlen-charsub.asm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

SECTION "test", ROM0

S EQUS "XBold<NULL>ABC"
DEF S EQUS "XBold<NULL>ABC"

assert CHARLEN("{S}") == 6
println CHARSUB("{S}", 2)
Expand Down
4 changes: 2 additions & 2 deletions test/asm/compound-assignment.asm
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ endm
try "def ", q
try "redef ", r

_RS += 100
def _RS += 100
println _RS

UnDeFiNeD ^= 300
def UnDeFiNeD ^= 300
println UnDeFiNeD
19 changes: 19 additions & 0 deletions test/asm/def.asm
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,22 @@ redef string equs "there"

redef constant equ 6*9
println constant

old_constant EQU 42
old_string EQUS "hello"

old_variable = 2 + 2
old_variable += 3
old_variable *= 4
old_variable -= 1
old_variable /= 5
old_variable %= 7
old_variable &= $ffff
old_variable |= %1010
old_variable ^= &123
old_variable <<= 2
old_variable >>= 1

old_byte rb
old_word rw
old_long rl
32 changes: 32 additions & 0 deletions test/asm/def.err
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
error: def.asm(23):
'constant' already defined at def.asm(10)
warning: def.asm(32): [-Wobsolete]
`old_constant EQU` is deprecated; use `DEF old_constant EQU`
warning: def.asm(33): [-Wobsolete]
`old_string EQUS` is deprecated; use `DEF old_string EQUS`
warning: def.asm(35): [-Wobsolete]
`old_variable =` is deprecated; use `DEF old_variable =`
warning: def.asm(36): [-Wobsolete]
`old_variable +=` is deprecated; use `DEF old_variable +=`
warning: def.asm(37): [-Wobsolete]
`old_variable *=` is deprecated; use `DEF old_variable *=`
warning: def.asm(38): [-Wobsolete]
`old_variable -=` is deprecated; use `DEF old_variable -=`
warning: def.asm(39): [-Wobsolete]
`old_variable /=` is deprecated; use `DEF old_variable /=`
warning: def.asm(40): [-Wobsolete]
`old_variable %=` is deprecated; use `DEF old_variable %=`
warning: def.asm(41): [-Wobsolete]
`old_variable &=` is deprecated; use `DEF old_variable &=`
warning: def.asm(42): [-Wobsolete]
`old_variable |=` is deprecated; use `DEF old_variable |=`
warning: def.asm(43): [-Wobsolete]
`old_variable ^=` is deprecated; use `DEF old_variable ^=`
warning: def.asm(44): [-Wobsolete]
`old_variable <<=` is deprecated; use `DEF old_variable <<=`
warning: def.asm(45): [-Wobsolete]
`old_variable >>=` is deprecated; use `DEF old_variable >>=`
warning: def.asm(47): [-Wobsolete]
`old_byte RB` is deprecated; use `DEF old_byte RB`
warning: def.asm(48): [-Wobsolete]
`old_word RW` is deprecated; use `DEF old_word RW`
warning: def.asm(49): [-Wobsolete]
`old_long RL` is deprecated; use `DEF old_long RL`
error: Assembly aborted (1 error)!
6 changes: 3 additions & 3 deletions test/asm/endc-eof-newline.asm
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
IF 1
X = 0
DEF X = 0
INCLUDE "endc-eof-newline.inc"
INCLUDE "endc-eof-newline-else.inc"
X = 1
DEF X = 1
INCLUDE "endc-eof-newline.inc"
INCLUDE "endc-eof-newline-else.inc"
ENDC
ENDC
2 changes: 1 addition & 1 deletion test/asm/equ-charmap.asm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
charmap "A", 1
SECTION "sec", ROM0[0]
_A_ EQU "A"
DEF _A_ EQU "A"
db _A_
2 changes: 1 addition & 1 deletion test/asm/equs-macrodef.asm
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
DEFINE equs "MACRO mac\nPRINTLN \"Hello :D\"\nENDM"
def DEFINE equs "MACRO mac\nPRINTLN \"Hello :D\"\nENDM"
DEFINE
mac
4 changes: 2 additions & 2 deletions test/asm/equs-nest.asm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
X1 equs "Y1 equs \"\\\"Success!\\\\n\\\"\""
Y1 equs "Z1"
def X1 equs "Y1 equs \"\\\"Success!\\\\n\\\"\""
def Y1 equs "Z1"
X1
PRINT Z1
2 changes: 1 addition & 1 deletion test/asm/equs-newline.asm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

ACT equs "WARN \"First\"\nWARN \"Second\""
def ACT equs "WARN \"First\"\nWARN \"Second\""
ACT
WARN "Third"
2 changes: 1 addition & 1 deletion test/asm/equs-purge.asm
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
BYE equs "PURGE BYE\nWARN \"Crash?\"\n \n"
def BYE equs "PURGE BYE\nWARN \"Crash?\"\n \n"
BYE
2 changes: 1 addition & 1 deletion test/asm/equs-recursion.asm
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
recurse EQUS "recurse"
DEF recurse EQUS "recurse"
recurse
4 changes: 2 additions & 2 deletions test/asm/expand-empty-string.asm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MACRO test
v equs "X"
X equs "" ; should not be expanded
def v equs "X"
def X equs "" ; should not be expanded
\1
ENDM
test v 0
2 changes: 1 addition & 1 deletion test/asm/ff00+c-label.asm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CONSTANT equ 42
def CONSTANT equ 42
PRINTLN $ff00 + CONSTANT

SECTION "Overreading much?", ROM0[0]
Expand Down
20 changes: 10 additions & 10 deletions test/asm/fixed-point-precision.asm
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
f1 = 3.1
f2 = 5.2
pm = MUL(f1, f2)
pr = 16.12
def f1 = 3.1
def f2 = 5.2
def pm = MUL(f1, f2)
def pr = 16.12
println "`3.1`: {9.6f:f1} -> ${08x:f1}"
println "`5.2`: {9.6f:f2} -> ${08x:f2}"
println "`MUL`: {9.6f:pm} -> ${08x:pm}"
println "`16.12`: {9.6f:pr} -> ${08x:pr}"

fl = 6.283185
def fl = 6.283185
println "`6.283185`: {.6f:fl} -> ${08x:fl}"

fr = MUL(20.0, 0.32)
def fr = MUL(20.0, 0.32)
println "32% of 20 = {f:fr} (~{.2f:fr}) (~~{.0f:fr})"

q8 = 1.25q8
q16 = 1.25Q16
q24 = 1.25q.24
def q8 = 1.25q8
def q16 = 1.25Q16
def q24 = 1.25q.24
println "Q8 ${x:q8} Q16 ${x:q16} Q24 ${x:q24}"

qerr = 1.25q32
def qerr = 1.25q32
println qerr
6 changes: 3 additions & 3 deletions test/asm/for.asm
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ endr

for v, 10, -1, -1
print "{d:v} "
v = 42
def v = 42
endr
println "-> {d:v}"

Expand All @@ -36,7 +36,7 @@ purge q
endr
println "-> {d:q}"

s EQUS "x"
DEF s EQUS "x"
for {s}, 3, 30, 3
print "{d:x} "
endr
Expand All @@ -46,7 +46,7 @@ for v, 10
println "{d:v}"
if v == 3
purge v
v equ 42 ; causes a fatal error
def v equ 42 ; causes a fatal error
endc
endr
println "-> {d:v}"
6 changes: 3 additions & 3 deletions test/asm/format-truncation.asm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
num equ 42
fix equ 123.0
str equs "hello"
def num equ 42
def fix equ 123.0
def str equs "hello"

println "{#0260x:num}"
println "{#-260x:num}"
Expand Down
2 changes: 1 addition & 1 deletion test/asm/interpolation-overflow.asm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; It seems that \1 was the easiest way to notice the memory corruption that
; resulted from this overflow
x = 0
def x = 0
{.99999999f:x}\1
2 changes: 1 addition & 1 deletion test/asm/interpolation-recursion.asm
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
recurse EQUS "\{recurse\}"
DEF recurse EQUS "\{recurse\}"
{recurse}
12 changes: 6 additions & 6 deletions test/asm/interpolation.asm
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
SECTION "Test", ROM0

NAME equs "ITEM"
FMT equs "d"
ZERO_NUM equ 0
ZERO_STR equs "0"
def NAME equs "ITEM"
def FMT equs "d"
def ZERO_NUM equ 0
def ZERO_STR equs "0"
; Defines INDEX as 100
INDEX = 1{ZERO_STR}{{FMT}:ZERO_NUM}
def INDEX = 1{ZERO_STR}{{FMT}:ZERO_NUM}
; Defines ITEM_100 as "\"hundredth\""
{NAME}_{d:INDEX} equs "\"hundredth\""
def {NAME}_{d:INDEX} equs "\"hundredth\""
; Prints "ITEM_100 is hundredth"
PRINTLN STRCAT("{NAME}_{d:INDEX}", " is ", {NAME}_{d:INDEX})
; Purges ITEM_100
Expand Down
10 changes: 5 additions & 5 deletions test/asm/invalid-utf-8-strings.asm
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
; 10: invalid bytes 0xE6 0xF0
; 11: invalid byte 0xA2
; 12: U+0021 !
invalid EQUS "aäbæ¼¢,a£¤bæð¢!"
DEF invalid EQUS "aäbæ¼¢,a£¤bæð¢!"

n = STRLEN("{invalid}")
copy EQUS STRSUB("{invalid}", 1)
DEF n = STRLEN("{invalid}")
DEF copy EQUS STRSUB("{invalid}", 1)

println "\"{invalid}\" == \"{copy}\" ({d:n})"

mid1 EQUS STRSUB("{invalid}", 5, 2)
mid2 EQUS STRSUB("{invalid}", 9, 1)
DEF mid1 EQUS STRSUB("{invalid}", 5, 2)
DEF mid2 EQUS STRSUB("{invalid}", 9, 1)
println "\"{mid2}{mid1}\""
6 changes: 3 additions & 3 deletions test/asm/isconst.asm
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

TEST_NUM = 0
DEF TEST_NUM = 0

MACRO test_expr
TEST_NUM = TEST_NUM + 1
DEF TEST_NUM = TEST_NUM + 1

IS_CONST = ISCONST(\1)
DEF IS_CONST = ISCONST(\1)
PRINTLN "Test #{d:TEST_NUM}: ISCONST reports {IS_CONST}"
IF (\1) || 1 ; Only test if the expression can be evaluated
WARN "Test #{d:TEST_NUM}: Compile-time constant"
Expand Down
2 changes: 1 addition & 1 deletion test/asm/jr-section.asm
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ SECTION "Test", ROM0

Label:
jr Label
DIFF equ Label - @
def DIFF equ Label - @
PRINTLN "{DIFF}"
Loading

0 comments on commit e3e9ae4

Please sign in to comment.