cli: add safe UTF-8 and supplied-buffer hex/base64 std modules

This commit is contained in:
dev committed 2026-10-06 17:06:39 +03:00
1 parent 6397a317e2
commit 3bb11e03b2
42 files changed
+2807 -14

No files matched your search

+5 -2
View File
@@ -115,13 +115,16 @@ test "standard imports lower identically in either order" {
defer a.deinit();
const arena = a.allocator();
const body = "fn main() -> u64\neffects []\n{ return std.math.min_u64(7, 11); }\n";
const first = try checkFile(arena, "a.aji", try std.mem.concat(arena, u8, &.{ "module t\nimport std.math;\nimport std.bytes;\n", body }));
const second = try checkFile(arena, "/another/directory/b.aji", try std.mem.concat(arena, u8, &.{ "module t\nimport std.bytes;\nimport std.math;\n", body }));
const first = try checkFile(arena, "a.aji", try std.mem.concat(arena, u8, &.{ "module t\nimport std.math;\nimport std.bytes;\nimport std.utf8;\nimport std.encoding.hex;\nimport std.encoding.base64;\n", body }));
const second = try checkFile(arena, "/another/directory/b.aji", try std.mem.concat(arena, u8, &.{ "module t\nimport std.encoding.base64;\nimport std.encoding.hex;\nimport std.bytes;\nimport std.math;\nimport std.utf8;\n", body }));
try std.testing.expectEqual(Status.accepted, first.status);
try std.testing.expectEqual(Status.accepted, second.status);
try std.testing.expectEqualStrings(first.lowered.?.air, second.lowered.?.air);
// Imported code enters the ordinary verifier with its original locations.
try std.testing.expect(std.mem.indexOf(u8, first.lowered.?.annotated, "; std/bytes.aji:") != null);
try std.testing.expect(std.mem.indexOf(u8, first.lowered.?.annotated, "; std/utf8.aji:") != null);
try std.testing.expect(std.mem.indexOf(u8, first.lowered.?.annotated, "; std/encoding/hex.aji:") != null);
try std.testing.expect(std.mem.indexOf(u8, first.lowered.?.annotated, "; std/encoding/base64.aji:") != null);
try std.testing.expect(std.mem.indexOf(u8, first.lowered.?.air, "intrinsic ") == null);
try std.testing.expect(std.mem.indexOf(u8, first.lowered.?.air, "own.") == null);
try std.testing.expect(std.mem.indexOf(u8, first.lowered.?.air, "cap<") == null);
+3
View File
@@ -9,7 +9,10 @@ const lower = @import("lower.zig");
const Entry = struct { name: []const u8, file: []const u8, source: []const u8 };
const registry = [_]Entry{
.{ .name = "std.bytes", .file = "std/bytes.aji", .source = @embedFile("std_bytes_aji") },
.{ .name = "std.encoding.base64", .file = "std/encoding/base64.aji", .source = @embedFile("std_encoding_base64_aji") },
.{ .name = "std.encoding.hex", .file = "std/encoding/hex.aji", .source = @embedFile("std_encoding_hex_aji") },
.{ .name = "std.math", .file = "std/math.aji", .source = @embedFile("std_math_aji") },
.{ .name = "std.utf8", .file = "std/utf8.aji", .source = @embedFile("std_utf8_aji") },
};
pub const Result = union(enum) { ok: ast.Module, err: lower.Problem };