Commit Graph

54 Commits

Author SHA1 Message Date
Will Hawkins 44e93e4cda compiler, runtime: Begin Runtime Refactor
Continuous Integration / Grammar Tests (push) Failing after 39s
Continuous Integration / Library Format Tests (push) Successful in 1m46s
Continuous Integration / Library Tests (push) Successful in 4m38s
Ultimately, the goal is to completely separate the compilation from
the runtime to make it possible to have the interpreter/evaluator
be "just another" entity that can perform meaningful work when
given a parsed GP4 program.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-05-29 08:41:54 -04:00
Will Hawkins c8d4d4fc65 compiler: Remove Too-Early Instatiation Reference
Continuous Integration / Grammar Tests (push) Successful in 38s
Continuous Integration / Library Format Tests (push) Successful in 1m41s
Continuous Integration / Library Tests (push) Failing after 4m29s
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-05-27 13:22:59 -04:00
Will Hawkins 294f76acd4 compiler: Refactor Compiler To Remove Ambiguities
Continuous Integration / Grammar Tests (push) Successful in 39s
Continuous Integration / Library Format Tests (push) Successful in 1m51s
Continuous Integration / Library Tests (push) Failing after 4m44s
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>
2026-05-27 12:59:29 -04:00
Will Hawkins 61d8f601e8 compiler, language, runtime: Separate Parser Type From Instances
Continuous Integration / Grammar Tests (push) Successful in 4m2s
Continuous Integration / Library Format Tests (push) Successful in 5m0s
Continuous Integration / Library Tests (push) Successful in 8m1s
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>
2026-05-27 05:41:23 -04:00
Will Hawkins 3cff82fd5c runtime: Remove Too-Soon Dependency on Protobuf Work
Continuous Integration / Grammar Tests (push) Successful in 4m18s
Continuous Integration / Library Format Tests (push) Successful in 7m30s
Continuous Integration / Library Tests (push) Successful in 10m36s
Continuous Integration / Cli Tests (push) Successful in 7m7s
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-05-18 23:38:12 -04:00
Will Hawkins a7d8fd1304 grammar,compiler: Add Support For Fixed-Width Integers
Continuous Integration / Grammar Tests (push) Successful in 4m13s
Continuous Integration / Library Format Tests (push) Successful in 5m17s
Continuous Integration / Library Tests (push) Failing after 8m34s
Continuous Integration / Cli Tests (push) Failing after 4m40s
Distinguishing between signed and unsigned fixed-width integer
types must still be done.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-05-18 06:53:22 -04:00
Will Hawkins 12fa43d9f9 common, codegen: Implement Visitor And Use For CodeGen
Continuous Integration / Grammar Tests (push) Successful in 4m6s
Continuous Integration / Library Format Tests (push) Successful in 5m5s
Continuous Integration / Library Tests (push) Successful in 9m0s
Continuous Integration / Cli Tests (push) Successful in 4m57s
Implement a generic visitor for components of a P4 program and use
it to start P4 code generation (according to the behavioral model).

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-05-15 08:14:24 -04:00
Will Hawkins 7c660b2b0c compiler, runtime: Refactor P4Type to P4QualifiedType
Also, refer to the different pieces of the qualified type as
qualifiers and not attributes.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-05-04 07:29:51 -04:00
Will Hawkins a84e778e79 Make Formatter Happy
Continuous Integration / Grammar Tests (push) Has been cancelled
Continuous Integration / Library Tests (push) Has been cancelled
Continuous Integration / Library Format Tests (push) Has been cancelled
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-30 18:41:01 -04:00
Will Hawkins ed976c7855 compiler, runtime: Initial Support For Calling Controls
Support calling (invoking) a Control. There is still plenty more to
do here, but we are off to a good start.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-30 18:39:52 -04:00
Will Hawkins bd262e5b73 runtime: Parameterize Runtime
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.
2026-04-30 18:37:21 -04:00
Will Hawkins 8c0c16ed87 documentation: Update Note Protocol
Using /// rather than simply //.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-27 09:03:59 -04:00
Will Hawkins f2bd53ce5f compiler, runtime, common: (Initial) Support For extern Declarations
Especially FFI

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-23 06:07:54 -04:00
Will Hawkins a2d6aa0e28 runtime: Refactor ExecutionEvaluator
Move as much of the common functionality of executing a block
of statements into a common area as possible.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-23 06:07:54 -04:00
Will Hawkins 99d3d2bace Make Formatter Happy
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-20 16:29:59 -04:00
Will Hawkins a24571222b runtime: Refactor Expression/Statement Evaluators
Allow the user to customize the evaluation/execution of expressions/
statements with something that implements functions that perform
those tasks. This additional functionality will make it possible for
the "classic" evaluator not to waste time checking for the presence
of interlopers and give implementers additional customization opportunities.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-20 16:28:07 -04:00
Will Hawkins 78a53d388f runtime: Remove extraneous print
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-20 05:55:07 -04:00
Will Hawkins 883b4127e8 Make Formatter Happy
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-20 05:54:00 -04:00
Will Hawkins d33066c543 compiler, runtime, testing, common: Centralize Execution/Evaluation
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>
2026-04-20 05:53:43 -04:00
Will Hawkins c6f086f67f compiler, runtime: Control Declarations Have Apply Statements
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-20 03:35:55 -04:00
Will Hawkins f687353326 compiler, runtime: Evaluate Expressions in Expression Statements
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-20 03:35:00 -04:00
Will Hawkins 23e0bf5de3 Make Formatter Happy
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-16 06:59:50 -04:00
Will Hawkins 82c125e4d1 compiler, runtime, common: Support (in)out Parameters
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>
2026-04-16 06:58:45 -04:00
Will Hawkins 94086c8e17 compiler, runtime, common, documentation: Refactor Type System
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>
2026-04-14 20:25:11 -04:00
Will Hawkins 35b2537754 compiler, runtime, common, testing: Support Directions on Parameters and Attributed Types
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>
2026-04-13 06:25:08 -04:00
Will Hawkins b687454389 Refactor Expected Types During Compilation
By adding an expected type to the compilation context, it is
now possible for type checking to occur on keyset expressions
and return statements at the moment that they are being compiled.

Previously, it was necessary to tentatively compile them and then
typecheck afterward.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-10 00:59:11 -04:00
Will Hawkins ad7e5a6f6d Make Formatter Happy
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-09 23:17:18 -04:00
Will Hawkins d39127ac17 Support Function Calls
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-09 23:16:27 -04:00
Will Hawkins d971aab1fe Support Calling Parsers With Parameters
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-02 01:28:43 -04:00
Will Hawkins 8299d76285 Make Formatter Happy
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-30 05:18:11 -04:00
Will Hawkins 7c9ecc2438 Refactor Parser States
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>
2026-03-30 05:16:48 -04:00
Will Hawkins 4d787394cd Fix Bug In Struct Field Initialization
Fields were not given default values when a struct was declared
without initializers.

Also, cleanup code in the helper function for binary operations
on struct instances.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-27 03:54:44 -04:00
Will Hawkins 99804e3053 Better Support For Keysets
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-27 01:36:38 -04:00
Will Hawkins fafc80553e Support Binary Math Operators
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-26 23:48:39 -04:00
Will Hawkins 12ec6a77ed Make Formatter Happy
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-23 12:48:52 -04:00
Will Hawkins 2861a82777 Implement Binary Operators and Grouping (in Expressions)
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-23 07:55:11 -04:00
Will Hawkins 6ff7c5175d Make Formatter Happy
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-20 04:30:07 -04:00
Will Hawkins f0d816b99f Refactor Names of Scope Types
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-20 04:29:44 -04:00
Will Hawkins 04627f20e2 Support Setting Arrays/Fields
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-20 04:29:37 -04:00
Will Hawkins 2fd5ecf8d6 Work On Derived Types
1. Add support for field access
2. Add support for proper type checking of array access
3. Add tests for nested field and array access

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-16 08:31:16 -04:00
Will Hawkins 75f9f68349 Make Formatter Happy
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-13 09:45:43 -04:00
Will Hawkins 0b4db34177 Initial Array Access Implementation
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-13 09:45:03 -04:00
Will Hawkins 4c63e7f92a Make Formatter Happy
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-13 08:27:41 -04:00
Will Hawkins d323434787 Begin Implementation of Binary Operator Support
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-13 08:26:47 -04:00
Will Hawkins 271092359c Make Formatter Happy
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-10 05:53:11 -04:00
Will Hawkins 3188b52965 Refactor Parsers and Parser States
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-10 03:56:18 -04:00
Will Hawkins 81b9345c7f Make Formatter Happy
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-06 21:40:37 -05:00
Will Hawkins eff19df968 Completely Refactor Execution
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-06 21:40:19 -05:00
Will Hawkins 6dba17c97a Refactor Parsing -> Compiling
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-02 08:25:29 -05:00
Will Hawkins 2c5bfc3e1c Start Moving Away From Queries
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-02-27 06:16:14 -05:00