air: data model, text parser and canonical serializer (P0-4, P0-5, P0-6)
- src/air/module.zig: types, values, instructions, blocks, functions - src/air/parse.zig: lexer and parser for text AIR format 0 with name resolution; reports E0001-E0006, E5001 (undefined/double definition), E5002 (unknown block label) - src/air/print.zig: canonical serializer (spec 07 §8.5) with a deterministic round-trip fuzz test - diag registry: E0xxx, E1003, T0xxx
This commit is contained in:
1 parent
41b764ccfd
commit
ef6a2c5475
5 files changed
+1636
-9
No files matched your search
+17
-1
@@ -16,9 +16,17 @@ pub const Code = struct {
|
||||
};
|
||||
|
||||
pub const registry = [_]Code{
|
||||
// E0xxx — AIR text and module
|
||||
.{ .id = "E0001", .kind = "parse.unexpected_token", .meaning = "Token not allowed by the text AIR grammar here" },
|
||||
.{ .id = "E0002", .kind = "parse.invalid_literal", .meaning = "Literal malformed or not representable in its type" },
|
||||
.{ .id = "E0003", .kind = "parse.duplicate_name", .meaning = "Function, type, block, field or variant name defined twice" },
|
||||
.{ .id = "E0004", .kind = "parse.unknown_name", .meaning = "Unknown opcode, type, function, field or variant" },
|
||||
.{ .id = "E0005", .kind = "module.unsupported_version", .meaning = "AIR format or language version not implemented" },
|
||||
.{ .id = "E0006", .kind = "module.unsupported_feature", .meaning = "Required feature or reserved type not implemented" },
|
||||
// E1xxx — Types and values
|
||||
.{ .id = "E1001", .kind = "type.mismatch", .meaning = "Operand/result type mismatch" },
|
||||
.{ .id = "E1002", .kind = "type.invalid_cast", .meaning = "Cast not permitted by safe semantics" },
|
||||
.{ .id = "E1003", .kind = "type.recursive", .meaning = "Aggregate type contains itself by value" },
|
||||
.{ .id = "E1010", .kind = "init.read_uninitialized", .meaning = "Read from uninitialized storage" },
|
||||
// E2xxx — Memory and ownership
|
||||
.{ .id = "E2001", .kind = "ownership.use_after_move", .meaning = "Value used after ownership transfer" },
|
||||
@@ -50,6 +58,14 @@ pub const registry = [_]Code{
|
||||
// E6xxx — Unsafe/ABI
|
||||
.{ .id = "E6001", .kind = "unsafe.required", .meaning = "Operation requires explicit unsafe boundary" },
|
||||
.{ .id = "E6101", .kind = "abi.unaligned_reference", .meaning = "Normal reference requested from insufficiently aligned storage" },
|
||||
// T0xxx — Runtime traps (reported in trap records, not by the verifier)
|
||||
.{ .id = "T0001", .kind = "trap.explicit", .meaning = "`trap` instruction executed" },
|
||||
.{ .id = "T0002", .kind = "trap.assert", .meaning = "Assertion failed" },
|
||||
.{ .id = "T0003", .kind = "trap.overflow", .meaning = "Checked arithmetic result not representable" },
|
||||
.{ .id = "T0004", .kind = "trap.division_by_zero", .meaning = "Division or remainder by zero" },
|
||||
.{ .id = "T0005", .kind = "trap.shift_out_of_range", .meaning = "Shift amount negative or not less than bit width" },
|
||||
.{ .id = "T0006", .kind = "trap.cast_out_of_range", .meaning = "Checked cast value not representable in target type" },
|
||||
.{ .id = "T0007", .kind = "trap.call_depth", .meaning = "Call depth limit (1 024 frames) exceeded" },
|
||||
};
|
||||
|
||||
pub fn lookup(id: []const u8) ?*const Code {
|
||||
@@ -158,7 +174,7 @@ test "registry mirrors docs/reference/error-codes.md" {
|
||||
var lines = std.mem.splitScalar(u8, md, '\n');
|
||||
while (lines.next()) |line| {
|
||||
// Table rows look like: | E1001 | type.mismatch | Meaning |
|
||||
if (!std.mem.startsWith(u8, line, "| E")) continue;
|
||||
if (!std.mem.startsWith(u8, line, "| E") and !std.mem.startsWith(u8, line, "| T")) continue;
|
||||
var cols = std.mem.tokenizeScalar(u8, line, '|');
|
||||
const id = std.mem.trim(u8, cols.next().?, " ");
|
||||
const kind = std.mem.trim(u8, cols.next().?, " ");
|
||||
|
||||
Reference in new issue
Block a user