package build import ( "git.akyoto.dev/cli/q/src/build/config" "git.akyoto.dev/cli/q/src/build/expression" ) // CompileFunctionCall executes a function call. // All call registers must hold the correct parameter values before the function invocation. // Registers that are in use must be saved if they are modified by the function. // After the function call, they must be restored in reverse order. func (f *Function) CompileFunctionCall(expr *expression.Expression) error { funcName := expr.Children[0].Token.Text() if funcName == "syscall" { return f.CompileSyscall(expr) } function := f.functions[funcName] if function != f { function.Wait() } parameters := expr.Children[1:] registers := f.cpu.Call[:len(parameters)] err := f.ExpressionsToRegisters(parameters, registers) if config.Verbose { f.Logf("call: %s", funcName) } f.assembler.Call(funcName) f.sideEffects += function.sideEffects return err } // CompileSyscall executes a syscall. func (f *Function) CompileSyscall(expr *expression.Expression) error { parameters := expr.Children[1:] registers := f.cpu.Syscall[:len(parameters)] err := f.ExpressionsToRegisters(parameters, registers) f.assembler.Syscall() f.sideEffects++ return err }