|
| From: | Egeyar Bagcioglu |
| Subject: | Re: [RFC] Methods and functions |
| Date: | Tue, 5 May 2020 18:24:05 +0200 |
| User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 |
Hi Jose,
*** A couple of restrictions
Given the different nature of the variables, functions and methods, there
are a couple of restrictions:
a) Methods can't access variables and function defined in the struct type.
This is not gratuitous: when you think about the mapping/construction
process, you will note these variables and functions are locals to the
mapper/constructor, which has already been executed at the time we are
in the position to invoke a method!
If you try to access a variable or function defined inside a struct
method, you will get a nice "invalid reference to struct
{variable,function}" error message from the compiler.
I am not sure if I understand this correctly and I am very skeptic about what I understand.
We keep re-mapping structs, right? I tried the following to make sure it works:
(poke) deftype Packet3 = struct { byte magic = 0xab; byte size; defvar real_size = (size == 0xff ? size - 0xff : size + 0x0); byte[real_size] payload; };
(poke) defvar packet3 = Packet3 @ 0#B
(poke) packet3
Packet3 {magic=171UB,size=2UB,payload=[99UB,100UB]}
(poke) packet3.size = 10
(poke) packet3
Packet3
{magic=171UB,size=10UB,payload=[99UB,100UB,101UB,102UB,103UB,104UB,105UB,106UB,97UB,98UB]}
Here, the only connection between the size and the payload is real_size. I am glad to see that the payload is still updated when we change the size.
Still, though, I do not get why we cannot access variables and functions of a struct within its method. They are already defined when we have the methods. Is this really as gratuitous?
Thanks Ege
| [Prev in Thread] | Current Thread | [Next in Thread] |