Added types

This commit is contained in:
Eduard Urbach 2024-08-06 15:12:07 +02:00
parent 7c5e0ae3a1
commit baa2463b4b
Signed by: eduard
GPG key ID: 49226B848C78F6C8
19 changed files with 122 additions and 60 deletions

View file

@ -12,12 +12,14 @@ import (
// 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(root *expression.Expression) error {
func (f *Function) CompileCall(root *expression.Expression) (*Function, error) {
var (
pkg = f.Package
nameRoot = root.Children[0]
fn *Function
name string
fullName string
exists bool
)
if nameRoot.IsLeaf() {
@ -32,13 +34,13 @@ func (f *Function) CompileCall(root *expression.Expression) error {
if !isSyscall {
if pkg != f.File.Package {
if f.File.Imports == nil {
return errors.New(&errors.UnknownPackage{Name: pkg}, f.File, nameRoot.Token.Position)
return nil, errors.New(&errors.UnknownPackage{Name: pkg}, f.File, nameRoot.Token.Position)
}
imp, exists := f.File.Imports[pkg]
if !exists {
return errors.New(&errors.UnknownPackage{Name: pkg}, f.File, nameRoot.Token.Position)
return nil, errors.New(&errors.UnknownPackage{Name: pkg}, f.File, nameRoot.Token.Position)
}
imp.Used = true
@ -49,10 +51,10 @@ func (f *Function) CompileCall(root *expression.Expression) error {
tmp.WriteString(".")
tmp.WriteString(name)
fullName = tmp.String()
_, exists := f.Functions[fullName]
fn, exists = f.Functions[fullName]
if !exists {
return errors.New(&errors.UnknownFunction{Name: name}, f.File, nameRoot.Token.Position)
return nil, errors.New(&errors.UnknownFunction{Name: name}, f.File, nameRoot.Token.Position)
}
}
@ -66,7 +68,7 @@ func (f *Function) CompileCall(root *expression.Expression) error {
err := f.ExpressionsToRegisters(parameters, registers)
if err != nil {
return err
return fn, err
}
// TODO: Save all return value registers of the function
@ -104,5 +106,5 @@ func (f *Function) CompileCall(root *expression.Expression) error {
}
}
return nil
return fn, nil
}