interp: serialize runtime values without recursive JSON nesting

This commit is contained in:
dev committed 2026-10-10 00:01:40 +03:00
1 parent 6353ab5f5d
commit c9064418bd
6 files changed
+422 -55

No files matched your search

@@ -0,0 +1,32 @@
; expect: run
; result: {"variant":"full","payload":[{"negative":-1,"flags":[false,true],"rows":[[7,14,21],[7,14,21]],"empty":{}},[0,255]]}
; phase: 1
; spec: docs/spec/07a-air-instructions.md Run result
module runtime.returned_json
air 0
lang 0.1
features [arrays, capabilities, effects, linear_aggregates, ownership, resources]
type @Empty = struct {}
type @Record = struct { negative: i128, flags: array<bool, 2>, rows: array<array<u16, 3>, 2>, empty: @Empty }
type @Choice = enum { empty, full(@Record, array<u8, 2>) }
fn @main() -> @Choice
effects []
entry:
%c_1 = const.u16 7
%c_2 = const.u16 14
%c_3 = const.u16 21
%arr_4 = array.make array<u16, 3>(%c_1, %c_2, %c_3)
%c_5 = const.i128 -1
%c_6 = const.bool false
%c_7 = const.bool true
%arr_8 = array.make array<bool, 2>(%c_6, %c_7)
%arr_9 = array.splat array<array<u16, 3>, 2> %arr_4
%s_10 = struct.make @Empty()
%s_11 = struct.make @Record(%c_5, %arr_8, %arr_9, %s_10)
%c_12 = const.u8 0
%c_13 = const.u8 255
%arr_14 = array.make array<u8, 2>(%c_12, %c_13)
%e_15 = enum.make @Choice.full(%s_11, %arr_14)
ret %e_15
@@ -0,0 +1,15 @@
// expect: run
// result: {"variant":"full","payload":[{"negative":-1,"flags":[false,true],"rows":[[7,14,21],[7,14,21]],"empty":{}},[0,255]]}
// phase: 6
// spec: docs/spec/07a-air-instructions.md Run result; docs/spec/15-source-language.md §5
module runtime.returned_json
struct Empty {}
struct Record { negative: i128, flags: [bool; 2], rows: [[u16; 3]; 2], empty: Empty }
enum Choice { empty, full(Record, [u8; 2]) }
fn main() -> Choice effects [] {
let row = [7u16, 14u16, 21u16];
let record = Record { negative: -1i128, flags: [false, true], rows: [row; 2], empty: Empty {} };
return Choice::full(record, [0u8, 255u8]);
}