diff --git a/lib/core/core_linux_arm.q b/lib/core/core_linux_arm.q index 939ba41..f20e626 100644 --- a/lib/core/core_linux_arm.q +++ b/lib/core/core_linux_arm.q @@ -5,4 +5,8 @@ init() { exit() { syscall(93, 0) +} + +crash() { + syscall(93, 1) } \ No newline at end of file diff --git a/lib/core/core_linux_x86.q b/lib/core/core_linux_x86.q index 41e7100..9c8f519 100644 --- a/lib/core/core_linux_x86.q +++ b/lib/core/core_linux_x86.q @@ -5,4 +5,8 @@ init() { exit() { syscall(60, 0) +} + +crash() { + syscall(60, 1) } \ No newline at end of file diff --git a/lib/core/core_mac.q b/lib/core/core_mac.q index 875a04a..91618b4 100644 --- a/lib/core/core_mac.q +++ b/lib/core/core_mac.q @@ -5,4 +5,8 @@ init() { exit() { syscall(0x2000001, 0) +} + +crash() { + syscall(0x2000001, 1) } \ No newline at end of file diff --git a/lib/core/core_windows.q b/lib/core/core_windows.q index 575b41e..516794a 100644 --- a/lib/core/core_windows.q +++ b/lib/core/core_windows.q @@ -9,6 +9,10 @@ exit() { kernel32.ExitProcess(0) } +crash() { + kernel32.ExitProcess(1) +} + const cp { utf8 65001 } diff --git a/src/asmc/resolvePointers.go b/src/asmc/resolvePointers.go index 7603a86..2cf0e52 100644 --- a/src/asmc/resolvePointers.go +++ b/src/asmc/resolvePointers.go @@ -16,7 +16,7 @@ restart: for i, pointer := range c.codePointers { address := pointer.Resolve() - if sizeof.Signed(int32(address)) > int(pointer.Size) { + if config.TargetArch == config.X86 && sizeof.Signed(int32(address)) > int(pointer.Size) { left := c.code[:pointer.Position-Address(pointer.OpSize)] right := c.code[pointer.Position+Address(pointer.Size):] size := pointer.Size + pointer.OpSize diff --git a/src/compiler/finalize.go b/src/compiler/finalize.go index 16f24de..85c0c7d 100644 --- a/src/compiler/finalize.go +++ b/src/compiler/finalize.go @@ -3,9 +3,7 @@ package compiler import ( "git.urbach.dev/cli/q/src/asm" "git.urbach.dev/cli/q/src/asmc" - "git.urbach.dev/cli/q/src/config" "git.urbach.dev/cli/q/src/core" - "git.urbach.dev/cli/q/src/x86" ) // finalize generates the final machine code. @@ -45,25 +43,6 @@ func (r *Result) finalize() { } }) - final.Label(asm.LABEL, asm.Label{ - Name: "_crash", - Type: asm.ControlLabel, - }) - - switch config.TargetOS { - case config.Linux: - final.RegisterNumber(asm.MOVE, x86.SyscallInputRegisters[0], LinuxExit) - final.RegisterNumber(asm.MOVE, x86.SyscallInputRegisters[1], 1) - final.Syscall() - case config.Mac: - final.RegisterNumber(asm.MOVE, x86.SyscallInputRegisters[0], MacExit) - final.RegisterNumber(asm.MOVE, x86.SyscallInputRegisters[1], 1) - final.Syscall() - case config.Windows: - final.RegisterNumber(asm.MOVE, x86.WindowsInputRegisters[0], 1) - final.RegisterNumber(asm.AND, x86.RSP, -16) - final.DLLCall("kernel32.ExitProcess") - } - + final.Merge(&r.Functions["core.crash"].Assembler) r.Code, r.Data = asmc.Finalize(&final, r.DLLs) } diff --git a/src/core/CompileAssert.go b/src/core/CompileAssert.go index 7614bd9..07af8ff 100644 --- a/src/core/CompileAssert.go +++ b/src/core/CompileAssert.go @@ -20,7 +20,7 @@ func (f *Function) CompileAssert(assert *ast.Assert) error { f.Defer(func() { f.AddLabel(fail) - f.Jump(asm.JUMP, asm.Label{Name: "_crash", Type: asm.ControlLabel}) + f.Jump(asm.JUMP, asm.Label{Name: "core.crash", Type: asm.ControlLabel}) }) return err diff --git a/tests/programs/assert.q b/tests/programs/assert.q index 9c3123e..c54983d 100644 --- a/tests/programs/assert.q +++ b/tests/programs/assert.q @@ -1,6 +1,3 @@ main() { - assert 1 != 0 - assert 1 == 0 || 1 != 0 - assert 1 != 0 && 2 != 0 assert 1 == 0 } \ No newline at end of file