compiler, runtime: Begin Runtime Refactor
Ultimately, the goal is to completely separate the compilation from the runtime to make it possible to have the interpreter/evaluator be "just another" entity that can perform meaningful work when given a parsed GP4 program. Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
@@ -439,11 +439,36 @@ public struct CliTestDeclarationMacro: PeerMacro, Sendable {
|
||||
}
|
||||
}
|
||||
|
||||
public struct DeriveCompilableStatement: PeerMacro, Sendable {
|
||||
public static func expansion(
|
||||
of node: AttributeSyntax,
|
||||
providingPeersOf declaration: some DeclSyntaxProtocol,
|
||||
in context: some MacroExpansionContext
|
||||
) throws -> [DeclSyntax] {
|
||||
|
||||
let type_name = declaration.cast(ExtensionDeclSyntax.self).extendedType
|
||||
let implementation = DeclSyntax(
|
||||
"""
|
||||
extension VariableDeclarationStatement: CompilableStatement {
|
||||
public static func CompileStatement(
|
||||
node: Node, withContext context: CompilerContext
|
||||
) -> Result<P4Statement> {
|
||||
return switch Compile(node: node, withContext: context) {
|
||||
case .Ok(let res): .Ok(res)
|
||||
case .Error(let e): .Error(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
""")
|
||||
return [implementation]
|
||||
}
|
||||
}
|
||||
|
||||
@main
|
||||
struct P4Macros: CompilerPlugin {
|
||||
var providingMacros: [Macro.Type] = [
|
||||
RequireResult.self, RequireErrorResult.self, UseOkResult.self, UseErrorResult.self,
|
||||
RequireNodeType.self, SkipUnlessNodeType.self, SkipUnlessNodesTypes.self, RequireNodesType.self,
|
||||
MustOr.self, CliTestDeclarationMacro.self,
|
||||
MustOr.self, CliTestDeclarationMacro.self, DeriveCompilableStatement.self,
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user