Improved type system

This commit is contained in:
2024-08-08 12:55:25 +02:00
parent d624a5f895
commit 5d9be01a85
20 changed files with 111 additions and 67 deletions

View File

@ -1,11 +1,10 @@
package core
import (
"strings"
"git.akyoto.dev/cli/q/src/asm"
"git.akyoto.dev/cli/q/src/errors"
"git.akyoto.dev/cli/q/src/expression"
"git.akyoto.dev/cli/q/src/types"
)
// CompileCall executes a function call.
@ -18,7 +17,6 @@ func (f *Function) CompileCall(root *expression.Expression) (*Function, error) {
nameNode = root.Children[0]
fn *Function
name string
fullName string
exists bool
)
@ -47,12 +45,7 @@ func (f *Function) CompileCall(root *expression.Expression) (*Function, error) {
imp.Used = true
}
tmp := strings.Builder{}
tmp.WriteString(pkg)
tmp.WriteString(".")
tmp.WriteString(name)
fullName = tmp.String()
fn, exists = f.Functions[fullName]
fn, exists = f.Functions[pkg+"."+name]
if !exists {
return nil, errors.New(&errors.UnknownFunction{Name: name}, f.File, nameNode.Token.Position)
@ -68,10 +61,10 @@ func (f *Function) CompileCall(root *expression.Expression) (*Function, error) {
return nil, err
}
if typ != fn.Parameters[i].Type {
if !types.Check(typ, fn.Parameters[i].Type) {
return nil, errors.New(&errors.TypeMismatch{
Encountered: string(typ),
Expected: string(fn.Parameters[i].Type),
Encountered: typ.Name,
Expected: fn.Parameters[i].Type.Name,
ParameterName: fn.Parameters[i].Name,
}, f.File, parameters[i].Token.Position)
}
@ -87,7 +80,7 @@ func (f *Function) CompileCall(root *expression.Expression) (*Function, error) {
}
}
f.Call(fullName)
f.Call(fn.UniqueName)
for _, register := range registers {
if register == f.CPU.Output[0] && root.Parent != nil {