Tomasz, please take a look at the small template below
macro datatypes types*&
irp <n, type>, types
macro type args:[?]&
match [?], args
emit n: ?
else match [x], args
emit n: x dup ?
else match [x] value, args
match =, v, value
emit n: x dup ?, v
else
emit n: x dup value
end match
else
irp arg, args
if arg eqtype ''
emit n: arg
else
local value
value = +arg
emit n: value
end if
end irp
end match
type.__size = n
datatype.type equ ::type::
end macro
struc (name) type args&
label .: n
type args
name.__size = n
name.__length = $ - .
end struc
end irp
end macro
datatypes 1,byte?, 2,word?, 4,dword?, 6,fword?, 8,qword?, 10,tbyte?, 16,oword?
macro log.number num
local n, s
n = +num
if n = 0
s = '0'
else
s = 0
while n > 0
s = s shl 8 + (n mod 10 + '0')
n = n / 10
end while
end if
display string s,13,10
end macro
;------------ ^^ just helpers above to compile --------------
macro struct? structname
macro end?.struct?!
end namespace
irp arg, args
match p:v, arg
log.number .p.__size
end match
end irp
end struc
virtual at 0
structname structname
structname.__size = $
end virtual
purge end?.struct?
end macro
struc (name) structname args&
label .: structname.__size
namespace .
name.__size = structname.__size ;<<<<<<< problem line
end macro
struct POINT
x word
y byte
end struct
struct POINT2
z POINT
end struct
my POINT2 z.x:1, z:1
I'm trying to get the size of a variable defined as structure. Variable, not structure itself, because later it will be an array of structures.
The problem is when I add
name.__size = structname.__size
I start getting the following error:
Processed: label .: POINT.__size
Error: symbol '__size' is undefined or out of scope.
However, both sizes are logged correctly. If line is removed, label .: POINT.__size doesn't generate the error any more.
I thought that it could be processing order, and structname.__size is not initialized yet, when name.__size appears in code, but I guess it would then fail on that very line. Thanks in advance for your assistance!