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 aacb8b5
Show file tree
Hide file tree
Showing 78 changed files with 350 additions and 263 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
11 changes: 0 additions & 11 deletions test/asm/builtin-overwrite.asm
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,6 @@ macro tickle
; There once was a bug where overwriting worked only on the second try, so
; try everything twice for good measure

; Skip this syntax for EQUS, as it is invalid
IF \2
\1 = 0
\1 = 0
PRINTLN \1

\1 EQU 0
\1 EQU 0
PRINTLN \1
ENDC

PURGE \1
PURGE \1
PRINTLN \1
Expand Down
58 changes: 25 additions & 33 deletions test/asm/builtin-overwrite.err
Original file line number Diff line number Diff line change
@@ -1,57 +1,49 @@
error: builtin-overwrite.asm(43) -> builtin-overwrite.asm::tickle(7):
'__UTC_YEAR__' already defined as constant at <command-line>
error: builtin-overwrite.asm(43) -> builtin-overwrite.asm::tickle(8):
'__UTC_YEAR__' already defined as constant at <command-line>
error: builtin-overwrite.asm(43) -> builtin-overwrite.asm::tickle(11):
'__UTC_YEAR__' already defined at <command-line>
error: builtin-overwrite.asm(43) -> builtin-overwrite.asm::tickle(12):
'__UTC_YEAR__' already defined at <command-line>
error: builtin-overwrite.asm(43) -> builtin-overwrite.asm::tickle(16):
error: builtin-overwrite.asm(32) -> builtin-overwrite.asm::tickle(5):
Built-in symbol '__UTC_YEAR__' cannot be purged
error: builtin-overwrite.asm(43) -> builtin-overwrite.asm::tickle(17):
error: builtin-overwrite.asm(32) -> builtin-overwrite.asm::tickle(6):
Built-in symbol '__UTC_YEAR__' cannot be purged
error: builtin-overwrite.asm(43) -> builtin-overwrite.asm::tickle(20):
error: builtin-overwrite.asm(32) -> builtin-overwrite.asm::tickle(9):
'__UTC_YEAR__' already defined at <command-line>
error: builtin-overwrite.asm(43) -> builtin-overwrite.asm::tickle(21):
error: builtin-overwrite.asm(32) -> builtin-overwrite.asm::tickle(10):
'__UTC_YEAR__' already defined at <command-line>
error: builtin-overwrite.asm(43) -> builtin-overwrite.asm::tickle(24):
error: builtin-overwrite.asm(32) -> builtin-overwrite.asm::tickle(13):
'__UTC_YEAR__' already defined as constant at <command-line>
error: builtin-overwrite.asm(43) -> builtin-overwrite.asm::tickle(25):
error: builtin-overwrite.asm(32) -> builtin-overwrite.asm::tickle(14):
'__UTC_YEAR__' already defined as constant at <command-line>
error: builtin-overwrite.asm(43) -> builtin-overwrite.asm::tickle(28):
error: builtin-overwrite.asm(32) -> builtin-overwrite.asm::tickle(17):
'__UTC_YEAR__' already defined at <command-line>
error: builtin-overwrite.asm(43) -> builtin-overwrite.asm::tickle(29):
error: builtin-overwrite.asm(32) -> builtin-overwrite.asm::tickle(18):
'__UTC_YEAR__' already defined at <command-line>
error: builtin-overwrite.asm(43) -> builtin-overwrite.asm::tickle(32):
error: builtin-overwrite.asm(32) -> builtin-overwrite.asm::tickle(21):
'__UTC_YEAR__' already defined as constant at <command-line>
error: builtin-overwrite.asm(43) -> builtin-overwrite.asm::tickle(33):
error: builtin-overwrite.asm(32) -> builtin-overwrite.asm::tickle(22):
'__UTC_YEAR__' already defined as constant at <command-line>
error: builtin-overwrite.asm(43) -> builtin-overwrite.asm::tickle(36):
error: builtin-overwrite.asm(32) -> builtin-overwrite.asm::tickle(25):
'__UTC_YEAR__' already defined as non-EQUS at <command-line>
error: builtin-overwrite.asm(43) -> builtin-overwrite.asm::tickle(37):
error: builtin-overwrite.asm(32) -> builtin-overwrite.asm::tickle(26):
'__UTC_YEAR__' already defined as non-EQUS at <command-line>
error: builtin-overwrite.asm(44) -> builtin-overwrite.asm::tickle(16):
error: builtin-overwrite.asm(33) -> builtin-overwrite.asm::tickle(5):
Built-in symbol '__ISO_8601_UTC__' cannot be purged
error: builtin-overwrite.asm(44) -> builtin-overwrite.asm::tickle(17):
error: builtin-overwrite.asm(33) -> builtin-overwrite.asm::tickle(6):
Built-in symbol '__ISO_8601_UTC__' cannot be purged
error: builtin-overwrite.asm(44) -> builtin-overwrite.asm::tickle(20):
error: builtin-overwrite.asm(33) -> builtin-overwrite.asm::tickle(9):
'__ISO_8601_UTC__' already defined at <command-line>
error: builtin-overwrite.asm(44) -> builtin-overwrite.asm::tickle(21):
error: builtin-overwrite.asm(33) -> builtin-overwrite.asm::tickle(10):
'__ISO_8601_UTC__' already defined at <command-line>
error: builtin-overwrite.asm(44) -> builtin-overwrite.asm::tickle(24):
error: builtin-overwrite.asm(33) -> builtin-overwrite.asm::tickle(13):
'__ISO_8601_UTC__' already defined as constant at <command-line>
error: builtin-overwrite.asm(44) -> builtin-overwrite.asm::tickle(25):
error: builtin-overwrite.asm(33) -> builtin-overwrite.asm::tickle(14):
'__ISO_8601_UTC__' already defined as constant at <command-line>
error: builtin-overwrite.asm(44) -> builtin-overwrite.asm::tickle(28):
error: builtin-overwrite.asm(33) -> builtin-overwrite.asm::tickle(17):
'__ISO_8601_UTC__' already defined at <command-line>
error: builtin-overwrite.asm(44) -> builtin-overwrite.asm::tickle(29):
error: builtin-overwrite.asm(33) -> builtin-overwrite.asm::tickle(18):
'__ISO_8601_UTC__' already defined at <command-line>
error: builtin-overwrite.asm(44) -> builtin-overwrite.asm::tickle(32):
error: builtin-overwrite.asm(33) -> builtin-overwrite.asm::tickle(21):
'__ISO_8601_UTC__' already defined as constant at <command-line>
error: builtin-overwrite.asm(44) -> builtin-overwrite.asm::tickle(33):
error: builtin-overwrite.asm(33) -> builtin-overwrite.asm::tickle(22):
'__ISO_8601_UTC__' already defined as constant at <command-line>
error: builtin-overwrite.asm(44) -> builtin-overwrite.asm::tickle(36):
error: builtin-overwrite.asm(33) -> builtin-overwrite.asm::tickle(25):
Built-in symbol '__ISO_8601_UTC__' cannot be redefined
error: builtin-overwrite.asm(44) -> builtin-overwrite.asm::tickle(37):
error: builtin-overwrite.asm(33) -> builtin-overwrite.asm::tickle(26):
Built-in symbol '__ISO_8601_UTC__' cannot be redefined
error: Assembly aborted (28 errors)!
error: Assembly aborted (24 errors)!
2 changes: 0 additions & 2 deletions test/asm/builtin-overwrite.out
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ $7C5
$7C5
$7C5
$7C5
$7C5
$7C5
1989-04-21T12:34:56Z
1989-04-21T12:34:56Z
1989-04-21T12:34:56Z
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
22 changes: 22 additions & 0 deletions test/asm/compound-assignment.err
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
warning: compound-assignment.asm(29) -> compound-assignment.asm::try(4): [-Wobsolete]
`p =` is deprecated; use `DEF p =`
warning: compound-assignment.asm(29) -> compound-assignment.asm::try(6): [-Wobsolete]
`p +=` is deprecated; use `DEF p +=`
warning: compound-assignment.asm(29) -> compound-assignment.asm::try(8): [-Wobsolete]
`p -=` is deprecated; use `DEF p -=`
warning: compound-assignment.asm(29) -> compound-assignment.asm::try(10): [-Wobsolete]
`p *=` is deprecated; use `DEF p *=`
warning: compound-assignment.asm(29) -> compound-assignment.asm::try(12): [-Wobsolete]
`p /=` is deprecated; use `DEF p /=`
warning: compound-assignment.asm(29) -> compound-assignment.asm::try(14): [-Wobsolete]
`p %=` is deprecated; use `DEF p %=`
warning: compound-assignment.asm(29) -> compound-assignment.asm::try(16): [-Wobsolete]
`p |=` is deprecated; use `DEF p |=`
warning: compound-assignment.asm(29) -> compound-assignment.asm::try(18): [-Wobsolete]
`p ^=` is deprecated; use `DEF p ^=`
warning: compound-assignment.asm(29) -> compound-assignment.asm::try(20): [-Wobsolete]
`p &=` is deprecated; use `DEF p &=`
warning: compound-assignment.asm(29) -> compound-assignment.asm::try(22): [-Wobsolete]
`p <<=` is deprecated; use `DEF p <<=`
warning: compound-assignment.asm(29) -> compound-assignment.asm::try(24): [-Wobsolete]
`p >>=` is deprecated; use `DEF p >>=`
error: compound-assignment.asm(36):
Expected constant expression: 'UnDeFiNeD' is not constant at assembly time
error: Assembly aborted (1 error)!
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
5 changes: 3 additions & 2 deletions test/asm/equs-nest.asm
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
X1 equs "Y1 equs \"\\\"Success!\\\\n\\\"\""
Y1 equs "Z1"
; the nested EQUS can't use DEF because Y1 would not be expanded
def X1 equs "Y1 equs \"\\\"Success!\\\\n\\\"\""
def Y1 equs "Z1"
X1
PRINT Z1
3 changes: 3 additions & 0 deletions test/asm/equs-nest.err
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
warning: equs-nest.asm(4): [-Wobsolete]
`Z1 EQUS` is deprecated; use `DEF Z1 EQUS`
while expanding symbol "X1"
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
Loading

0 comments on commit aacb8b5

Please sign in to comment.