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>
This commit is contained in:
Will Hawkins
2026-04-27 08:39:40 -04:00
parent f2bd53ce5f
commit 0f0662709e
12 changed files with 698 additions and 565 deletions
+29 -1
View File
@@ -225,10 +225,38 @@ public struct SkipUnlessNodeType: CodeItemMacro {
}
}
public struct MustOr: CodeItemMacro {
public static func expansion(
of node: some FreestandingMacroExpansionSyntax, in context: some MacroExpansionContext
) throws -> [CodeBlockItemSyntax] {
let arguments = node.arguments.indices
var arg_index = arguments.startIndex
let result = node.arguments[arg_index].expression
arg_index = arguments.index(after: arg_index)
let thing = node.arguments[arg_index].expression
arg_index = arguments.index(after: arg_index)
let or = node.arguments[arg_index].expression
return [
CodeBlockItemSyntax(
"""
if let __thing = \(thing) {
\(result) = __thing
} else {
return \(or)
}
""")
]
}
}
@main
struct P4Macros: CompilerPlugin {
var providingMacros: [Macro.Type] = [
RequireResult.self, RequireErrorResult.self, UseOkResult.self, UseErrorResult.self,
RequireNodeType.self, SkipUnlessNodeType.self, RequireNodesType.self,
RequireNodeType.self, SkipUnlessNodeType.self, RequireNodesType.self, MustOr.self,
]
}