-
-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow declaration of data structures #98
Comments
I think that you can pretty much get the same effect with macros.
Yes, sure, it is not very convenient to get the value of a specific field, but that's how I usually do this. |
Does ISSOtm/rgbds-structs do what you want? |
Sjasm has structure support similar to how rgbds-structs works. |
Here's a rough first draft for how structs might be implemented in rgbasm. I'm trying to reuse existing keywords and keep the syntax similar to what's already there. Suggestions welcome.
Inside a RAM section, you can use
I'm not sure about how Another problem: it would be nice to allow Example 1:
This would act like:
Example 2:
This would act like:
|
Honestly, Braces are obviously ineligible, but (single) brackets are fair game. I know it would feel very different from the rest of the syntax, but it's also, in concept, nothing like it anyway. |
There's
I don't think a new block construct like this should use brace-style delimiters unless the others are being changed to do the same, like "nothing like it anyway": eh, it reminds me of |
I prefer RGBDS Structs' use of
Then you could do something like this:
|
Or just |
Something like I'd appreciate if someone could refactor existing WRAM labels into a struct with minimal editing. Like turning this from pokecrystal:
to this:
(That does raise the issue of, " |
I'm worried about the readability of that. There isn't much point in implementing structs if they're going to be that similar, since you might as well just use macros. Our goal should be to break the mold a bit, since RGBDS Structs already does most of this. |
If #635 is merged, this would look fine: struct Substatus [
SubStatus1:: db
SubStatus2:: db
SubStatus3:: db
SubStatus4:: db
SubStatus5:: db
]
wPlayer:: dstruct Substatus |
That looks alright to me. Maybe use double brackets so they stand out more? Presumably it would support |
I don't like that syntax because it fails to convey which is the type and which is the name. Besides, we'd probably also want initializer syntax for ROM data. PlayerData: struct Substatus [
0, 1, 2, 3, 4, ; Allow trailing commas
]
EnemyData: struct Substatus [
Substatus1 = 8, Substatus2 = 7, Substatus3 = 6, Substatus4 = 5, Substatus5 = 4
]
PeonData: struct Substatus [
Substatus4 = NPC_SUBSTAT4 ; Commas or newlines, or both
Substatus2 = HIGH(PEON_CONST), Substatus3 = LOW(PEON_CONST),
... = 0 ; Syntax for default init...
Substatus1 = 69 ; ...not necessarily last
] (RGBDS-structs has a more clunky syntax for initializers, since it's constrained by macro syntax.) |
(I edited those Agreed that a ROM initializer syntax would be useful too. Although I think |
This was being discussed again in the discord so I figured I'd contribute my own idea for syntax:
This will allow the use of macros and doesn't require the user to initialize every value if they don't need to. |
I like that syntax; |
Syntax from WLA-DX for comparison: .STRUCT water
name ds 8
age db
weight dw
.ENDST
.DSTRUCT waterdrop INSTANCEOF water VALUES
name: .db "tingle"
age: .db 40
weight: .dw 120
.ENDST
.STRUCT drop_pair
waterdrops: instanceof water 2
.ENDST
.DSTRUCT drops INSTANCEOF drop_pair VALUES
waterdrops.1: .db "qwertyui" 40
.dw 120
waterdrops.2.name: .db "tingle"
waterdrops.2.age: .db 40
waterdrops.2.weight: .dw 12
.ENDST |
And syntax from NASM: struc mytype
mt_long: resd 1
mt_word: resw 1
mt_byte: resb 1
mt_str: resb 32
endstruc
mystruc:
istruc mytype
at mt_long, dd 123456
at mt_word, dw 1024
at mt_byte, db 'x'
at mt_str, db 'hello, world', 13, 10, 0
iend |
And from ca65: .struct Point
xcoord .word
ycoord .word
.endstruct
P1: .tag Point
P2: .tag Point |
I should probably comment at this point that ("What do they do", I hear? |
If we come across a third use case, maybe I'll push to actually implement Edit: Hmm. I think even with |
Definition:
foo_struct: STRUCT foo, bar
Declaration:
foo_struct Name, $01, $2345
Use:
dbw Name.foo, Name.bar
The text was updated successfully, but these errors were encountered: