Moved external calls to a separate function
This commit is contained in:
parent
3b66dae1d4
commit
49afa5d800
23
src/core/CallExtern.go
Normal file
23
src/core/CallExtern.go
Normal file
@ -0,0 +1,23 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.akyoto.dev/cli/q/src/expression"
|
||||
"git.akyoto.dev/cli/q/src/types"
|
||||
"git.akyoto.dev/cli/q/src/x86"
|
||||
)
|
||||
|
||||
// CallExtern calls an external function.
|
||||
func (f *Function) CallExtern(fn *Function, parameters []*expression.Expression) ([]types.Type, error) {
|
||||
f.DLLs = f.DLLs.Append(fn.Package, fn.Name)
|
||||
registers := x86.WindowsInputRegisters[:len(parameters)]
|
||||
err := f.BeforeCall(fn, parameters, registers)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
f.DLLCall(fmt.Sprintf("%s.%s", fn.Package, fn.Name))
|
||||
return fn.OutputTypes, nil
|
||||
}
|
@ -1,12 +1,9 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.akyoto.dev/cli/q/src/errors"
|
||||
"git.akyoto.dev/cli/q/src/expression"
|
||||
"git.akyoto.dev/cli/q/src/types"
|
||||
"git.akyoto.dev/cli/q/src/x86"
|
||||
)
|
||||
|
||||
// CompileCall executes a function call.
|
||||
@ -74,16 +71,7 @@ func (f *Function) CompileCall(root *expression.Expression) ([]types.Type, error
|
||||
}
|
||||
|
||||
if fn.IsExtern() {
|
||||
f.DLLs = f.DLLs.Append(pkg, name)
|
||||
registers := x86.WindowsInputRegisters[:len(parameters)]
|
||||
err := f.BeforeCall(fn, parameters, registers)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
f.DLLCall(fmt.Sprintf("%s.%s", pkg, name))
|
||||
return fn.OutputTypes, nil
|
||||
return f.CallExtern(fn, parameters)
|
||||
}
|
||||
|
||||
registers := f.CPU.Input[:len(parameters)]
|
||||
|
Loading…
x
Reference in New Issue
Block a user