Added more tests
This commit is contained in:
parent
76c916018a
commit
3d245a15f9
@ -3,6 +3,7 @@ package register
|
||||
import (
|
||||
"git.akyoto.dev/cli/q/src/build/asm"
|
||||
"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) {
|
||||
@ -10,11 +11,20 @@ func (f *Machine) RegisterNumber(mnemonic asm.Mnemonic, a cpu.Register, b int) {
|
||||
f.SaveRegister(a)
|
||||
}
|
||||
|
||||
f.Assembler.RegisterNumber(mnemonic, a, b)
|
||||
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.postInstruction()
|
||||
}
|
||||
|
||||
if mnemonic == asm.MOVE {
|
||||
f.UseRegister(a)
|
||||
}
|
||||
|
||||
f.postInstruction()
|
||||
}
|
||||
|
12
tests/programs/64-bit.q
Normal file
12
tests/programs/64-bit.q
Normal 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
|
||||
}
|
@ -1,7 +1,10 @@
|
||||
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
|
||||
}
|
@ -1,5 +1,17 @@
|
||||
main() {
|
||||
a := -32
|
||||
b := 64
|
||||
assert a + b == 32
|
||||
a := -1
|
||||
b := -2
|
||||
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
|
||||
}
|
6
tests/programs/out-of-memory.q
Normal file
6
tests/programs/out-of-memory.q
Normal file
@ -0,0 +1,6 @@
|
||||
import mem
|
||||
|
||||
main() {
|
||||
address := mem.alloc(1024 * 1024 * 1024 * 1024)
|
||||
assert address < 0
|
||||
}
|
@ -51,6 +51,7 @@ var programs = []struct {
|
||||
{"jump-near", "", "", 0},
|
||||
{"loop", "", "", 0},
|
||||
{"loop-lifetime", "", "", 0},
|
||||
{"out-of-memory", "", "", 0},
|
||||
}
|
||||
|
||||
func TestPrograms(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user