From 49afa5d800a9a3e7f3b7f0a5f1bfb253650bc7ad Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Wed, 12 Feb 2025 11:25:20 +0100 Subject: [PATCH] Moved external calls to a separate function --- src/core/CallExtern.go | 23 +++++++++++++++++++++++ src/core/CompileCall.go | 14 +------------- 2 files changed, 24 insertions(+), 13 deletions(-) create mode 100644 src/core/CallExtern.go diff --git a/src/core/CallExtern.go b/src/core/CallExtern.go new file mode 100644 index 0000000..8d3f358 --- /dev/null +++ b/src/core/CallExtern.go @@ -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 +} diff --git a/src/core/CompileCall.go b/src/core/CompileCall.go index 688673a..2518ab5 100644 --- a/src/core/CompileCall.go +++ b/src/core/CompileCall.go @@ -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)]