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,15 @@
; Passes u16 to a block parameter of type u8.
; expect: reject E1001
; phase: 0
; spec: docs/spec/07a-air-instructions.md
module test.block_argument_type
air 0
lang 0.1
features []
fn @f(%a: u16) -> void
effects []
entry:
br @next(%a)
next(%x: u8):
ret
@@ -0,0 +1,15 @@
; Branch passes two arguments to a block with one parameter.
; expect: reject E5002
; phase: 0
; spec: docs/spec/07-air.md
module test.branch_arity
air 0
lang 0.1
features []
fn @f(%a: u8) -> u8
effects []
entry:
br @next(%a, %a)
next(%x: u8):
ret %x
@@ -0,0 +1,19 @@
; Calls @g with an i32 where u32 is expected.
; expect: reject E1001
; phase: 0
; spec: docs/spec/07a-air-instructions.md
module test.call_argument_type
air 0
lang 0.1
features []
fn @f(%a: i32) -> void
effects []
entry:
call @g(%a)
ret
fn @g(%x: u32) -> void
effects []
entry:
ret
@@ -0,0 +1,15 @@
; %a is defined twice.
; expect: reject E5001
; phase: 0
; spec: docs/spec/07-air.md
module test.double_definition
air 0
lang 0.1
features []
fn @f() -> u8
effects []
entry:
%a = const.u8 1
%a = const.u8 2
ret %a
@@ -0,0 +1,18 @@
; Two functions named @f.
; expect: reject E0003
; phase: 0
; spec: docs/spec/07-air.md
module test.duplicate_function
air 0
lang 0.1
features []
fn @f() -> void
effects []
entry:
ret
fn @f() -> void
effects []
entry:
ret
@@ -0,0 +1,13 @@
; f64 is reserved in format version 0.
; expect: reject E0006
; phase: 0
; spec: docs/spec/07-air.md
module test.float_reserved
air 0
lang 0.1
features []
fn @f(%x: f64) -> void
effects []
entry:
ret
@@ -0,0 +1,14 @@
; 256 does not fit in u8.
; expect: reject E0002
; phase: 0
; spec: docs/spec/07a-air-instructions.md
module test.literal_out_of_range
air 0
lang 0.1
features []
fn @f() -> u8
effects []
entry:
%a = const.u8 256
ret %a
@@ -0,0 +1,14 @@
; widen from i8 to u64 loses negative values.
; expect: reject E1002
; phase: 0
; spec: docs/spec/02-types-and-values.md
module test.lossy_widen
air 0
lang 0.1
features []
fn @f(%a: i8) -> u64
effects []
entry:
%b = cast.widen.u64 %a
ret %b
@@ -0,0 +1,17 @@
; enum.switch misses variant B and has no default.
; expect: reject E5002
; phase: 0
; spec: docs/spec/07a-air-instructions.md
module test.non_exhaustive_enum_switch
air 0
lang 0.1
features []
type @E = enum { A, B }
fn @f(%e: @E) -> void
effects []
entry:
enum.switch @E %e, A -> @x
x:
ret
@@ -0,0 +1,15 @@
; A struct contains itself by value.
; expect: reject E1003
; phase: 0
; spec: docs/spec/07-air.md
module test.recursive_type
air 0
lang 0.1
features []
type @Node = struct { value: u8, next: @Node }
fn @f() -> void
effects []
entry:
ret
@@ -0,0 +1,13 @@
; Returns u64 from a function declared to return u32.
; expect: reject E1001
; phase: 0
; spec: docs/spec/07a-air-instructions.md
module test.return_type_mismatch
air 0
lang 0.1
features []
fn @f(%a: u64) -> u32
effects []
entry:
ret %a
@@ -0,0 +1,14 @@
; Missing comma between operands.
; expect: reject E0001
; phase: 0
; spec: docs/reference/air-text.ebnf
module test.syntax_error
air 0
lang 0.1
features []
fn @f(%a: u8) -> u8
effects []
entry:
%b = add.checked.u8 %a %a
ret %b
@@ -0,0 +1,14 @@
; A terminator is followed by another instruction.
; expect: reject E5002
; phase: 0
; spec: docs/spec/07-air.md
module test.terminator_mid_block
air 0
lang 0.1
features []
fn @f() -> void
effects []
entry:
ret
ret
@@ -0,0 +1,13 @@
; 65 parameters exceed the limit of 64.
; expect: reject E5101
; phase: 0
; spec: docs/spec/08-verifier.md
module test.too_many_params
air 0
lang 0.1
features []
fn @f(%p0: u8, %p1: u8, %p2: u8, %p3: u8, %p4: u8, %p5: u8, %p6: u8, %p7: u8, %p8: u8, %p9: u8, %p10: u8, %p11: u8, %p12: u8, %p13: u8, %p14: u8, %p15: u8, %p16: u8, %p17: u8, %p18: u8, %p19: u8, %p20: u8, %p21: u8, %p22: u8, %p23: u8, %p24: u8, %p25: u8, %p26: u8, %p27: u8, %p28: u8, %p29: u8, %p30: u8, %p31: u8, %p32: u8, %p33: u8, %p34: u8, %p35: u8, %p36: u8, %p37: u8, %p38: u8, %p39: u8, %p40: u8, %p41: u8, %p42: u8, %p43: u8, %p44: u8, %p45: u8, %p46: u8, %p47: u8, %p48: u8, %p49: u8, %p50: u8, %p51: u8, %p52: u8, %p53: u8, %p54: u8, %p55: u8, %p56: u8, %p57: u8, %p58: u8, %p59: u8, %p60: u8, %p61: u8, %p62: u8, %p63: u8, %p64: u8) -> void
effects []
entry:
ret
@@ -0,0 +1,13 @@
; Branch to a label that does not exist.
; expect: reject E5002
; phase: 0
; spec: docs/spec/07-air.md
module test.unknown_block
air 0
lang 0.1
features []
fn @f() -> void
effects []
entry:
br @nowhere()
@@ -0,0 +1,14 @@
; frobnicate is not an AIR opcode; %a is then never defined.
; expect: reject E0004 E5001
; phase: 0
; spec: docs/spec/07-air.md
module test.unknown_opcode
air 0
lang 0.1
features []
fn @f() -> u8
effects []
entry:
%a = frobnicate.u8 1
ret %a
@@ -0,0 +1,8 @@
; AIR format version 7 is not implemented.
; expect: reject E0005
; phase: 0
; spec: docs/spec/07-air.md
module test.unsupported_version
air 7
lang 0.1
features []
@@ -0,0 +1,20 @@
; %x is defined on one path only but used after the join.
; expect: reject E5001
; phase: 0
; spec: docs/spec/07-air.md
module test.use_not_dominated
air 0
lang 0.1
features []
fn @f(%c: bool) -> u8
effects []
entry:
cbr %c, @a(), @b()
a:
%x = const.u8 1
br @join()
b:
br @join()
join:
ret %x