From df5813515d0c4e6ff8be91164f5af5c42d52e023 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Fri, 2 Aug 2024 15:06:32 +0200 Subject: [PATCH] Fixed an incorrect register move --- examples/collatz/collatz.q | 4 +++- src/build/core/CompileLoop.go | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/examples/collatz/collatz.q b/examples/collatz/collatz.q index 3093312..32507a4 100644 --- a/examples/collatz/collatz.q +++ b/examples/collatz/collatz.q @@ -2,8 +2,10 @@ import log import sys main() { - x := 12 + collatz(12) +} +collatz(x) { loop { if x & 1 == 0 { x /= 2 diff --git a/src/build/core/CompileLoop.go b/src/build/core/CompileLoop.go index 1a28900..83b8c1a 100644 --- a/src/build/core/CompileLoop.go +++ b/src/build/core/CompileLoop.go @@ -9,6 +9,10 @@ import ( // CompileLoop compiles a loop instruction. func (f *Function) CompileLoop(loop *ast.Loop) error { + for _, register := range f.CPU.Input { + f.SaveRegister(register) + } + f.count.loop++ label := fmt.Sprintf("%s_loop_%d", f.UniqueName, f.count.loop) f.AddLabel(label)