- 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)
39 lines
779 B
LLVM
39 lines
779 B
LLVM
; switch over integers and exhaustive enum.switch with payload binding.
|
|
; expect: accept
|
|
; phase: 0
|
|
; spec: docs/spec/07a-air-instructions.md
|
|
module test.switch_and_enums
|
|
air 0
|
|
lang 0.1
|
|
features []
|
|
|
|
type @Shape = enum { Empty, Square(u32), Rect(u32, u32) }
|
|
|
|
fn @area(%s: @Shape) -> u32
|
|
effects []
|
|
entry:
|
|
enum.switch @Shape %s, Empty -> @empty, Square -> @square, Rect -> @rect
|
|
empty:
|
|
%z = const.u32 0
|
|
ret %z
|
|
square(%side: u32):
|
|
%a = mul.checked.u32 %side, %side
|
|
ret %a
|
|
rect(%w: u32, %h: u32):
|
|
%b = mul.checked.u32 %w, %h
|
|
ret %b
|
|
|
|
fn @classify(%n: i8) -> u8
|
|
effects []
|
|
entry:
|
|
switch.i8 %n, -1 -> @neg(), 0 -> @zero(), default -> @other()
|
|
neg:
|
|
%a = const.u8 0
|
|
ret %a
|
|
zero:
|
|
%b = const.u8 1
|
|
ret %b
|
|
other:
|
|
%c = const.u8 2
|
|
ret %c
|