There were significant overlaps in the names of data structures
between the compiler and the language that made it necessary
to litter the code with P4Lang.xxxx. This refactor removes that
requirement in most places (Parser is ambiguous wherever TreeSitter
is used -- cannot avoid that!)
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
In P4, parsers are considered types. Those parsers are instantiated.
The instantiated parsers are values. Previously, gp4 treated a parser
type and a parser value as identical. This PR makes that difference
clear _and_ sets the stage for the future.
TODO: Make the same distinction between control and action types and
values.
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
Parameterize Runtime (nee ParserRuntime) so that it can run anything
that is LibraryCallable. TODO: Refactor its API -- left mostly as
it was because changing unit tests will be laborious.
Centralize the execution of statements and evaluation of expressions
so that the user can specify a debugging "callback" after every
execution/evaluation.
The callback can be used for myriad things, but it seems likely that
it will be useful for implementing:
1. Testing
2. Debugger
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
When a function is called, if there is an (in)out parameter,
make sure that updated values are propogated to the calling
function.
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
The type system (and the value system) now include attributes
for each type (things like direction, const-ness).
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
Add support for directions on parameters and attributed types. The
latter is necessary to support the former, but is not limited to
the direction use case. An attributed type is a P4 type with attributes
(like its direction, whether it is read only, etc.) Other attributes
will be added in the future.
Changes necessary to support attributed types include:
1. Global instances tracked during compilation are not attributed
types and not simply types.
2. (future) Type checking will have to make sure that a types
attributes do not affect type compatibility.
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
Refactor the class hierarchy for parser states so that
there is a parser state that acts more like a type and
one that acts more like a value (the latter, then, serves
as the base class for the other instantiated parser states).
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>