Commit Graph

28 Commits

Author SHA1 Message Date
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 3d4d26d07b Make Formatter Happy
Continuous Integration / Library Format Tests (push) Has been cancelled
Continuous Integration / Grammar Tests (push) Failing after 1m30s
Continuous Integration / Library Tests (push) Failing after 8s
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-05-04 10:34:33 -04:00
Will Hawkins 168d48fa7c compiler, runtime: Refactor Errors
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-05-04 10:34:07 -04:00
Will Hawkins b49ec104e9 compiler, runtime: Make Default Values Optional
For types, make it optional to return a default value. While default
values for some types are meaningful, they are not meaningful for all
types (e.g., Action, Control, Parser, Parser state, etc.).

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-05-04 08:35:33 -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 0f0662709e compiler, testing: Build System for Compilation
The compilation code was written as a precursor for implementation
with macros. The updates in this commit make the switch.

There is still plenty to do:

1. Comment Walker.
2. Comment Macros.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-27 08:39:40 -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 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 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 cd26d1d22c Parse Struct Declarations
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-27 03:33:15 -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 aac007f1f2 Allow Declaring Instances of Structs
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 4c63e7f92a Make Formatter Happy
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-13 08:27:41 -04:00
Will Hawkins 377f40447f Add update Methods for Compilation Context
update method will allow the creation of a new compilation context
based on the current one with new types/names.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-13 07:03:31 -04:00
Will Hawkins 2f7d05a3fd Refactor Compilation Interface
Compilation interface(s) now contain a compilation context.
The change will make it easier to expand on what each step
of the compilation process needs to know to complete its task
without having to make major changes to the interface.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-13 06:25:30 -04:00
Will Hawkins 4269104379 Refactor Parser Interfaces
Do not pass around the MutableTree -- now that we are not
using queries for walking the AST, it is unnecessary.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-10 05:52:04 -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 59d56e7b73 Make Formatter Happy
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-02 08:26:37 -05:00
Will Hawkins 6dba17c97a Refactor Parsing -> Compiling
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-02 08:25:29 -05:00