### Build and run 'add.0' example Source: https://github.com/vercel-labs/zerolang/blob/main/examples/README.md Shows how to build and run an executable program using ZeroLang CLI commands. This example demonstrates basic arithmetic operations. ```sh bin/zero dev --json --target linux-musl-x64 examples/add.0 ``` ```sh bin/zero build --emit exe --target linux-musl-x64 examples/add.0 --out .zero/out/add ``` ```sh bin/zero ship --target linux-musl-x64 examples/add.0 --out .zero/ship/add ``` ```sh ./.zero/out/add ``` -------------------------------- ### ZeroLang Filesystem Example: Create, Write, Rename, and Remove Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/modules/fs.md This example demonstrates creating a file, writing content to it, checking its length, renaming it, and finally removing it. It utilizes several functions from the `std.fs` module and includes error handling with `raises` and `check`. ```zero pub fn main(world: World) -> Void raises [NotFound, TooLarge, Io] { let fs: Fs = std.fs.host() var file: owned = check std.fs.createOrRaise(fs, ".zero/out/example.txt") check std.fs.writeAllOrRaise(&mut file, std.mem.span("hello\n")) let len: usize = check std.fs.fileLenOrRaise(&mut file) std.fs.close(&mut file) if len == 6 && std.fs.exists(".zero/out/example.txt") { if std.fs.rename(".zero/out/example.txt", ".zero/out/example-renamed.txt") { if std.fs.remove(".zero/out/example-renamed.txt") { check world.out.write("fs ok\n") } } } } ``` -------------------------------- ### Install Zero Extension for Cursor Source: https://github.com/vercel-labs/zerolang/blob/main/extensions/vscode/README.md Install the Zero language extension into Cursor from the repository root using pnpm. ```sh pnpm run extension:install:cursor ``` -------------------------------- ### List Available Targets and Build Example Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/cross-compilation.md Lists available targets and demonstrates building a memory package for a specific target. ```sh bin/zero targets bin/zero check --target linux-musl-x64 examples/memory-package bin/zero build --target linux-musl-x64 examples/memory-package --out .zero/out/memory-package ``` -------------------------------- ### Check systems-package example Source: https://github.com/vercel-labs/zerolang/blob/main/examples/README.md Illustrates `zero.json`, multiple source files, `defer`, and standard library helpers. Useful for understanding multi-file project structure. ```sh bin/zero check examples/systems-package ``` -------------------------------- ### Check Immutable Let Bindings Source: https://github.com/vercel-labs/zerolang/blob/main/examples/README.md This command checks the 'hello-let.0' example, which teaches about immutable 'let' bindings in Zero. ```sh bin/zero check examples/hello-let.0 ``` -------------------------------- ### Install Latest Zero Release Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/install.md Installs the latest Zero release using a curl script and adds it to your PATH. Verifies the installation with `zero --version`. ```sh curl -fsSL https://zerolang.ai/install.sh | bash export PATH="$HOME/.zero/bin:$PATH" zero --version ``` -------------------------------- ### Example ProgramGraph Output Source: https://github.com/vercel-labs/zerolang/blob/main/README.md Example output from the 'zero graph dump' command, showing the structure of a zerolang program. ```text zero-graph v1 origin source-text module "hello" hash "graph:b8a019041020df03" node #ea5ea1ca Function name:"main" type:"Void" public:true fallible:true node #f9ce8b3e Param name:"world" type:"World" node #421a4d4b MethodCall name:"write" type:"Void" node #610c78bf Literal type:"String" value:"hello from zero\n" edge #421a4d4b arg #610c78bf order:0 edge #ea5ea1ca body #6c48dda8 ``` -------------------------------- ### Explain error-tour example Source: https://github.com/vercel-labs/zerolang/blob/main/examples/README.md Demonstrates copyable failing commands and repaired fixtures for common diagnostics. Useful for understanding and debugging ZeroLang errors. ```sh bin/zero explain TAR002 ``` -------------------------------- ### Build Compiler from Source Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/install.md Installs dependencies, builds the native Zero compiler from a local checkout, and verifies the build. ```sh pnpm install make -C native/zero-c bin/zero --version ``` -------------------------------- ### Check Multiple Zero Examples Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/getting-started.md Runs the Zero checker on a series of example files to demonstrate core language features like bindings, functions, conditionals, and types. ```sh zero check examples/hello.0 zero check examples/hello-let.0 zero check examples/functions.0 zero check examples/branch.0 zero check examples/point.0 zero check examples/result-choice.0 ``` -------------------------------- ### Run Quick Command Loop Examples Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/building-from-source.md Demonstrates common ZeroLang command-line operations for checking code, building executables for specific targets, and running the compiled output. ```sh bin/zero check examples/hello.0 bin/zero build --emit exe --target linux-musl-x64 examples/add.0 --out .zero/out/add ./.zero/out/add ``` -------------------------------- ### Build Executable for Helper Functions and Return Values Source: https://github.com/vercel-labs/zerolang/blob/main/examples/README.md This command builds the 'add.0' example, which demonstrates helper functions, the 'return' keyword, and 'if'/'else' control flow. It emits an executable file. ```sh bin/zero build --emit exe --target linux-musl-x64 examples/add.0 --out .zero/out/add ``` -------------------------------- ### Integer Type Examples Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/learn-zero.md Illustrates explicit integer width declarations and literal formatting with separators and suffixes. ```zero let count: u32 = 0x12c_u32 let byte: u8 = count as u8 ``` -------------------------------- ### Integer Literal Examples Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/primitives.md Demonstrates the use of various integer literals with different bases, separators, and suffixes. ```zero let count: u32 = 0x12c_u32 let byte: u8 = 255 let page: usize = 4_096 ``` -------------------------------- ### Standard Library Imports in Zero Source: https://github.com/vercel-labs/zerolang/blob/main/skill-data/packages.md Examples of importing modules from the Zero standard library. Ensure imports are explicit and known. ```zero use std.mem use std.parse ``` -------------------------------- ### Creating and Writing to a Hosted File Source: https://github.com/vercel-labs/zerolang/blob/main/skill-data/stdlib.md Shows how to create a file using `std.fs.createOrRaise` and write data to it using `std.fs.writeAllOrRaise`. This example uses explicit file handles and error propagation. ```zero pub fn main() -> Void raises { let fs: Fs = std.fs.host() var file: owned = check std.fs.createOrRaise(fs, ".zero/out/log.txt") check std.fs.writeAllOrRaise(&mut file, std.mem.span("hello\n")) } ``` -------------------------------- ### Build memory-package example Source: https://github.com/vercel-labs/zerolang/blob/main/examples/README.md Exercises target-neutral package imports and byte-span helper checks without hosted file I/O. Suitable for cross-compilation testing. ```sh bin/zero build --target linux-musl-x64 examples/memory-package --out .zero/out/memory-package ``` -------------------------------- ### Check resource-cli example Source: https://github.com/vercel-labs/zerolang/blob/main/examples/README.md Demonstrates args/env fallback, path joins, `std.mem.copy`/`fill`, and named-error owned-file resources. Useful for command-line argument parsing and resource management. ```sh bin/zero check examples/resource-cli ``` -------------------------------- ### Zero Project Manifest Example Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/getting-started.md A sample 'zero.json' manifest file defining package metadata and target configurations for a Zero project. ```json { "package": { "name": "systems-package", "version": "0.1.0" }, "targets": { "cli": { "kind": "exe", "main": "src/main.0" } } } ``` -------------------------------- ### Check config-shape.0 example Source: https://github.com/vercel-labs/zerolang/blob/main/examples/README.md Demonstrates `extern c` and `extern type` with C-shaped data. Use this to verify C interoperability. ```sh bin/zero check examples/config-shape.0 ``` -------------------------------- ### Build Object File for i64/u64 Support Source: https://github.com/vercel-labs/zerolang/blob/main/examples/README.md This command builds the 'direct-i64-return.0' example as an object file, showcasing direct ELF64 object backend support for i64/u64 values. ```sh bin/zero build --emit obj --target linux-musl-x64 examples/direct-i64-return.0 --out .zero/out/direct-i64-return.o ``` -------------------------------- ### Check Basic Hello World Program Source: https://github.com/vercel-labs/zerolang/blob/main/examples/README.md This command checks the 'hello.0' example, which demonstrates the basic 'pub fn main', 'World' string, 'check' command, and stdout functionality. ```sh bin/zero check examples/hello.0 ``` -------------------------------- ### Perform a GET Request Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/modules/http.md Makes a GET request to a specified URL and handles the response. Includes a timeout and checks for successful retrieval. ```zero pub fn main(world: World) -> Void raises { let net: Net = std.net.host() let client: HttpClient = std.http.client(net) var response: [512]u8 = [0_u8; 512] let request: Span = std.mem.span("GET https://example.com\n\n") let result: HttpResult = std.http.fetch(client, request, response, std.time.ms(1000)) if std.http.resultOk(result) { check world.out.write("http get ok\n") return } check world.err.write("http get failed\n") } ``` -------------------------------- ### Get Machine-Readable Explain Output Source: https://github.com/vercel-labs/zerolang/blob/main/skill-data/diagnostics.md Run the 'zero explain' command with the --json flag to get machine-readable output for diagnostic explanations. This provides stable fields for automation. ```sh zero explain --json ``` -------------------------------- ### Check direct-package-call-order example Source: https://github.com/vercel-labs/zerolang/blob/main/examples/README.md Illustrates direct backend package merge order and cross-module helper calls. Use this to understand package dependency resolution. ```sh bin/zero check examples/direct-package-call-order ``` -------------------------------- ### Check While Loop Syntax Source: https://github.com/vercel-labs/zerolang/blob/main/examples/README.md This command checks the 'countdown.0' example, which demonstrates the 'while' loop syntax in Zero. ```sh bin/zero check examples/countdown.0 ``` -------------------------------- ### Float Literal Examples Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/learn-zero.md Demonstrates the use of `f32` and `f64` for decimal numbers, including scientific notation and basic arithmetic. ```zero let ratio: f64 = 1.0e-3 let small: f32 = 0.5 let total: f64 = ratio + 2.0 ``` -------------------------------- ### Check readall-cli example Source: https://github.com/vercel-labs/zerolang/blob/main/examples/README.md Shows package-local imports, named errors, `std.fs.readAll`, and explicit fixed-buffer allocation. Good for learning file I/O and error handling patterns. ```sh bin/zero check examples/readall-cli ``` -------------------------------- ### Common Zero CLI Entry Points Source: https://github.com/vercel-labs/zerolang/blob/main/skills/zero/SKILL.md Provides examples of frequently used Zero CLI commands for code analysis, graphing, size estimation, and explanation. ```sh zero check zero graph zero graph view zero graph check zero graph dump --json zero size zero explain ``` -------------------------------- ### Run ZeroLang in Development Mode Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/cli-reference.md Starts the ZeroLang development server for live reloading. Supports JSON output, tracing, specifying a target, and input file. ```sh zero dev [--json] [--trace] [--target ] ``` -------------------------------- ### Fixed Buffer Allocation Example Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/modules/mem.md Illustrates allocating memory from a fixed-size buffer using `std.mem.fixedBufAlloc` and `std.mem.allocBytes`. This is useful for scenarios where memory must be managed within a predefined buffer. ```zero pub fn main(world: World) -> Void raises { var storage: [8]u8 = [0, 0, 0, 0, 0, 0, 0, 0] var alloc: FixedBufAlloc = std.mem.fixedBufAlloc(storage) let bytes: Maybe> = std.mem.allocBytes(alloc, 4) if bytes.has { bytes.value[0] = 90 check world.out.write("fixed buffer allocated\n") } } ``` -------------------------------- ### Check batch3-cli example Source: https://github.com/vercel-labs/zerolang/blob/main/examples/README.md Covers module graph metadata, local `rescue`, path helpers, named fs errors, and explicit allocation. Use this to explore advanced error handling and path manipulation. ```sh bin/zero check examples/batch3-cli ``` -------------------------------- ### Get ZeroLang Version Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/cli-reference.md Displays the installed ZeroLang version. The --json flag outputs the version in JSON format. ```sh zero --version [--json] ``` -------------------------------- ### Get Language Skill Source: https://github.com/vercel-labs/zerolang/blob/main/README.md Command to retrieve the language guide bundled with the zerolang compiler. This provides documentation on the language syntax and features. ```bash zero skills get language ``` -------------------------------- ### Interact with World capability Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/primitives.md Example of interacting with the 'World' capability to perform an output write operation. This demonstrates basic effect handling in ZeroLang. ```zero pub fn main(world: World) -> Void raises { check world.out.write("hello\n") } ``` -------------------------------- ### Import and use std.parse primitives Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/learn-zero.md Import the `std.parse` module to use primitives for character classification. This example checks if a character is an ASCII digit and if it's a valid identifier start. ```zero use std.parse pub fn main(world: World) -> Void raises { let digit: Bool = std.parse.isAsciiDigit("7") let ident: Bool = std.parse.isIdentifierStart("_") if digit && ident { check world.out.write("parse primitives ok\n") } } ``` -------------------------------- ### Build Object File for Byte-View Relocations Source: https://github.com/vercel-labs/zerolang/blob/main/examples/README.md This command builds the 'direct-byte-view-reloc.0' example as an object file, demonstrating direct ELF64 readonly byte-view relocations for string-backed span locals. ```sh bin/zero build --emit obj --target linux-musl-x64 examples/direct-byte-view-reloc.0 --out .zero/out/direct-byte-view-reloc.o ``` -------------------------------- ### Check Direct Backend Stack-Memory Bounds Traps Source: https://github.com/vercel-labs/zerolang/blob/main/examples/README.md This command checks the 'direct-array-bounds-trap.0' example, which demonstrates direct backend stack-memory bounds traps. ```sh bin/zero check examples/direct-array-bounds-trap.0 ``` -------------------------------- ### Manage Version-Matched Skills Source: https://github.com/vercel-labs/zerolang/blob/main/skills/zero/SKILL.md Commands to list, get, and retrieve full details of skills bundled with a specific Zero version. Essential for development workflows. ```sh zero skills list zero skills get zero zero skills get zero --full ``` -------------------------------- ### Organize a package with module imports Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/learn-zero.md Structure a Zero package by organizing source files under `src/` and importing standard library modules. This example imports `std.codec`, `std.parse`, and `std.time` for various operations. ```zero use std.codec use std.parse use std.time pub fn main(world: World) -> Void raises { defer cleanup() let current: Status = status() let result: Result = Result.ok let word: i32 = std.codec.readU32("abcd") let digits: i32 = std.parse.scanDigits("123abc") let duration: i32 = std.time.add(std.time.ms(5), std.time.seconds(1)) if digits == 3 && word > 0 && std.time.asMsFloor(duration) > 0 { check world.out.write("systems package\n") } } ``` -------------------------------- ### Check Direct Backend Bump Allocation Source: https://github.com/vercel-labs/zerolang/blob/main/examples/README.md This command checks the 'direct-alloc-bump.0' example, demonstrating direct backend explicit 'FixedBufAlloc' bump allocation over caller-provided storage. ```sh bin/zero check examples/direct-alloc-bump.0 ``` -------------------------------- ### Zero Test Block Example Source: https://github.com/vercel-labs/zerolang/blob/main/skill-data/testing.md Define a simple function and write a test block to verify its behavior using the `expect` keyword. A false expectation fails the test. ```zero fn add(left: i32, right: i32) -> i32 { return left + right } test "addition works" { expect add(2, 3) == 5 } ``` -------------------------------- ### Zero Diagnostic JSON Schema Example Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/diagnostics.md An example of the structured JSON output for diagnostics, providing detailed information for programmatic use. ```json { "schemaVersion": 1, "ok": false, "diagnostics": [ { "severity": "error", "code": "NAM003", "message": "unknown identifier 'message'", "path": "examples/hello.0", "line": 2, "column": 27, "length": 7, "expected": "visible local, parameter, function, or builtin", "actual": "no visible symbol named 'message'", "help": "declare the name before using it", "fixSafety": "behavior-preserving", "repair": { "id": "manual-review", "summary": "Inspect the diagnostic fields and choose a repair manually." }, "related": [] } ] } ``` -------------------------------- ### Write and Check a 'Hello World' Program Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/getting-started.md Creates a simple 'hello.0' file that writes 'hello from zero' to standard output and then checks its syntax using the Zero checker. ```zero pub fn main(world: World) -> Void raises { check world.out.write("hello from zero\n") } ``` ```sh zero check hello.0 ``` -------------------------------- ### Check Direct Backend Byte-Span Equality Source: https://github.com/vercel-labs/zerolang/blob/main/examples/README.md This command checks the 'direct-string-eql.0' example, which demonstrates direct backend byte-span equality over readonly string views. ```sh bin/zero check examples/direct-string-eql.0 ``` -------------------------------- ### Check Direct Backend Generic Vector Layout Source: https://github.com/vercel-labs/zerolang/blob/main/examples/README.md This command checks the 'direct-generic-vec.0' example, demonstrating direct backend generic fixed-capacity vector layouts for various element kinds. ```sh bin/zero check examples/direct-generic-vec.0 ``` -------------------------------- ### Initialize HTTP Client and Server Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/modules/http.md Sets up a basic HTTP client and server. This snippet demonstrates the initialization of network components and parsing of HTTP methods. ```zero pub fn main(world: World) -> Void raises { let net: Net = std.net.host() let addr: Address = std.net.address("localhost", 8080_u16) let _client: HttpClient = std.http.client(net) let _server: HttpServer = std.http.server(net, addr) let method: HttpMethod = std.http.parseMethod("GET") if method == std.http.parseMethod("GET") && std.mem.len(std.mem.span("body")) == 4 { check world.out.write("http ok\n") } } ``` -------------------------------- ### Check Direct Backend Local Rescue Fallback Source: https://github.com/vercel-labs/zerolang/blob/main/examples/README.md This command checks the 'direct-rescue-basic.0' example, demonstrating direct backend local 'rescue' fallback mechanisms over a raised error. ```sh bin/zero check examples/direct-rescue-basic.0 ``` -------------------------------- ### Build a Zero Executable Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/install.md Compiles a Zero project (`examples/hello.0`) into a native executable for a specified target (`linux-musl-x64`). ```sh zero build --emit exe --target linux-musl-x64 examples/hello.0 --out .zero/out/hello ``` -------------------------------- ### Build and Run an Executable Program Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/getting-started.md Creates an 'add.0' program that performs a simple calculation and writes the result to standard output. It then runs the program using the Zero runtime. ```zero fn answer() -> i32 { return 40 + 2 } pub fn main(world: World) -> Void raises { let value: i32 = answer() if value == 42 { check world.out.write("math works\n") } else { check world.out.write("math broke\n") } } ``` ```sh zero run add.0 ``` -------------------------------- ### Check Direct Backend Local Byte Views Source: https://github.com/vercel-labs/zerolang/blob/main/examples/README.md This command checks the 'direct-byte-view-locals.0' example, which covers direct backend local 'String'/'Span' pointer-length byte views. ```sh bin/zero check examples/direct-byte-view-locals.0 ``` -------------------------------- ### Explain and Plan Repairs with JSON Source: https://github.com/vercel-labs/zerolang/blob/main/README.md Use 'zero explain --json' to get explanations for diagnostic codes and 'zero fix --plan --json' to generate typed repair plans. These commands aid in understanding and automating code fixes. ```bash zero explain --json TYP009 ``` ```bash zero fix --plan --json examples/agent-repair-demo/broken.0 ``` -------------------------------- ### Get Machine-Readable Check Output Source: https://github.com/vercel-labs/zerolang/blob/main/skill-data/diagnostics.md Run the 'zero check' command with the --json flag to get machine-readable output. This is useful for scripts and tools that need stable fields. ```sh zero check --json ``` -------------------------------- ### Example Usage of Math Helpers Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/modules/math.md Demonstrates the usage of std.math.gcdU32 and std.math.isPrimeU32 functions within a ZeroLang program. This snippet checks if the greatest common divisor of 84 and 30 is 6 and if 31 is a prime number. ```zero pub fn main(world: World) -> Void raises { if std.math.gcdU32(84, 30) == 6 && std.math.isPrimeU32(31) { check world.out.write("math helper ok\n") } } ``` -------------------------------- ### Standard Library Symbol Metadata Example Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/standard-library.md Public standard library symbols document metadata for safe invocation, including effects, allocation behavior, target support, error behavior, ownership notes, and example paths. ```text symbol: std.fs.readAllOrRaise effects: fs allocation behavior: caller allocator target support: host error behavior: `raises [NotFound, TooLarge, Io]` ownership notes: returns owned example: examples/readall-cli/ ``` -------------------------------- ### Check Local Environment with Zero Doctor Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/install.md Verifies your local environment setup for Zero development. Use `--json` for detailed output including target toolchains readiness. ```sh zero doctor ``` ```sh zero doctor --json ``` -------------------------------- ### Get Specific Skill Content Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/cli-reference.md Retrieves the content for a specific skill, such as 'zero'. ```sh zero skills get zero ``` -------------------------------- ### Expected Output of 'zero run examples/add.0' Source: https://github.com/vercel-labs/zerolang/blob/main/README.md The expected output when running the 'examples/add.0' program, demonstrating basic arithmetic functionality. ```text math works ``` -------------------------------- ### Check Direct Backend Mutable Byte Copy/Fill Source: https://github.com/vercel-labs/zerolang/blob/main/examples/README.md This command checks the 'direct-byte-copy-fill.0' example, which shows direct backend mutable byte copy and fill operations over fixed buffers. ```sh bin/zero check examples/direct-byte-copy-fill.0 ``` -------------------------------- ### Check zero-hash cross-target status Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/examples.md Command to check the JSON status for the zero-hash example on Linux-musl-x64. ```sh bin/zero check --json --target linux-musl-x64 examples/zero-hash ``` -------------------------------- ### Inspect zero-hash graph metadata Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/examples.md Command to inspect the JSON graph metadata for the zero-hash example. ```sh bin/zero graph --json examples/zero-hash ``` -------------------------------- ### Build Direct Executable and Object File Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/cross-compilation.md Demonstrates building a direct executable and an object file for different targets. ```sh bin/zero build --emit exe --target linux-musl-x64 examples/direct-exe-return.0 --out .zero/out/direct-exe-return bin/zero build --emit obj --target darwin-arm64 examples/direct-call-add.0 --out .zero/out/direct-call-add.o ``` -------------------------------- ### Static Value Parameter Check Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/diagnostics.md Demonstrates how static value parameters are checked before emission to ensure fixed-size layouts remain concrete. This example shows a type with a static size parameter. ```zero type FixedVec { len: usize, items: [N]T, } fn first(vec: ref>) -> T { return vec.items[0] } let vec: FixedVec = FixedVec { len: 4, items: [1, 2, 3, 4] } let bad: u8 = first(&vec) ``` -------------------------------- ### Build with Different Compiler Profiles Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/examples.md Illustrates building a Zero program using different compiler profiles (debug, fast, small). Each profile offers different trade-offs between build time, performance, and artifact size. ```sh bin/zero build --json --profile debug --target linux-musl-x64 examples/hello.0 --out .zero/out/hello-debug bin/zero build --json --profile fast --target linux-musl-x64 examples/hello.0 --out .zero/out/hello-fast bin/zero build --json --profile small --target linux-musl-x64 examples/hello.0 --out .zero/out/hello-small ``` -------------------------------- ### Get ZeroLang Tokens Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/cli-reference.md Tokenizes ZeroLang source code and outputs the tokens in JSON format. ```sh zero tokens --json ``` -------------------------------- ### Check Direct Backend Signed LEB Literals and Helper Calls Source: https://github.com/vercel-labs/zerolang/blob/main/examples/README.md This command checks the 'direct-u8-helper-call.0' example, which covers direct backend signed LEB literals, byte arrays, and helper calls. ```sh bin/zero check examples/direct-u8-helper-call.0 ``` -------------------------------- ### Get zero-hash size report Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/examples.md Command to generate a JSON size report for the zero-hash executable. ```sh bin/zero size --json --target linux-musl-x64 examples/zero-hash --out .zero/out/zero-hash-size.json ``` -------------------------------- ### Check Direct Backend Token Shape Layout Source: https://github.com/vercel-labs/zerolang/blob/main/examples/README.md This command checks the 'direct-token-shape.0' example, which covers direct backend stack layout for type literals, field loads, defaults, and field stores. ```sh bin/zero check examples/direct-token-shape.0 ``` -------------------------------- ### Importing Standard Library Modules Source: https://github.com/vercel-labs/zerolang/blob/main/skill-data/stdlib.md Demonstrates how to import modules from the Zero standard library. Functions are called using their full module path. ```zero use std.mem use std.parse ``` -------------------------------- ### Explain Diagnostics and Inspect Repair Plans Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/building-from-source.md Uses `bin/zero explain` to understand diagnostics and `bin/zero fix` to inspect repair plans without modifying files. ```sh bin/zero explain TAR002 bin/zero fix --plan --json conformance/native/fail/mem-copy-immutable-dst.0 ``` -------------------------------- ### Get Full Skill Content Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/cli-reference.md Retrieves the full content for a specific skill, such as 'zero', including all details. ```sh zero skills get zero --full ``` -------------------------------- ### Get Standard Library Skill Source: https://github.com/vercel-labs/zerolang/blob/main/README.md Command to retrieve information about the standard library provided by the zerolang compiler. ```bash zero skills get stdlib ``` -------------------------------- ### Get Diagnostics Skill Source: https://github.com/vercel-labs/zerolang/blob/main/README.md Command to retrieve information about diagnostics (errors, warnings) supported by the zerolang compiler. ```bash zero skills get diagnostics ``` -------------------------------- ### Create a New Zero Project Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/getting-started.md Initializes a new Zero project named 'cli', navigates into the project directory, and performs standard project checks and builds. ```sh zero new cli hello cd hello zero check . zero test . zero run . zero build --target linux-musl-x64 --out .zero/out/hello . ``` -------------------------------- ### Basic Hello World Program Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/learn-zero.md The smallest runnable Zero program. It exports a `main` function that writes 'hello from zero\n' to standard output. ```zero pub fn main(world: World) -> Void raises { check world.out.write("hello from zero\n") } ``` -------------------------------- ### Check Booleans and Branches Source: https://github.com/vercel-labs/zerolang/blob/main/examples/README.md This command checks the 'branch.0' example, which covers the use of booleans and conditional branching in Zero. ```sh bin/zero check examples/branch.0 ``` -------------------------------- ### Run docs site development server Source: https://github.com/vercel-labs/zerolang/blob/main/examples/README.md Command to run the ZeroLang documentation site in development mode. Use this to view and test the documentation locally. ```sh pnpm run docs:dev ``` -------------------------------- ### Defining and Calling a Helper Function Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/learn-zero.md Shows how to define a simple function `answer` that returns an integer and call it from `main`. ```zero fn answer() -> i32 { return 40 + 2 } pub fn main(world: World) -> Void raises { let value: i32 = answer() if value == 42 { check world.out.write("math works\n") } else { check world.out.write("math broke\n") } } ``` -------------------------------- ### Build and Compare Profile Contracts and Size Metadata Source: https://github.com/vercel-labs/zerolang/blob/main/examples/README.md Use these commands to build Zero programs with different profiles and targets, and to check their size. The output includes JSON reports detailing profile semantics, budgets, size breakdowns, and optimization hints. ```sh bin/zero build --json --profile debug --target linux-musl-x64 examples/hello.0 --out .zero/out/hello-debug bin/zero build --json --profile fast --target linux-musl-x64 examples/hello.0 --out .zero/out/hello-fast bin/zero build --json --profile small --target linux-musl-x64 examples/hello.0 --out .zero/out/hello-small bin/zero size --json --profile tiny --target linux-musl-x64 examples/fixed-vec.0 ``` -------------------------------- ### Example Zero Diagnostic Message Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/diagnostics.md A typical error message from the Zero compiler, detailing the error code, location, and explanation. ```text error[NAM003]: Unknown identifier unknown identifier 'message' examples/hello.0:2:27 2 | check world.out.write(message) | ^^^^^^^ rule: Names must be declared before use in the current lexical scope. expected: local binding, parameter, function, builtin value actual: no visible symbol named 'message' fix: Introduce a local binding before this use (local-edit) explain: zero explain NAM003 ``` -------------------------------- ### Using Bindings with `let` Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/learn-zero.md Demonstrates how to declare and use immutable local bindings with `let` to store values like strings. ```zero pub fn main(world: World) -> Void raises { let message: String = "hello from a binding\n" check world.out.write(message) } ``` -------------------------------- ### std.fs.makeDir Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/modules/fs.md Creates a hosted directory. ```APIDOC ## std.fs.makeDir ### Description Creates a hosted directory. ### Method `std.fs.makeDir(path: string) -> Bool` ### Parameters #### Path Parameters - **path** (string) - Required - The path of the directory to create. ### Return Value - **Bool** - `true` if the directory was created successfully, `false` otherwise. ``` -------------------------------- ### Character Literal Examples Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/learn-zero.md Shows how to use `char` for single-quoted byte literals and comparisons, including hexadecimal escape sequences. ```zero let letter: char = 'A' let newline: char = '\n' let same: Bool = letter == '\x41' ``` -------------------------------- ### Create New ZeroLang Project Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/cli-reference.md Initializes a new ZeroLang project of type cli, lib, or package at the specified path. ```sh zero new cli|lib|package ``` -------------------------------- ### std.fs.host Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/modules/fs.md Creates the hosted filesystem capability. ```APIDOC ## std.fs.host ### Description Creates the hosted filesystem capability. ### Method `std.fs.host() -> Fs` ### Return Value - **Fs** - The hosted filesystem capability. ``` -------------------------------- ### Get ZeroLang Size Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/cli-reference.md Calculates the size of a ZeroLang input. Supports JSON output, specifying a target, and outputting to an artifact. ```sh zero size [--json] [--target ] [--out ] ``` -------------------------------- ### Get memory profile Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/optimization.md Generates a memory profile for a project, including JSON output for detailed memory usage information. ```sh bin/zero mem --json examples/allocator-collections.0 ``` -------------------------------- ### Get ZeroLang Graph Size Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/cli-reference.md Calculates the size of a ZeroLang program graph or package, outputting the result to a specified artifact file. ```sh zero graph size [--json] [--target ] --out ``` -------------------------------- ### Explain a Diagnostic Code in JSON Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/diagnostics.md Use `zero explain --json` to get a machine-readable JSON explanation for a diagnostic code. ```shell zero explain --json TYP009 ``` -------------------------------- ### Explain Zero Diagnostic Code Source: https://github.com/vercel-labs/zerolang/blob/main/skill-data/diagnostics.md Use this command to get an explanation for a specific Zero diagnostic code. This helps in understanding the error. ```sh zero explain ``` -------------------------------- ### Get Specific Zero Skill Information Source: https://github.com/vercel-labs/zerolang/blob/main/skill-data/agent.md Retrieve detailed information about specific Zero skills like language, graph, or diagnostics. ```sh zero skills get language zero skills get graph zero skills get diagnostics ``` -------------------------------- ### Build Zero Executable Source: https://github.com/vercel-labs/zerolang/blob/main/skill-data/builds.md Use 'zero build --emit exe' to create an executable from a Zero program. Specify the output path with '--out'. ```sh zero build --emit exe examples/hello.0 --out .zero/out/hello ``` -------------------------------- ### Check Function Calls and Ignored Return Values Source: https://github.com/vercel-labs/zerolang/blob/main/examples/README.md This command checks the 'functions.0' example, which demonstrates calling functions and ignoring their return values. ```sh bin/zero check examples/functions.0 ``` -------------------------------- ### Check Unsupported File System Target Source: https://github.com/vercel-labs/zerolang/blob/main/examples/error-tour/README.md Demonstrates a 'bad' command for checking a file system target that is unsupported on the current host. Use 'bin/zero build' for a valid build command. ```shell bin/zero check --json --target linux-musl-x64 conformance/native/fail/std-fs-target-unsupported.0 ``` ```shell bin/zero build --target linux-musl-x64 examples/memory-package --out .zero/out/memory-package ``` -------------------------------- ### Example Diagnostic JSON Output Source: https://github.com/vercel-labs/zerolang/blob/main/README.md This JSON structure represents a diagnostic, including its code, message, expected and actual values, and repair suggestions. ```json { "code": "NAM003", "message": "unknown identifier 'message'", "expected": "visible local, parameter, function, or builtin", "actual": "no matching visible symbol", "repair": { "id": "declare-missing-symbol" } } ``` -------------------------------- ### Build Tiny Profile Artifacts Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/examples.md Shows how to build a release-tiny artifact for a Zero program and check its size. Useful for creating minimal executables. ```sh bin/zero build --release tiny --target linux-musl-x64 examples/hello.0 --out .zero/out/hello-tiny bin/zero size --json --release tiny --target linux-musl-x64 --out .zero/out/hello-tiny examples/hello.0 ``` -------------------------------- ### Explain Diagnostic and Fix Issues Source: https://github.com/vercel-labs/zerolang/blob/main/skill-data/agent.md Explain a compiler diagnostic code and get a JSON output for checking or fixing issues in a file or package. ```sh zero explain zero check --json zero fix --plan --json ``` -------------------------------- ### Manage Skills with Specific Binary Path Source: https://github.com/vercel-labs/zerolang/blob/main/skills/zero/SKILL.md Demonstrates how to use a specific Zero binary path to manage skills, ensuring consistency with the project's compiler version. ```sh /path/to/zero skills list /path/to/zero skills get zero --full ``` -------------------------------- ### Prepare Release Branch Source: https://github.com/vercel-labs/zerolang/blob/main/AGENTS.md Build the native compiler locally as a prerequisite for release preparation. ```sh make -C native/zero-c ``` -------------------------------- ### Using Field Defaults in Types Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/learn-zero.md Illustrates how to define a `type` with default values for fields, allowing for partial initialization. ```zero type Counter { value: i32 = 0, } let counter: Counter = Counter {} ``` -------------------------------- ### Checking Target Facts Source: https://github.com/vercel-labs/zerolang/blob/main/skill-data/stdlib.md Demonstrates how to query target information using the `zero` command-line tool. This is useful for cross-compilation and understanding build environments. ```sh zero targets zero check --target linux-musl-x64 zero graph --target linux-musl-x64 ``` -------------------------------- ### Explain Diagnostic Code Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/target-capabilities.md Use 'zero explain' to get human-readable explanations for diagnostic codes. This command provides a detailed breakdown of a specific diagnostic. ```sh zero explain TAR002 ``` -------------------------------- ### BufferView Structure and Length Calculation Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/primitives.md Defines a `BufferView` struct containing a byte span and an optional owner, and a function to get the length of the byte span. ```zero type BufferView { bytes: Span, owner: Maybe>, } pub fn len(view: BufferView) -> usize { return std.mem.len(view.bytes) } ``` -------------------------------- ### Generate Documentation Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/cli-reference.md Emits public API documentation facts for a Zero program. ```sh zero doc ``` -------------------------------- ### Local Path Dependencies in Zero Source: https://github.com/vercel-labs/zerolang/blob/main/skill-data/packages.md Example of defining a local dependency in a Zero package manifest. The path must point to a directory containing a `zero.json` file. ```json { "dependencies": { "local-tools": { "path": "../local-tools", "version": "0.1.0" } } } ``` -------------------------------- ### std.net.listen Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/modules/net.md Returns a bootstrap listener handle if available. ```APIDOC ## std.net.listen ### Description Returns a bootstrap listener handle when available. ### Parameters #### Path Parameters - **net** (Net) - Required - The network capability. - **address** (Address) - Required - The address to listen on. ### Returns - `Maybe`: A `Maybe` containing a listener handle if successful, otherwise `Nothing`. ``` -------------------------------- ### Common Zerolang Commands Source: https://github.com/vercel-labs/zerolang/blob/main/README.md A collection of frequently used Zerolang commands for checking, running, building, inspecting graph and size, getting skills, and diagnosing issues. ```bash zero check examples/hello.0 ``` ```bash zero run examples/add.0 ``` ```bash zero build --emit exe --target linux-musl-x64 examples/add.0 --out .zero/out/add ``` ```bash zero graph --json examples/systems-package ``` ```bash zero size --json examples/point.0 ``` ```bash zero skills get zero --full ``` ```bash zero doctor --json ``` -------------------------------- ### Build with C Libraries and Vendored Headers Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/c-interop.md Builds a Zero project for a specific target, ensuring correct handling of C libraries and vendored headers. This command is crucial for cross-compilation and avoiding host path contamination. ```sh bin/zero build --json --target linux-musl-x64 conformance/c/host-leak-package --out .zero/out/host-leak-package ``` -------------------------------- ### Build Zero Object File Source: https://github.com/vercel-labs/zerolang/blob/main/skill-data/builds.md Use 'zero build --emit obj' to compile a Zero program into an object file. Specify the output path with '--out'. ```sh zero build --emit obj examples/hello.0 --out .zero/out/hello.o ``` -------------------------------- ### Ship Zero Program Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/cli-reference.md Produces a release preview with checksums and metadata for a Zero program. Use `--json` for structured output and specify target with `--target`. ```sh zero ship --json --target linux-musl-x64 examples/hello.0 --out .zero/ship/hello ``` -------------------------------- ### Run Benchmarks with Sandbox Backend Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/benchmarks.md Explicitly run the benchmark suite using the sandbox backend for an isolated environment, useful for CI. ```sh ZERO_BENCH_MODE=sandbox pnpm run bench ``` -------------------------------- ### Run Documentation Tests Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/building-from-source.md Executes the documentation tests for the project. ```sh pnpm run docs:test ``` -------------------------------- ### Check Direct Backend Packed Error-Result Propagation Source: https://github.com/vercel-labs/zerolang/blob/main/examples/README.md This command checks the 'direct-raises-basic.0' example, which shows direct backend packed error-result propagation for 'raise' and 'check' operations. ```sh bin/zero check examples/direct-raises-basic.0 ``` -------------------------------- ### Importing Modules Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/language-reference.md Shows the syntax for importing modules into the current scope. ```zero use std.codec ``` ```zero use std.parse ``` -------------------------------- ### Check Direct Backend Readonly String Slices Source: https://github.com/vercel-labs/zerolang/blob/main/examples/README.md This command checks the 'direct-span-read.0' example, which illustrates direct backend readonly string slices used as byte-span views. ```sh bin/zero check examples/direct-span-read.0 ``` -------------------------------- ### Build with 'small' profile Source: https://github.com/vercel-labs/zerolang/blob/main/docs/articles/optimization.md Builds a project using the 'small' optimization profile, targeting linux-musl-x64, and outputs to a specified directory. Includes JSON output for detailed build information. ```sh bin/zero build --json --profile small --target linux-musl-x64 examples/hello.0 --out .zero/out/hello-small ``` -------------------------------- ### Run Zerolang Repair Demo Source: https://github.com/vercel-labs/zerolang/blob/main/README.md Execute the agent repair demo script to see the full cycle of checking, explaining, planning, and rerunning repairs on a broken fixture. ```bash pnpm run agent:demo ```