[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [SUGGESTION] Pretty-printing custom unit types
|
From: |
apache2 |
|
Subject: |
Re: [SUGGESTION] Pretty-printing custom unit types |
|
Date: |
Mon, 11 Jul 2022 14:36:35 +0200 |
|
User-agent: |
Mutt/1.9.3 (2018-01-21) |
On Fri, Jul 08, 2022 at 08:43:06PM +0200, Jose E. Marchesi wrote:
>
> > Here it prints #32 instead of #U32bits.
> >
> > If how_many was an offset<int, B> it would however print how_many=0x0#B
> >
>
> which will be an array of structs with pairs (ULONG, STR). This array
> will be used as a stack using the currently available operations we
> have.
>
> When the compiler generates code for an `unit FOO=666' construction, it
> will include code to push an entry {FOO, 666} in the _pkl_unit_names
> stack.
>
> The printers and formatters will then be able to traverse the
> _pkl_unit_names array (via calls to functions in rt.pk) in order to find
> the name of units.
>
> When the compiler generates code for an end of scope where an unit is
> defined (such as the end of a compound statement) it will pop the top of
> the unit_names stack, which will be guaranteed to be the unit in
> question!
>
Hmm, maybe I'm not understanding it correctly, but would this correctly handle
multiple units with the same size being interleaved in a struct?
I would have thought that to cover this comprehensively we would have to add a
tag field to the unit type struct, but I'm happy to stand corrected if you
have a more elegant solution. :-)
/* Example: */
#!!# unit Foo = 4;
#!!# unit Bar = 4;
#!!# type X = struct { offset<int, Foo> a; offset<int, Bar> b; offset<int, Foo>
c; };
#!!# X{}
X {
a=0x0#N,
b=0x0#N,
c=0x0#N
}
/* should be: */
X {
a=0x0#Foo,
b=0x0#Bar,
c=0x0#Foo
}
/* we need to remember to handle the error messages too: */
#!!# X{a=1,b=2,c=3}
<stdin>:1:5: error: invalid initializer for `a' in constructor
<stdin>:1:5: error: expected offset<int,4>, got int<32>
X{a=1,b=2,c=3};