[Top][All Lists]

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

Re: [RFC] Syntax for fields with both explicit constraints and initializ

From: Jose E. Marchesi
Subject: Re: [RFC] Syntax for fields with both explicit constraints and initializers
Date: Fri, 05 Mar 2021 10:21:36 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Hi Matt.

> As a solution I propose the following new syntax for struct fields:
> where INITVAL is the default field value that is used if none is
> provided, and EXPR is a constraint expression. Here's how I would
> propose handling the different combinations of INITVAL and EXPR:
> - No INITVAL or EXPR: No change
> - Only INITVAL: No change
> - Only EXPR: No change
> - Both INITVAL and EXPR: INITVAL is treated as only a default value,
> and no implicit constraint is created based on it. The only constraint
> that will exist is the one declared by EXPR. The explicit constraint
> overrides the implicit constraint that would normally be created.
> For example we could make the comp_type field above have a default of 
> COMP_NONE like so:
> ...
> uint<8> comp_type = COMP_NONE : comp_type in [COMP_NONE, COMP_LZO, COMP_ZLIB];
> ...
> and then you can construct a chunk with just:
> var chunk = Chunk {}
> assert(chunk.comp_type == COMP_NONE);
> Thoughts?

I like this solution.

I just just add a little thing: if both INITVAL and EXPR are provided,
then INITVAL should be checked against EXPR.

In other words, this should raise a constraint expression:

    int i = QUUX : i in [FOO, BAR, BAZ];

reply via email to

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