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>
This commit is contained in:
Will Hawkins
2026-05-15 08:14:20 -04:00
parent f1f20e96a2
commit 12fa43d9f9
7 changed files with 678 additions and 18 deletions
+8
View File
@@ -73,6 +73,14 @@ public func Map<T, U>(input: T, block: (T) -> U) -> U {
return block(input)
}
public func Fold<T, A>(input: [T], initial: A, block: (T, A) -> A) -> A {
var result = initial
for i in input {
result = block(i, result)
}
return result
}
@freestanding(expression) public macro RequireOkResult<T>(_: Result<T>) -> Bool =
#externalMacro(module: "Macros", type: "RequireResult")
@freestanding(expression) public macro RequireErrorResult<T>(