mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Implement [[ fragment literals ]] (#1614)
This feature is referred to as "code/data literals" in ASMotor, and simply as "literals" in some older assemblers like MIDAS for the PDP-10. RGBASM already had the "section fragments" feature for keeping disparate contents together when linked, so these worked naturally as "fragment literals".
This commit is contained in:
@@ -1,15 +1,15 @@
|
||||
error: code-after-endm-endr-endc.asm(6):
|
||||
syntax error, unexpected PRINTLN, expecting end of line or end of buffer
|
||||
syntax error, unexpected PRINTLN, expecting end of line or end of buffer or end of fragment literal
|
||||
error: code-after-endm-endr-endc.asm(7):
|
||||
Macro "mac" not defined
|
||||
error: code-after-endm-endr-endc.asm(12):
|
||||
syntax error, unexpected PRINTLN, expecting end of line or end of buffer
|
||||
syntax error, unexpected PRINTLN, expecting end of line or end of buffer or end of fragment literal
|
||||
error: code-after-endm-endr-endc.asm(17):
|
||||
syntax error, unexpected PRINTLN, expecting end of line
|
||||
error: code-after-endm-endr-endc.asm(19):
|
||||
syntax error, unexpected PRINTLN, expecting end of line or end of buffer
|
||||
syntax error, unexpected PRINTLN, expecting end of line or end of buffer or end of fragment literal
|
||||
error: code-after-endm-endr-endc.asm(23):
|
||||
syntax error, unexpected PRINTLN, expecting end of line
|
||||
error: code-after-endm-endr-endc.asm(25):
|
||||
syntax error, unexpected PRINTLN, expecting end of line or end of buffer
|
||||
syntax error, unexpected PRINTLN, expecting end of line or end of buffer or end of fragment literal
|
||||
Assembly aborted with 7 errors!
|
||||
|
||||
14
test/asm/fragment-literal-in-load.asm
Normal file
14
test/asm/fragment-literal-in-load.asm
Normal file
@@ -0,0 +1,14 @@
|
||||
SECTION "OAMDMACode", ROM0
|
||||
OAMDMACode:
|
||||
LOAD "hOAMDMA", HRAM
|
||||
hOAMDMA::
|
||||
ldh [$ff46], a
|
||||
ld a, 40
|
||||
jp [[
|
||||
: dec a
|
||||
jr nz, :-
|
||||
ret
|
||||
]]
|
||||
.end
|
||||
ENDL
|
||||
OAMDMACodeEnd:
|
||||
2
test/asm/fragment-literal-in-load.err
Normal file
2
test/asm/fragment-literal-in-load.err
Normal file
@@ -0,0 +1,2 @@
|
||||
FATAL: fragment-literal-in-load.asm(7):
|
||||
`LOAD` blocks cannot contain fragment literals
|
||||
9
test/asm/fragment-literal-in-ram.asm
Normal file
9
test/asm/fragment-literal-in-ram.asm
Normal file
@@ -0,0 +1,9 @@
|
||||
SECTION "RAM", WRAM0
|
||||
|
||||
wFoo:: db
|
||||
wBar:: ds 3
|
||||
println "ok"
|
||||
wQux:: dw [[
|
||||
ds 4
|
||||
println "inline"
|
||||
]]
|
||||
2
test/asm/fragment-literal-in-ram.err
Normal file
2
test/asm/fragment-literal-in-ram.err
Normal file
@@ -0,0 +1,2 @@
|
||||
FATAL: fragment-literal-in-ram.asm(6):
|
||||
Section 'RAM' cannot contain fragment literals (not ROM0 or ROMX)
|
||||
1
test/asm/fragment-literal-in-ram.out
Normal file
1
test/asm/fragment-literal-in-ram.out
Normal file
@@ -0,0 +1 @@
|
||||
ok
|
||||
5
test/asm/fragment-literal-in-union.asm
Normal file
5
test/asm/fragment-literal-in-union.asm
Normal file
@@ -0,0 +1,5 @@
|
||||
SECTION UNION "U", ROM0
|
||||
db $11
|
||||
dw [[ db $22 ]]
|
||||
SECTION UNION "U", ROM0
|
||||
db $33
|
||||
2
test/asm/fragment-literal-in-union.err
Normal file
2
test/asm/fragment-literal-in-union.err
Normal file
@@ -0,0 +1,2 @@
|
||||
FATAL: fragment-literal-in-union.asm(3):
|
||||
`SECTION UNION` cannot contain fragment literals
|
||||
62
test/asm/fragment-literals.asm
Normal file
62
test/asm/fragment-literals.asm
Normal file
@@ -0,0 +1,62 @@
|
||||
SECTION "1", ROM0[0]
|
||||
|
||||
DEF VERSION EQU $11
|
||||
GetVersion::
|
||||
ld a, [ [[db VERSION]] ]
|
||||
ret
|
||||
|
||||
SECTION "2", ROM0, ALIGN[4]
|
||||
|
||||
MACRO text
|
||||
db \1, 0
|
||||
ENDM
|
||||
|
||||
MACRO text_pointer
|
||||
dw [[
|
||||
text \1
|
||||
]]
|
||||
ENDM
|
||||
|
||||
GetText::
|
||||
ld hl, [[
|
||||
dw [[ db "Alpha", 0 ]]
|
||||
dw [[
|
||||
text "Beta"
|
||||
]]
|
||||
text_pointer "Gamma"
|
||||
dw 0
|
||||
]]
|
||||
ld c, a
|
||||
ld b, 0
|
||||
add hl, bc
|
||||
add hl, bc
|
||||
ld a, [hli]
|
||||
ld h, [hl]
|
||||
ld l, a
|
||||
ret
|
||||
|
||||
SECTION "C", ROM0
|
||||
|
||||
Foo::
|
||||
call [[ jp [[ jp [[ ret ]] ]] ]]
|
||||
call [[
|
||||
Label::
|
||||
call GetVersion
|
||||
DEF MYTEXT EQU 3
|
||||
ld a, MYTEXT
|
||||
call GetText
|
||||
ld b, h
|
||||
ld c, l
|
||||
ret
|
||||
]]
|
||||
jp [[
|
||||
Bar:
|
||||
inc hl
|
||||
.loop
|
||||
nop
|
||||
: dec l
|
||||
jr nz, :-
|
||||
dec h
|
||||
jr nz, .loop
|
||||
ret
|
||||
]]
|
||||
BIN
test/asm/fragment-literals.out.bin
Normal file
BIN
test/asm/fragment-literals.out.bin
Normal file
Binary file not shown.
@@ -7,5 +7,5 @@ error: syntax-error-after-syntax-error.asm(6):
|
||||
error: syntax-error-after-syntax-error.asm(9):
|
||||
syntax error, unexpected :
|
||||
error: syntax-error-after-syntax-error.asm(10):
|
||||
syntax error, unexpected stop, expecting end of line or end of buffer or ::
|
||||
syntax error, unexpected stop, expecting end of line or end of buffer or end of fragment literal or ::
|
||||
Assembly aborted with 5 errors!
|
||||
|
||||
Reference in New Issue
Block a user