Commit Graph

182 Commits

Author SHA1 Message Date
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 b934089fe7 common: Add a Table Hit/Miss Value/Type
When support for enums is added, we can replace this one-off.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-30 18:38:40 -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 b97aa1af72 parser, compiler: Support Table Actions
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 05:38:29 -04:00
Will Hawkins 833979a5c9 Make Formatter Happy
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-27 09:15:31 -04:00
Will Hawkins 75da49ba7e documentation: Rename Project (2)
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-27 09:10:47 -04:00
Will Hawkins 0012963361 documentation: Rename Project
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-27 09:08:07 -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 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 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 74fead1eba grammar: Parse externs
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 47cc52ea44 documentation: Correct typo
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-20 06:00:52 -04:00
Will Hawkins 5a9ef6ce4d documentation: Describe NOTEs
Describe how/why notes are used in the code.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-20 05:59:27 -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 1847df7fab compiler: Actions Have BlockStatements for Bodies
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-20 03:35:44 -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 5bc9db9aca compiler, common, testing: Support For Checking For Invalid Statements
Add support functions to check whether a (block of) statement(s) contains
any statements that should not appear in that block (e.g., switch in
an action).

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-20 03:25:58 -04:00
Will Hawkins a3a06efdb4 grammar: Make apply statements have block bodies
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-20 03:25:07 -04:00
Will Hawkins 95c489ecd7 grammar: Refactor apply Grammar
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-20 02:39:33 -04:00
Will Hawkins 902dc945fd grammar: Add apply to control declaration
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-20 02:27:36 -04:00
Will Hawkins 6cb28bc873 grammar: Add exit statement
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-20 02:27:08 -04:00
Will Hawkins fa1f694d76 grammar: Hide the return keyword in the grammar
And, add a grammar test for the return keyword.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-20 02:25:28 -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 9669a99dfc Documentation: README: Describe commit message headline format
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-13 06:23:23 -04:00
Will Hawkins fcb3b4e304 Grammar: parameter_list: Refactor and Add Tests
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-13 04:58:43 -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 708f65a0a9 Make Formatter Happy
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-06 08:50:20 -04:00
Will Hawkins 68ee5b1067 P4Lang/Program/InstancesWithTypes and TypesWithTypes
Add helper functions to fetch globally instantiated/declared
parser/controls (etc) and types in a user's P4 program.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-06 08:49:35 -04:00
Will Hawkins 29dfa62472 Start Handling Control Blocks
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-06 08:49:28 -04:00
Will Hawkins 443b21b890 Initial Work on Compiling Function Declarations
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-02 02:49:04 -04:00
Will Hawkins fc0276ad42 Support Parsing Function Declarations
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-02 02:48:43 -04:00
Will Hawkins 07f1943611 Fix Warnings In Tests
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-02 01:30:33 -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 7cdbee1999 Refactor Parser For Parameter Lists
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-02 01:28:27 -04:00
Will Hawkins 8962235aca Support Parameters For Parsers
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-30 07:57:41 -04:00
Will Hawkins 744c375c5f Add Select Expression Ordering Test
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-30 05:18:36 -04:00
Will Hawkins 8299d76285 Make Formatter Happy
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-30 05:18:11 -04:00