Added more tests
This commit is contained in:
parent
cc66b02bf8
commit
8f9481c548
@ -50,13 +50,3 @@ func (f *Function) CompileCall(root *expression.Expression) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CompileSyscall executes a syscall.
|
|
||||||
func (f *Function) CompileSyscall(expr *expression.Expression) error {
|
|
||||||
parameters := expr.Children[1:]
|
|
||||||
registers := f.cpu.Syscall[:len(parameters)]
|
|
||||||
err := f.ExpressionsToRegisters(parameters, registers)
|
|
||||||
f.assembler.Syscall()
|
|
||||||
f.sideEffects++
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
@ -18,7 +18,6 @@ type state struct {
|
|||||||
assembler asm.Assembler
|
assembler asm.Assembler
|
||||||
cpu cpu.CPU
|
cpu cpu.CPU
|
||||||
count counter
|
count counter
|
||||||
sideEffects int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// counter stores how often a certain statement appeared so we can generate a unique label from it.
|
// counter stores how often a certain statement appeared so we can generate a unique label from it.
|
||||||
|
@ -16,6 +16,7 @@ func TestCLI(t *testing.T) {
|
|||||||
tests := []cliTest{
|
tests := []cliTest{
|
||||||
{[]string{}, 2},
|
{[]string{}, 2},
|
||||||
{[]string{"invalid"}, 2},
|
{[]string{"invalid"}, 2},
|
||||||
|
{[]string{"help"}, 0},
|
||||||
{[]string{"system"}, 0},
|
{[]string{"system"}, 0},
|
||||||
{[]string{"build", "invalid-directory"}, 1},
|
{[]string{"build", "invalid-directory"}, 1},
|
||||||
{[]string{"build", "--invalid-parameter"}, 2},
|
{[]string{"build", "--invalid-parameter"}, 2},
|
||||||
@ -23,6 +24,7 @@ func TestCLI(t *testing.T) {
|
|||||||
{[]string{"build", "../../examples/hello", "--dry"}, 0},
|
{[]string{"build", "../../examples/hello", "--dry"}, 0},
|
||||||
{[]string{"build", "../../examples/hello", "--dry", "--verbose"}, 0},
|
{[]string{"build", "../../examples/hello", "--dry", "--verbose"}, 0},
|
||||||
{[]string{"build", "../../examples/hello/hello.q", "--dry"}, 0},
|
{[]string{"build", "../../examples/hello/hello.q", "--dry"}, 0},
|
||||||
|
{[]string{"build", "../../examples/hello"}, 0},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
12
tests/programs/math.q
Normal file
12
tests/programs/math.q
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
main() {
|
||||||
|
x := 1000
|
||||||
|
syscall(60, div10(x) / 10 + div(x, 100) * 4 - 40 - x + x)
|
||||||
|
}
|
||||||
|
|
||||||
|
div(x, y) {
|
||||||
|
return x / y
|
||||||
|
}
|
||||||
|
|
||||||
|
div10(x) {
|
||||||
|
return x / 10
|
||||||
|
}
|
@ -16,6 +16,7 @@ var programs = []struct {
|
|||||||
ExpectedExitCode int
|
ExpectedExitCode int
|
||||||
}{
|
}{
|
||||||
{"empty.q", "", 0},
|
{"empty.q", "", 0},
|
||||||
|
{"math.q", "", 10},
|
||||||
{"precedence.q", "", 10},
|
{"precedence.q", "", 10},
|
||||||
{"square-sum.q", "", 25},
|
{"square-sum.q", "", 25},
|
||||||
{"chained-calls.q", "", 9},
|
{"chained-calls.q", "", 9},
|
||||||
|
Loading…
Reference in New Issue
Block a user