Moved external calls to a separate function

This commit is contained in:
Eduard Urbach 2025-02-12 11:25:20 +01:00
parent 3b66dae1d4
commit 49afa5d800
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
2 changed files with 24 additions and 13 deletions

23
src/core/CallExtern.go Normal file
View 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
}

View File

@ -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)]