Simplified file structure
This commit is contained in:
51
src/core/CompileASTNode.go
Normal file
51
src/core/CompileASTNode.go
Normal file
@ -0,0 +1,51 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"git.akyoto.dev/cli/q/src/ast"
|
||||
)
|
||||
|
||||
// CompileASTNode compiles a node in the AST.
|
||||
func (f *Function) CompileASTNode(node ast.Node) error {
|
||||
switch node := node.(type) {
|
||||
case *ast.Assert:
|
||||
f.Fold(node.Condition)
|
||||
return f.CompileAssert(node)
|
||||
|
||||
case *ast.Assign:
|
||||
f.Fold(node.Expression)
|
||||
return f.CompileAssign(node)
|
||||
|
||||
case *ast.Call:
|
||||
f.Fold(node.Expression)
|
||||
_, err := f.CompileCall(node.Expression)
|
||||
return err
|
||||
|
||||
case *ast.Define:
|
||||
f.Fold(node.Expression)
|
||||
return f.CompileDefinition(node)
|
||||
|
||||
case *ast.If:
|
||||
f.Fold(node.Condition)
|
||||
return f.CompileIf(node)
|
||||
|
||||
case *ast.Loop:
|
||||
return f.CompileLoop(node)
|
||||
|
||||
case *ast.Return:
|
||||
for _, value := range node.Values {
|
||||
f.Fold(value)
|
||||
}
|
||||
|
||||
return f.CompileReturn(node)
|
||||
|
||||
case *ast.Switch:
|
||||
for _, c := range node.Cases {
|
||||
f.Fold(c.Condition)
|
||||
}
|
||||
|
||||
return f.CompileSwitch(node)
|
||||
|
||||
default:
|
||||
panic("unknown AST type")
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user