Commit Graph

46 Commits

Author SHA1 Message Date
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 d39127ac17 Support Function Calls
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-04-09 23:16:27 -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 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 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 3b9c3a7076 Add Select Expression Tests
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-30 05:18:00 -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 cd26d1d22c Parse Struct Declarations
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-27 03:33:15 -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 0d1a0b11df Add Binary Operator and Grouping (in Expressions) Tests
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-23 07:55:37 -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 f0d816b99f Refactor Names of Scope Types
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-20 04:29:44 -04:00
Will Hawkins 0aef385afc Refactor Tests
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-20 04:29:44 -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 0b4db34177 Initial Array Access Implementation
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-13 09:45:03 -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 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 4e9927c601 Add Tree Sitter Tests for Annotations (And General Test Updates)
Update Tests

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-10 05:52:04 -04:00
Will Hawkins f82c69e4f9 Add Tests For Unsupported Features
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-10 05:52:04 -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 eff19df968 Completely Refactor Execution
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-06 21:40:19 -05:00
Will Hawkins c3b3be77eb Update Compiler To Use Macros
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-03-06 08:02:35 -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 cfe78a9b29 Semicolon Cleanup
1. Semicolons were required in the wrong spot.
2. Make semicolons "invisible" (from the tree-sitter perspective).

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-02-27 08:23:27 -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
Will Hawkins a2335a01ed Initial Support For If Statements
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-02-24 06:08:12 -05:00
Will Hawkins 64a0fe4255 Refactor Parsing/Runtime
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-02-24 00:28:41 -05:00
Will Hawkins d9c8c5aeb0 Refactor Runtime
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-02-19 22:50:19 -05:00
Will Hawkins 3693bdc02d Start Evaluation
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-02-10 03:37:57 -05:00
Will Hawkins 90135d7f24 Rename Package to p4rse
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-02-06 07:48:05 -05:00
Will Hawkins c3fdfb62e8 Refactor Type System
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-02-06 07:46:18 -05:00
Will Hawkins 989c9b1212 Refactor
Refactor into four major components:

1. Common: Things shared among all other components.
2. Lang: P4-language-related components.
3. Runtime: Components required to run a P4 program.
4. Parser: Components for parsing a P4 program from source.

Other components:

1. Macros
2. Tests
3. TreeSitterExtensions: Extra tree sitter functionality

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-02-03 08:22:58 -05:00
Will Hawkins 1203c0c90a Improve Parsing of P4 Parsers And Continue Runtime Implementation
1. Parsing of P4 Parsers was broken: Multiple local elements and
statements were not allowed.
2. Support more functionality on scopes.
3. Refactor variable/identifier.
4. Add more tests.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-01-30 08:33:40 -05:00
Will Hawkins 23b775bf4f Conditionally Support CustomStringConvertible on Result
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-01-30 08:33:40 -05:00
Will Hawkins 995abcc470 Add License Information
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-01-23 23:51:49 -05:00
Will Hawkins d6d5cc8df7 Runtime Work
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-01-23 23:30:28 -05:00
Will Hawkins 4bec71dcf4 Refactor Library And Start Runtime
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-01-20 07:10:58 -05:00
Will Hawkins 08beba6cb1 Initial Commit
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-01-14 12:49:49 -05:00