[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [SUGGESTION] Pretty-printing custom unit types
From: |
Jose E. Marchesi |
Subject: |
Re: [SUGGESTION] Pretty-printing custom unit types |
Date: |
Mon, 11 Jul 2022 15:53:14 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
> 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?
No, it would not.
> 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. :-)
Hmm, so you are suggesting to expand both the boxed offset PVM values
_and_ the boxed offset types PVM values in order to hold an unit name?
> /* 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};