poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: assert() inside type x = struct { ...


From: Jose E. Marchesi
Subject: Re: assert() inside type x = struct { ...
Date: Sat, 09 Apr 2022 14:51:28 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> Hi.
>
> On Fri, Apr 08, 2022 at 05:12:24PM +0200, Jose E. Marchesi wrote:
>> 
>> > Is it intentional that assert() does not work inside type definitions like 
>> > this?
>> >
>> > type foo = struct { string yo; };
>> > type x = struct {
>> >   uint<8> len;
>> >   union {
>> >     foo myfoo;
>> >     byte[len] unknown;
>> >   } payload;
>> >   assert(payload'size'magnitude/8 == len);
>> > };
>> 
>> Statements inside struct types are not supported, no.
>> Only declarations.
>> 
>
> What do you think about chaning the `format` to be an expression of type
> `int`?
> That way users can do something like this:
>
> ```poke
> struct
> {
>   int field1;
>   int field2;
>   
>   var a_descriptive_variable_name = assert (some_condition, "...");
> };
>
> ```
>
> If you agree with this, I can send the patch.


I wouldn't object to that.  Then you could write in constraint
expressions things like:

struct
{
  int foo : foo in [0, 1] || assert (0);
}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]