Added a program init function
This commit is contained in:
@ -44,6 +44,11 @@ func (f *Function) CompileCall(root *expression.Expression) ([]types.Type, error
|
||||
name = nameNode.Token.Text(f.File.Bytes)
|
||||
}
|
||||
|
||||
if f.UniqueName == "core.init" && pkg == "main" && name == "main" {
|
||||
f.Call("main.main")
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
fn, exists = f.Functions[pkg+"."+name]
|
||||
|
||||
if !exists {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"git.akyoto.dev/cli/q/src/asm"
|
||||
@ -91,19 +92,28 @@ func (f *Function) ExpressionToRegister(node *expression.Expression, register cp
|
||||
rightText := right.Token.Text(f.File.Bytes)
|
||||
variable := f.VariableByName(leftText)
|
||||
|
||||
if variable == nil {
|
||||
constant, isConst := f.Constants[f.Package+"."+leftText+"."+rightText]
|
||||
|
||||
if isConst {
|
||||
return f.TokenToRegister(constant.Value, register)
|
||||
}
|
||||
|
||||
return nil, errors.New(&errors.UnknownIdentifier{Name: leftText}, f.File, left.Token.Position)
|
||||
if variable != nil {
|
||||
field := variable.Type.(*types.Pointer).To.(*types.Struct).FieldByName(rightText)
|
||||
f.MemoryRegister(asm.LOAD, asm.Memory{Base: variable.Register, Offset: int8(field.Offset), Length: byte(field.Type.Size())}, register)
|
||||
return field.Type, nil
|
||||
}
|
||||
|
||||
field := variable.Type.(*types.Pointer).To.(*types.Struct).FieldByName(rightText)
|
||||
f.MemoryRegister(asm.LOAD, asm.Memory{Base: variable.Register, Offset: int8(field.Offset), Length: byte(field.Type.Size())}, register)
|
||||
return field.Type, nil
|
||||
constant, isConst := f.Constants[f.Package+"."+leftText+"."+rightText]
|
||||
|
||||
if isConst {
|
||||
return f.TokenToRegister(constant.Value, register)
|
||||
}
|
||||
|
||||
uniqueName := fmt.Sprintf("%s.%s", leftText, rightText)
|
||||
function, exists := f.Functions[uniqueName]
|
||||
|
||||
if exists {
|
||||
f.File.Imports[leftText].Used = true
|
||||
f.RegisterLabel(asm.MOVE, register, function.UniqueName)
|
||||
return types.AnyPointer, nil
|
||||
}
|
||||
|
||||
return nil, errors.New(&errors.UnknownIdentifier{Name: leftText}, f.File, left.Token.Position)
|
||||
}
|
||||
|
||||
if len(node.Children) == 1 {
|
||||
|
Reference in New Issue
Block a user