33 lines
774 B
Go
33 lines
774 B
Go
package build
|
|
|
|
import (
|
|
"git.akyoto.dev/cli/q/src/build/expression"
|
|
"git.akyoto.dev/cli/q/src/build/token"
|
|
)
|
|
|
|
// CompileFunctionCall compiles a top-level function call.
|
|
func (f *Function) CompileFunctionCall(expr *expression.Expression) error {
|
|
funcName := expr.Children[0].Token.Text()
|
|
parameters := expr.Children[1:]
|
|
|
|
for i, parameter := range parameters {
|
|
err := f.ExpressionToRegister(parameter, f.CPU.Syscall[i])
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
if funcName == "syscall" {
|
|
f.Assembler.Syscall()
|
|
} else {
|
|
f.Assembler.Call(funcName)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// isFunctionCall returns true if the expression is a function call.
|
|
func isFunctionCall(expr *expression.Expression) bool {
|
|
return expr.Token.Kind == token.Operator && expr.Token.Text() == "λ"
|
|
}
|