From fca944d26c099ef8a45288f7b924b06418ae4ff8 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Sat, 6 Jul 2024 13:06:39 +0200 Subject: [PATCH] Added more tests --- src/build/core/CompileCall.go | 10 ---------- src/build/core/state.go | 1 - src/cli/Main_test.go | 2 ++ tests/programs/math.q | 12 ++++++++++++ tests/programs_test.go | 1 + 5 files changed, 15 insertions(+), 11 deletions(-) create mode 100644 tests/programs/math.q diff --git a/src/build/core/CompileCall.go b/src/build/core/CompileCall.go index e9fa102..079cf97 100644 --- a/src/build/core/CompileCall.go +++ b/src/build/core/CompileCall.go @@ -50,13 +50,3 @@ func (f *Function) CompileCall(root *expression.Expression) error { 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 -} diff --git a/src/build/core/state.go b/src/build/core/state.go index 6a0d5e8..2bca805 100644 --- a/src/build/core/state.go +++ b/src/build/core/state.go @@ -18,7 +18,6 @@ type state struct { assembler asm.Assembler cpu cpu.CPU count counter - sideEffects int } // counter stores how often a certain statement appeared so we can generate a unique label from it. diff --git a/src/cli/Main_test.go b/src/cli/Main_test.go index 63b5366..6471939 100644 --- a/src/cli/Main_test.go +++ b/src/cli/Main_test.go @@ -16,6 +16,7 @@ func TestCLI(t *testing.T) { tests := []cliTest{ {[]string{}, 2}, {[]string{"invalid"}, 2}, + {[]string{"help"}, 0}, {[]string{"system"}, 0}, {[]string{"build", "invalid-directory"}, 1}, {[]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", "--verbose"}, 0}, {[]string{"build", "../../examples/hello/hello.q", "--dry"}, 0}, + {[]string{"build", "../../examples/hello"}, 0}, } for _, test := range tests { diff --git a/tests/programs/math.q b/tests/programs/math.q new file mode 100644 index 0000000..b3bb8ee --- /dev/null +++ b/tests/programs/math.q @@ -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 +} \ No newline at end of file diff --git a/tests/programs_test.go b/tests/programs_test.go index 91c483d..bcd947a 100644 --- a/tests/programs_test.go +++ b/tests/programs_test.go @@ -16,6 +16,7 @@ var programs = []struct { ExpectedExitCode int }{ {"empty.q", "", 0}, + {"math.q", "", 10}, {"precedence.q", "", 10}, {"square-sum.q", "", 25}, {"chained-calls.q", "", 9},