From 3c4e039e4808a2a0d8016cb90f244ef575ab6560 Mon Sep 17 00:00:00 2001 From: allaun Date: Tue, 30 Jun 2026 18:10:48 -0500 Subject: [PATCH] fix(go): type conversion errors in floorDiv/avmClamp - floorDiv returns int64 instead of int32 to match avmClamp signature - instr.Arg wrapped in int64() for avmClamp/avmQ0Clamp calls - Test expected value cast to int32 fix(julia): add Q16_SCALE export to Q16_16 module --- go/avm.go | 14 +++++------ go/avm_test.go | 2 +- julia/CoreFormalism/Q16_16.jl | 3 ++- signatures/avm_verification_receipt.json | 32 +++++++++++++++++++++--- 4 files changed, 39 insertions(+), 12 deletions(-) diff --git a/go/avm.go b/go/avm.go index 2d5b95de..d5466a0a 100644 --- a/go/avm.go +++ b/go/avm.go @@ -25,12 +25,12 @@ func avmQ0Clamp(x int64) int32 { return int32(x) } -func floorDiv(a, b int64) int32 { +func floorDiv(a, b int64) int64 { if b == 0 { panic("division by zero") } q := a / b r := a % b if r != 0 && ((a ^ b) < 0) { q-- } - return int32(q) + return q } func ltQ16V6(a, b int32) bool { @@ -161,11 +161,11 @@ func Step(s State, prog []Instr) (*State, error) { switch instr.Op { case PushQ16: - stack = append(stack, Val{Ty: Q16_16, Q: avmClamp(instr.Arg)}) - case PushBool: - stack = append(stack, Val{Ty: Bool, Bval: instr.Arg2}) - case PushQ0: - stack = append(stack, Val{Ty: Q0_16, Q: avmQ0Clamp(instr.Arg)}) + stack = append(stack, Val{Ty: Q16_16, Q: avmClamp(int64(instr.Arg))}) + case PushBool: + stack = append(stack, Val{Ty: Bool, Bval: instr.Arg2}) + case PushQ0: + stack = append(stack, Val{Ty: Q0_16, Q: avmQ0Clamp(int64(instr.Arg))}) case Pop: if len(stack) == 0 { return nil, errors.New("empty stack") } stack = stack[:len(stack)-1] diff --git a/go/avm_test.go b/go/avm_test.go index 57c5a664..554b8114 100644 --- a/go/avm_test.go +++ b/go/avm_test.go @@ -30,7 +30,7 @@ func TestFloorDiv(t *testing.T) { } s, err := runTest(prog, 100) if err != nil { t.Fatal(err) } - expected := (3 * Q16Scale) / 5 + expected := int32((3 * Q16Scale) / 5) if s.Stack[0].Q != expected { t.Fatalf("got %d, expected %d", s.Stack[0].Q, expected) } } diff --git a/julia/CoreFormalism/Q16_16.jl b/julia/CoreFormalism/Q16_16.jl index 718fe40a..e34198c1 100644 --- a/julia/CoreFormalism/Q16_16.jl +++ b/julia/CoreFormalism/Q16_16.jl @@ -14,7 +14,7 @@ in `Q16_16Numerics.lean`. """ module Q16_16 -export Q16_16Value, +export Q16_16Value, Q16_SCALE, of_raw_int, to_int, zero, one, epsilon, two, half, q16_min_raw, q16_max_raw, q16_scale, @@ -27,6 +27,7 @@ export Q16_16Value, const q16_min_raw = -2147483648 const q16_max_raw = 2147483647 const q16_scale = 65536 +const Q16_SCALE = q16_scale """ Q16_16Value diff --git a/signatures/avm_verification_receipt.json b/signatures/avm_verification_receipt.json index 9ac426a9..a09736de 100644 --- a/signatures/avm_verification_receipt.json +++ b/signatures/avm_verification_receipt.json @@ -10,7 +10,7 @@ { "property": "Q16 scale (2^16)", "python": 65536, - "wolfram": "65536 sixty-five thousand, five hundred thirty-six 10000000000000000_2 2^16 m | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9\n65536 mod m | 0 | 1 | 0 | 1 | 4 | 2 | 0 | 7 65536 = 2^16 is a perfect 16th power. A regular 65536-gon is constructible with straightedge and compass. 65536 is an even number.", + "wolfram": "65536 sixty-five thousand, five hundred thirty-six 10000000000000000_2 2^16 m | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9\n65536 mod m | 0 | 1 | 0 | 1 | 4 | 2 | 0 | 7 A regular 65536-gon is constructible with straightedge and compass. 65536 = 2^16 is a perfect 16th power. 65536 is an even number.", "match": true }, { @@ -29,11 +29,37 @@ "port_tests": { "Python": { "passed": true, - "output": "ass\n \u2705 type_mismatch: rejected\n \u2705 stack_overflow: rejected\n \u2705 div_by_zero: rejected\n \u2705 control_flow: jump_if true\n \u2705 locals: store+load\n \u2705 mul_div_roundtrip: 5*3/3 = 5\n\nAll Python tests passed.\n" + "output": "c_add: 5 + 3 = 8\n \u2705 div_q16: 3/5 = 0.6\n \u2705 saturation: max-1 + 2 = max\n \u2705 v6_comparison: 5 cases pass\n \u2705 type_mismatch: rejected\n \u2705 stack_overflow: rejected\n \u2705 div_by_zero: rejected\n \u2705 control_flow: jump_if true\n \u2705 locals: store+load\n \u2705 mul_div_roundtrip: 5*3/3 = 5\n\nAll Python tests passed.\n" }, "Rust": { + "passed": false, + "output": "ured; 0 filtered out; finished in 0.00s\n\n\nrunning 1 test\ntest test_nuvmap_projector ... ok\n\ntest result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s\n\n\nrunning 0 tests\n\ntest result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s\n\n" + }, + "Go": { + "passed": false, + "skipped": true, + "reason": "go not found" + }, + "C": { + "passed": false, + "output": "" + }, + "C++": { + "passed": false, + "output": "" + }, + "Julia": { "passed": true, - "output": "ult: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s\n\n\nrunning 0 tests\n\ntest result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s\n\n" + "output": "Test Summary: | Pass Total Time\nAVM ISA | 12 12 0.9s\n" + }, + "R": { + "passed": false, + "output": "PASS: add Q16\nPASS: jump_if\nPASS: store/load\nPASS: type error\nPASS: division by zero\n\nAll R AVM tests passed!\n" + }, + "Octave": { + "passed": false, + "skipped": true, + "reason": "octave not found" } } } \ No newline at end of file