ajhahn.de
← Flash
Flash 49 lines
// base — the Zig interop shim for the core module.
//
// This is the only std module that may import Zig's std. Every other module
// under std/ is pure Flash and imports only `base` and its sibling modules,
// so the toolchain dependency stays confined to this one file — the same
// confinement rule the compiler's own support shim follows. The surface
// below is an enumerated bill of materials: additions land together with
// the module that needs them, never speculatively.

use std

// Memory: the allocator handle std signatures carry, and the alignment
// type its v-table functions receive. The aliases name the same types the
// compiler's shim re-exports, so signatures stay interchangeable across
// that facade.
pub const Allocator = std.mem.Allocator
pub const Alignment = std.mem.Alignment

// Test hooks, so the std modules' own Flash test blocks need no std import.
pub const expect = std.testing.expect
pub const expectEqual = std.testing.expectEqual
pub const expectEqualSlices = std.testing.expectEqualSlices
pub const expectEqualStrings = std.testing.expectEqualStrings
pub const expectError = std.testing.expectError
pub const testAlloc = std.testing.allocator

// Failure injection, so allocation-failure paths are provable from Flash
// test blocks: a child allocator that fails at a chosen allocation index,
// and the sweep driver that re-runs a body failing each of its allocations
// in turn, leak-checking every induced failure. Test-only surface, like
// the hooks above.
pub const FailingAllocator = std.testing.FailingAllocator
pub const checkAllAllocationFailures = std.testing.checkAllAllocationFailures

test "the shim surface is reachable" {
    _ = Allocator
    _ = Alignment
    try expect(true)
    try expectEqual(1, 1)
    try expectEqualSlices(u8, "ab", "ab")
    try expectEqualStrings("flash", "flash")
    _ = &expectError
    _ = FailingAllocator
    _ = &checkAllAllocationFailures
    s := try testAlloc.alloc(u8, 2)
    defer testAlloc.free(s)
    try expectEqual(2, s.len)
}