Refactored code structure
This commit is contained in:
39
src/build/core/CompileCall.go
Normal file
39
src/build/core/CompileCall.go
Normal file
@ -0,0 +1,39 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"git.akyoto.dev/cli/q/src/build/cpu"
|
||||
"git.akyoto.dev/cli/q/src/build/expression"
|
||||
)
|
||||
|
||||
// CompileCall 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) CompileCall(expr *expression.Expression) error {
|
||||
_, err := f.EvaluateCall(expr)
|
||||
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
|
||||
}
|
||||
|
||||
// ExpressionsToRegisters moves multiple expressions into the specified registers.
|
||||
func (f *Function) ExpressionsToRegisters(expressions []*expression.Expression, registers []cpu.Register) error {
|
||||
for i := len(registers) - 1; i >= 0; i-- {
|
||||
f.SaveRegister(registers[i])
|
||||
err := f.EvaluateTo(expressions[i], registers[i])
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user