Skip to content

6 standard library std eng

TransCompilator edited this page Nov 26, 2026 · 1 revision

6 Standard Library (std/*.eng)

Source: https://deepwiki.com/PonvasanthPon/TransCompilator/6-standard-library-std-eng

Standard Library (std/*.eng)

Relevant source files

The following files were used as context for generating this wiki page:

The TransCompilator standard library (std/*.eng) provides a zero-libc, self-hosted foundation implemented entirely in structured English. It establishes essential types, memory allocation, string management, buffered input/output, collections, math, and filesystem primitives. By targeting raw Linux system calls (Ask Linux kernel ...), programs compiled through tc_r1 execute without any external C runtime dependencies.

Sources: std/core.eng:1-68, std/alloc.eng:1-97, std/string.eng:1-177, std/io.eng:1-190

title "Standard Library Layering and Syscall Bridge"
graph TD
    subgraph "NaturalLanguageSpace"
        NL_Alloc[""allocate size bytes""]
        NL_Write[""say s (a pointer to TcString)""]
        NL_Parse[""parse whole number from text s""]
    end
    subgraph "CodeEntitySpace"
        CE_Alloc[""std/alloc.eng:heap_alloc""]
        CE_Write[""std/string.eng:print_str""]
        CE_Parse[""std/string.eng:str_parse_i64""]
        SyscallLayer[""Linux Kernel Syscalls mmap=9, write=1, exit=60""]
    end
    NL_Alloc --> CE_Alloc
    NL_Write --> CE_Write
    NL_Parse --> CE_Parse
    CE_Alloc --> SyscallLayer
    CE_Write --> SyscallLayer
Loading

Sources: std/core.eng:46-49, std/alloc.eng:48, std/string.eng:80


Core and Allocation

The core module (std/core.eng) defines foundational algebraic data types such as Option and Result, alongside system panic handlers and raw byte utilities std/core.eng:1-67. It provides inline option and result payloads with zero heap allocation overhead, alongside panic, assert_true, mem_zero, and mem_eq std/core.eng:3-67.

The allocation module (std/alloc.eng) implements a custom heap manager on top of Linux memory mapping (mmap, syscall 9) std/alloc.eng:1-96. It manages a shared free list of reusable MemoryBlock headers, aligning allocations to 16 bytes and handling block splitting, coalescing, and page-level growth (heap_alloc, heap_free, heap_realloc) std/alloc.eng:8-89.

For deep technical details, implementations, and verification tests, see Core and Allocation.

Sources: std/core.eng:1-68, std/alloc.eng:1-97

title "Core and Allocation Data Structures"
graph TD
    subgraph "EnglishRecordDefinitions"
        RecOpt[""Option of T""]
        RecRes[""Result of T and E""]
        RecBlk[""MemoryBlock""]
    end
    subgraph "CodeEntitySpace"
        SrcOpt[""std/core.eng:Option""]
        SrcRes[""std/core.eng:Result""]
        SrcBlk[""std/alloc.eng:MemoryBlock""]
        SrcAlloc[""std/alloc.eng:heap_alloc""]
    end
    RecOpt --> SrcOpt
    RecRes --> SrcRes
    RecBlk --> SrcBlk
    SrcBlk --> SrcAlloc
Loading

Sources: std/core.eng:6-8, std/alloc.eng:8-12


Strings and I/O

Strings are represented by TcString in std/string.eng, which wraps a byte pointer, length, and capacity, maintaining a final zero byte to ensure compatibility with kernel expectations std/string.eng:1-8. It exposes robust operations for text creation (str_new, str_from_bytes), resizing/appending (str_push_bytes), slicing, comparison (str_eq), and numeric parsing (str_parse_i64) std/string.eng:10-152.

Console input and formatted output are handled by std/io.eng, which provides conversion routines for integers, unsigned numbers, and decimals (format_u64_into, format_i64_into, format_f64_into) as well as buffered reading (read_i64_stdin, read_f64_stdin) interacting with Linux file descriptors std/io.eng:7-178.

For deep technical details, implementations, and verification tests, see Strings and I/O.

Sources: std/string.eng:1-177, std/io.eng:1-190


Collections, Math and Filesystem

The remainder of the standard library supplies collection containers, mathematical utilities, and operating system interface wrappers. std/list.eng and std/map.eng provide dynamic list and hash map containers built on top of std/alloc.eng. std/math.eng provides fundamental mathematical operations, while std/fs.eng wraps low-level Linux file operations (open, read, write, close) into structured English statements.

For deep technical details, implementations, and verification tests, see Collections, Math and Filesystem.

Sources: std/core.eng:1-68, std/alloc.eng:1-97, std/string.eng:1-177, std/io.eng:1-190


Clone this wiki locally