poke-devel
[Top][All Lists]
Advanced

[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: Fri, 08 Jul 2022 20:43:06 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> When pretty-printing, poke doesn't use the original unit name of struct 
> fields:
>
> #!!# unit U32bits = 4*8;
> #!!# type Foo = struct { offset< int, U32bits> how_many; };
> #!!# Foo{}
> Foo {
>   how_many=0x0#32
> }
> Here it prints #32 instead of #U32bits.
>
> If how_many was an offset<int, B> it would however print how_many=0x0#B
>
> Is this something we can fix without too much work?

Good suggestion... and it is already in the todo! :D

I even have a sketch of a design.  I would avoid making the PVM aware of
unit names (keeping it as simple as possible is important.)

So instead I would make it part of the run-time.  Basically, the
run-time (rt.pk) will define an array:

 var _pkl_unit_names = Pkl_Unit_Name[]();

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!

Fun to implement :)



reply via email to

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