flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > [fasmg] get this struc name |
Author |
|
zhak 16 Feb 2017, 19:12
Ah, I found this in documentation. struc should be defined with (name) special param
|
|||
16 Feb 2017, 19:12 |
|
Tomasz Grysztar 16 Feb 2017, 19:26
The special "(name)" parameter is only necessary when you need the actual text of the parameter (for example when you plan to convert it to string with "`name" or match it with some other text). If you only need to refer to the label, use a lone dot, just as it fasm 1:
Code: label . : byte |
|||
16 Feb 2017, 19:26 |
|
zhak 16 Feb 2017, 20:04
Well, while studying the engine, I'm trying to create a struct macro with the ability to partially define elements of the structure.
For now I came up with the following solution: Code: macro struct? name, alignment macro end?.struct?! end namespace local param, value, indx, is_seq param equ value equ indx = 0 is_seq = false irp arg, args match a: <x>, arg if is_seq = false param equ a value equ x indx = 0 else err err_struc end if else match a: <x, arg if is_seq = false param equ a value equ x indx = 0 is_seq = true else err err_struc end if else match a: x, arg if is_seq = false param equ a value equ x indx = 0 else err err_struc end if else match x>, arg if is_seq = true is_seq = false indx = indx + 1 value equ x else err err_struc end if else match x, arg if is_seq = true indx = indx + 1 value equ x else err err_struc end if end match match name, param local length match type v, value virtual at 0 type v length = $ load value:length from 0 end virtual else if value eqtype '' length = lengthof value else length = .name.__size end if if length <= (.name.__length / .name.__size - indx) * .name.__size store value:length at .name + .name.__size * indx indx = indx + length / .name.__size - 1 else err err_struc_value_range end if end match end irp end struc virtual at 0 name name sizeof.name = $ end virtual purge end?.struct? end macro struc name args& match =align? x, alignment align x end match label .:sizeof.name namespace . end macro For this I added custom data types declarations: Code: macro dword? args:[1]& match [?], args dd ? else match [n], args dd n dup ? else match [n] value, args match =, v, value dd n dup ?, v else dd n dup value end match else dd args end match .__size = 4 .__length = $ - . end macro struc dword? args& label . dword args end struc struc uint32? args& align 4 label . dword args end struc (Decided not to overwrite standard data declaration types) This allows declaring data as Code: a int32 ; the same as rd 1 b int32 [4] ; the same rd 4 c int32 [2] 5, 6 ; the same db 2 dup 5, 6 etc. and structures like Code: struct MY_STRUCT a int32 [2] b int32 end struct my x:<'1234', 2>, y:3 but I find accessing data size and length with __ prefixed variables not very attractive. What is more, it doesn't yet allow expressions in arguments like (3-2), so experimenting to find some more beautiful solution. Maybe something with `element` to access params in a way similar to original `sizeof data` notation but in struc's namespace only |
|||
16 Feb 2017, 20:04 |
|
Tomasz Grysztar 16 Feb 2017, 20:15
I strongly suggest to use the label size metadata to store the size of every entity, for example:
Code: struc dword? args& label . : dword dword args end struc |
|||
16 Feb 2017, 20:15 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.