interp: deterministic interpreter, aji run, run tests (P0-11, P0-12)

- src/interp/machine.zig: format-0 interpreter on the air64 target;
  checked/wrapping arithmetic, shifts, casts, aggregates, calls with a
  1024-frame limit, traps as records with T0xxx codes
- aji run: prints one JSON run record; exit code 4 on trap
- conformance runner: `expect: run` with `result:`/`trap:`, every run
  executed twice and compared byte-for-byte; header keys must be single
  lowercase words
- Phase 0 corpus: 3 accept, 19 reject, 15 run tests (41 total)
This commit is contained in:
dev committed 2026-10-04 12:28:27 +03:00
1 parent 50bf990355
commit 1f5008bb37
45 files changed
+1463 -23

No files matched your search

@@ -0,0 +1,21 @@
; Structs and enums are rendered in the run record.
; expect: run
; result: {"variant":"Err","payload":[{"code":404,"fatal":false}]}
; phase: 0
; spec: docs/spec/07a-air-instructions.md
module test.aggregates
air 0
lang 0.1
features []
type @Error = struct { code: u16, fatal: bool }
type @Result = enum { Ok(u32), Err(@Error) }
fn @main() -> @Result
effects []
entry:
%code = const.u16 404
%fatal = const.bool false
%e = struct.make @Error(%code, %fatal)
%r = enum.make @Result.Err(%e)
ret %r
@@ -0,0 +1,17 @@
; shr on signed values is arithmetic.
; expect: run
; result: -1
; phase: 0
; spec: docs/spec/02-types-and-values.md
module test.arithmetic_shift
air 0
lang 0.1
features []
fn @main() -> i16
effects []
entry:
%a = const.i16 -32768
%b = const.i16 15
%c = shr.i16 %a, %b
ret %c
@@ -0,0 +1,16 @@
; A false assertion traps.
; expect: run
; trap: T0002
; phase: 0
; spec: docs/spec/07a-air-instructions.md
module test.assert_failure
air 0
lang 0.1
features []
fn @main() -> void
effects []
entry:
%f = const.bool false
assert %f
ret
@@ -0,0 +1,21 @@
; Unbounded recursion hits the call-depth limit.
; expect: run
; trap: T0007
; phase: 0
; spec: docs/spec/07a-air-instructions.md
module test.call_depth
air 0
lang 0.1
features []
fn @main() -> void
effects []
entry:
call @down()
ret
fn @down() -> void
effects []
entry:
call @down()
ret
@@ -0,0 +1,16 @@
; Checked cast of 300 to u8 traps.
; expect: run
; trap: T0006
; phase: 0
; spec: docs/spec/02-types-and-values.md
module test.checked_cast
air 0
lang 0.1
features []
fn @main() -> u8
effects []
entry:
%a = const.u32 300
%b = cast.checked.u8 %a
ret %b
@@ -0,0 +1,17 @@
; u8 200 + 56 overflows.
; expect: run
; trap: T0003
; phase: 0
; spec: docs/spec/07a-air-instructions.md
module test.checked_overflow
air 0
lang 0.1
features []
fn @main() -> u8
effects []
entry:
%a = const.u8 200
%b = const.u8 56
%c = add.checked.u8 %a, %b
ret %c
@@ -0,0 +1,17 @@
; Division by zero traps.
; expect: run
; trap: T0004
; phase: 0
; spec: docs/spec/02-types-and-values.md
module test.division_by_zero
air 0
lang 0.1
features []
fn @main() -> i32
effects []
entry:
%a = const.i32 1
%b = const.i32 0
%c = div.checked.i32 %a, %b
ret %c
@@ -0,0 +1,14 @@
; The trap instruction traps.
; expect: run
; trap: T0001
; phase: 0
; spec: docs/spec/07a-air-instructions.md
module test.explicit_trap
air 0
lang 0.1
features []
fn @main() -> void
effects []
entry:
trap
@@ -0,0 +1,27 @@
; Iterative Fibonacci with loop-carried block parameters.
; expect: run
; result: 2880067194370816120
; phase: 0
; spec: docs/spec/07a-air-instructions.md
module test.fibonacci
air 0
lang 0.1
features []
fn @main() -> u64
effects []
entry:
%n = const.u64 90
%z = const.u64 0
%o = const.u64 1
br @loop(%z, %z, %o)
loop(%i: u64, %a: u64, %b: u64):
%d = ge.u64 %i, %n
cbr %d, @done(), @step()
step:
%c = add.checked.u64 %a, %b
%one = const.u64 1
%j = add.checked.u64 %i, %one
br @loop(%j, %b, %c)
done:
ret %a
+15
View File
@@ -0,0 +1,15 @@
; Phase 0 hello: @main returns a value that the run record reports (Q-008).
; expect: run
; result: 42
; phase: 0
; spec: docs/spec/07a-air-instructions.md
module test.hello
air 0
lang 0.1
features []
fn @main() -> u32
effects []
entry:
%v = const.u32 42
ret %v
@@ -0,0 +1,17 @@
; Shift by the bit width traps.
; expect: run
; trap: T0005
; phase: 0
; spec: docs/spec/02-types-and-values.md
module test.shift_out_of_range
air 0
lang 0.1
features []
fn @main() -> u32
effects []
entry:
%a = const.u32 1
%b = const.u32 32
%c = shl.u32 %a, %b
ret %c
@@ -0,0 +1,17 @@
; i64 MIN / -1 traps as overflow.
; expect: run
; trap: T0003
; phase: 0
; spec: docs/spec/02-types-and-values.md
module test.signed_min_div
air 0
lang 0.1
features []
fn @main() -> i64
effects []
entry:
%a = const.i64 -9223372036854775808
%b = const.i64 -1
%c = div.checked.i64 %a, %b
ret %c
@@ -0,0 +1,17 @@
; Remainder has the sign of the dividend.
; expect: run
; result: -1
; phase: 0
; spec: docs/spec/02-types-and-values.md
module test.truncating_remainder
air 0
lang 0.1
features []
fn @main() -> i32
effects []
entry:
%a = const.i32 -7
%b = const.i32 3
%c = rem.checked.i32 %a, %b
ret %c
@@ -0,0 +1,17 @@
; Wrapping add does not trap.
; expect: run
; result: 0
; phase: 0
; spec: docs/spec/07a-air-instructions.md
module test.wrapping_add
air 0
lang 0.1
features []
fn @main() -> u8
effects []
entry:
%a = const.u8 200
%b = const.u8 56
%c = add.wrap.u8 %a, %b
ret %c
@@ -0,0 +1,16 @@
; Wrapping cast keeps the low bits of the two's-complement value.
; expect: run
; result: 254
; phase: 0
; spec: docs/spec/02-types-and-values.md
module test.wrapping_cast
air 0
lang 0.1
features []
fn @main() -> u8
effects []
entry:
%a = const.i32 -2
%b = cast.wrap.u8 %a
ret %b