Added more tests

This commit is contained in:
Eduard Urbach 2024-07-31 15:24:21 +02:00
parent 76c916018a
commit 3d245a15f9
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
6 changed files with 52 additions and 8 deletions

View File

@ -3,6 +3,7 @@ package register
import ( import (
"git.akyoto.dev/cli/q/src/build/asm" "git.akyoto.dev/cli/q/src/build/asm"
"git.akyoto.dev/cli/q/src/build/cpu" "git.akyoto.dev/cli/q/src/build/cpu"
"git.akyoto.dev/cli/q/src/build/sizeof"
) )
func (f *Machine) RegisterNumber(mnemonic asm.Mnemonic, a cpu.Register, b int) { func (f *Machine) RegisterNumber(mnemonic asm.Mnemonic, a cpu.Register, b int) {
@ -10,11 +11,20 @@ func (f *Machine) RegisterNumber(mnemonic asm.Mnemonic, a cpu.Register, b int) {
f.SaveRegister(a) f.SaveRegister(a)
} }
if sizeof.Signed(int64(b)) == 8 {
tmp := f.NewRegister()
f.Assembler.RegisterNumber(asm.MOVE, tmp, b)
f.UseRegister(tmp)
f.postInstruction()
f.Assembler.RegisterRegister(mnemonic, a, tmp)
f.postInstruction()
f.FreeRegister(tmp)
} else {
f.Assembler.RegisterNumber(mnemonic, a, b) f.Assembler.RegisterNumber(mnemonic, a, b)
f.postInstruction()
}
if mnemonic == asm.MOVE { if mnemonic == asm.MOVE {
f.UseRegister(a) f.UseRegister(a)
} }
f.postInstruction()
} }

12
tests/programs/64-bit.q Normal file
View File

@ -0,0 +1,12 @@
main() {
x := 20000000000
assert x == 20000000000
x -= 10000000000
assert x == 10000000000
x -= 10000000000
assert x == 0
x -= 10000000000
assert x == -10000000000
x -= 10000000000
assert x == -20000000000
}

View File

@ -1,7 +1,10 @@
main() { main() {
assert f(-32) == 32 assert neg(-1) == 1
assert neg(1) == -1
assert neg(-256) == 256
assert neg(256) == -256
} }
f(x) { neg(x) {
return -x return -x
} }

View File

@ -1,5 +1,17 @@
main() { main() {
a := -32 a := -1
b := 64 b := -2
assert a + b == 32 assert a == -1
assert a != 0xFF
assert a != 0xFFFF
assert a != 0xFFFFFFFF
assert b == -2
assert b != 0xFE
assert b != 0xFFFE
assert b != 0xFFFFFFFE
assert a + b == -3
assert a - b == 1
assert a * b == 2
assert a / b == 0
assert a % b == -1
} }

View File

@ -0,0 +1,6 @@
import mem
main() {
address := mem.alloc(1024 * 1024 * 1024 * 1024)
assert address < 0
}

View File

@ -51,6 +51,7 @@ var programs = []struct {
{"jump-near", "", "", 0}, {"jump-near", "", "", 0},
{"loop", "", "", 0}, {"loop", "", "", 0},
{"loop-lifetime", "", "", 0}, {"loop-lifetime", "", "", 0},
{"out-of-memory", "", "", 0},
} }
func TestPrograms(t *testing.T) { func TestPrograms(t *testing.T) {