Implemented package specific structs

This commit is contained in:
2025-02-08 16:06:39 +01:00
parent 91bafc0867
commit 97cdcbd1cb
15 changed files with 121 additions and 78 deletions

View File

@ -10,22 +10,11 @@ import (
)
// Compile waits for the scan to finish and compiles all functions.
func Compile(files <-chan *fs.File, functions <-chan *core.Function, structs <-chan types.Type, errs <-chan error) (Result, error) {
func Compile(files <-chan *fs.File, functions <-chan *core.Function, structs <-chan *types.Struct, errs <-chan error) (Result, error) {
result := Result{}
allFiles := make([]*fs.File, 0, 8)
allFunctions := map[string]*core.Function{}
allTypes := map[string]types.Type{
"Int": types.Int,
"Int64": types.Int64,
"Int32": types.Int32,
"Int16": types.Int16,
"Int8": types.Int8,
"Float": types.Float,
"Float64": types.Float64,
"Float32": types.Float32,
"Pointer": types.PointerAny,
}
allStructs := map[string]*types.Struct{}
for functions != nil || files != nil || errs != nil {
select {
@ -36,16 +25,16 @@ func Compile(files <-chan *fs.File, functions <-chan *core.Function, structs <-c
}
function.Functions = allFunctions
function.Types = allTypes
function.Structs = allStructs
allFunctions[function.UniqueName] = function
case typ, ok := <-structs:
case structure, ok := <-structs:
if !ok {
structs = nil
continue
}
allTypes[typ.Name()] = typ
allStructs[structure.UniqueName] = structure
case file, ok := <-files:
if !ok {
@ -66,14 +55,8 @@ func Compile(files <-chan *fs.File, functions <-chan *core.Function, structs <-c
}
// Calculate size of structs
for _, typ := range allTypes {
structure, isStruct := typ.(*types.Struct)
if !isStruct {
continue
}
structure.Update(allTypes)
for _, structure := range allStructs {
structure.Update(allStructs)
}
// Resolve the types