Skip to content

Commit 2536967

Browse files
committed
fix datasize() on last label of struct
1 parent 9baaa4e commit 2536967

2 files changed

Lines changed: 27 additions & 7 deletions

File tree

src/asar/assembleblock.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,6 +1320,14 @@ void cmd_endstruct(char** words, int numwords) {
13201320
structs.create(struct_parent) = parent;
13211321
}
13221322

1323+
// create a fake label for the end, so that datasize() acts nicer on the last label in the struct
1324+
string endname = STR ":endstruct_";
1325+
if(in_sub_struct) {
1326+
endname += struct_parent + ".";
1327+
}
1328+
endname += struct_name;
1329+
setlabel(endname, snespos, static_struct);
1330+
13231331
pop_pc();
13241332
in_struct = false;
13251333
in_sub_struct = false;

tests/datasize.asm

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
1-
;`A9 03 00 A9 F3 7F A9 09 00 00 00 02
2-
;`warnWdatasize_last_label
3-
;`warnWdatasize_exceeds_size
1+
struct wat $0000
2+
.first: skip 5
3+
.last: skip 2
4+
endstruct
5+
46
org $008000
57
main:
68

7-
lda #datasize(my_table) ;3
8-
lda #datasize(other_label) ;0xFFFFFF
9-
lda #datasize(main) ;9
10-
9+
;`A9 03 00
10+
lda #datasize(my_table)
11+
;`A9 F3 7F
12+
;`warnWdatasize_last_label
13+
;`warnWdatasize_exceeds_size
14+
lda #datasize(other_label)
15+
;`A9 09 00
16+
lda #datasize(main)
1117

1218
my_table:
19+
;`00 00 02
1320
db $00, $00, $02
1421
other_label:
22+
23+
;`a9 05
24+
lda #datasize(wat.first)
25+
;`a9 02
26+
lda #datasize(wat.last)

0 commit comments

Comments
 (0)