diff --git a/src/build/register/RegisterNumber.go b/src/build/register/RegisterNumber.go index ce9a41f..298c4d7 100644 --- a/src/build/register/RegisterNumber.go +++ b/src/build/register/RegisterNumber.go @@ -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() } diff --git a/tests/programs/64-bit.q b/tests/programs/64-bit.q new file mode 100644 index 0000000..37e9d42 --- /dev/null +++ b/tests/programs/64-bit.q @@ -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 +} \ No newline at end of file diff --git a/tests/programs/negation.q b/tests/programs/negation.q index 94e2826..709f995 100644 --- a/tests/programs/negation.q +++ b/tests/programs/negation.q @@ -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 } \ No newline at end of file diff --git a/tests/programs/negative.q b/tests/programs/negative.q index f300e48..dd0ff3f 100644 --- a/tests/programs/negative.q +++ b/tests/programs/negative.q @@ -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 } \ No newline at end of file diff --git a/tests/programs/out-of-memory.q b/tests/programs/out-of-memory.q new file mode 100644 index 0000000..4b7603f --- /dev/null +++ b/tests/programs/out-of-memory.q @@ -0,0 +1,6 @@ +import mem + +main() { + address := mem.alloc(1024 * 1024 * 1024 * 1024) + assert address < 0 +} \ No newline at end of file diff --git a/tests/programs_test.go b/tests/programs_test.go index 6fbc5fe..3406331 100644 --- a/tests/programs_test.go +++ b/tests/programs_test.go @@ -51,6 +51,7 @@ var programs = []struct { {"jump-near", "", "", 0}, {"loop", "", "", 0}, {"loop-lifetime", "", "", 0}, + {"out-of-memory", "", "", 0}, } func TestPrograms(t *testing.T) {