Improved Windows ABI support

This commit is contained in:
2025-02-15 18:23:33 +01:00
parent 0a1a8f741d
commit d0bcd8cf9f
22 changed files with 124 additions and 32 deletions

View File

@ -32,7 +32,15 @@ func (f *Function) CallExtern(fn *Function, parameters []*expression.Expression)
return nil, err
}
f.Register(asm.PUSH, x86.RBP)
f.RegisterRegister(asm.MOVE, x86.RBP, x86.RSP)
f.RegisterNumber(asm.AND, x86.RSP, -16)
f.Number(asm.PUSH, 0)
f.Number(asm.PUSH, 0)
f.RegisterNumber(asm.SUB, x86.RSP, 32)
f.DLLCall(fmt.Sprintf("%s.%s", fn.Package, fn.Name))
f.RegisterRegister(asm.MOVE, x86.RSP, x86.RBP)
f.Register(asm.POP, x86.RBP)
for _, register := range registers {
f.FreeRegister(register)

View File

@ -34,7 +34,7 @@ func (f *Function) CompileAssignArray(node *ast.Assign) error {
index := left.Children[1]
if index.Token.IsNumeric() {
offset, err := f.Number(index.Token)
offset, err := f.ToNumber(index.Token)
if err != nil {
return err

View File

@ -12,7 +12,12 @@ import (
func (f *Function) CompileMemoryStore(root *expression.Expression) error {
parameters := root.Children[1:]
name := parameters[0].Token.Text(f.File.Bytes)
numBytes, _ := f.Number(parameters[1].Token)
numBytes, err := f.ToNumber(parameters[1].Token)
if err != nil {
return err
}
value := parameters[2]
variable := f.VariableByName(name)
@ -28,6 +33,6 @@ func (f *Function) CompileMemoryStore(root *expression.Expression) error {
Length: byte(numBytes),
}
_, err := f.ExpressionToMemory(value, memory)
_, err = f.ExpressionToMemory(value, memory)
return err
}

View File

@ -21,7 +21,7 @@ func (f *Function) ExecuteLeaf(operation token.Token, register cpu.Register, ope
return f.ExecuteRegisterRegister(operation, register, variable.Register)
case token.Number, token.Rune:
number, err := f.Number(operand)
number, err := f.ToNumber(operand)
if err != nil {
return err

View File

@ -30,7 +30,7 @@ func (f *Function) ExpressionToMemory(node *expression.Expression, memory asm.Me
}
if node.Token.IsNumeric() {
number, err := f.Number(node.Token)
number, err := f.ToNumber(node.Token)
if err != nil {
return nil, err

View File

@ -59,7 +59,7 @@ func (f *Function) ExpressionToRegister(node *expression.Expression, register cp
}
if index.Token.IsNumeric() {
offset, err := f.Number(index.Token)
offset, err := f.ToNumber(index.Token)
if err != nil {
return nil, err

View File

@ -18,7 +18,7 @@ func (f *Function) Fold(expr *expression.Expression) error {
if expr.IsLeaf() {
if expr.Token.IsNumeric() {
value, err := f.Number(expr.Token)
value, err := f.ToNumber(expr.Token)
expr.Value = value
expr.IsFolded = true
return err

View File

@ -9,8 +9,8 @@ import (
"git.akyoto.dev/cli/q/src/token"
)
// Number tries to convert the token into a numeric value.
func (f *Function) Number(t token.Token) (int, error) {
// ToNumber tries to convert the token into a numeric value.
func (f *Function) ToNumber(t token.Token) (int, error) {
switch t.Kind {
case token.Number:
digits := t.Text(f.File.Bytes)

View File

@ -34,7 +34,7 @@ func (f *Function) TokenToRegister(t token.Token, register cpu.Register) (types.
return nil, errors.New(&errors.UnknownIdentifier{Name: name}, f.File, t.Position)
case token.Number, token.Rune:
number, err := f.Number(t)
number, err := f.ToNumber(t)
if err != nil {
return nil, err