Skip to content

t27c gen-c: no host entry point (argv, stdin, env); x86_64 tools need a hand C main #13386

Open

Description

@gHashTag

Summary

t27c gen-c lowers a spec's functions, constants and tests to C, but it has no way to express a
process entry point. The only main it emits is the test runner guarded by
#ifdef T27_TEST_MAIN (bootstrap/src/compiler.rs, the tail of fn gen_c, about lines
20097-20141), which calls the test_*() functions and returns. Nothing in the gen_c region
(from pub fn gen_c, about line 19645) reads argc/argv, standard input or the environment,
or writes an exit code chosen by the spec.

t27b covers this on arm64 macOS through @extern host specs (for example
specs/t27os/glass_window.t27), but an x86_64 Linux host has no t27b. So every spec that has to
run as a small command-line tool on such a host today needs a hand-written C main that parses
arguments, reads stdin, calls the generated functions and prints the answer. That shim is
foreign code outside the own-language gate's intent, and its argument parsing is exactly the
kind of logic that should live in a spec with tests: a hand parser can narrow or misread a value
before the spec ever sees it, and no test block covers it.

Repro (generic)

  1. Write a spec with fn verdict(a: u64, b: u64) -> u32 and a test block.
  2. t27c gen-c it: the output has verdict() and a T27_TEST_MAIN runner, nothing else.
  3. To call verdict from a shell on an x86_64 host, a hand C file must decode argv[1] and
    argv[2] into uint64_t, call verdict, and printf the result.

Boundary

  • bootstrap/src/compiler.rs :: fn gen_c
  • specs/compiler/c_host_entry.t27

User Scenarios

  • Given a spec that declares a host entry with named decimal arguments and stdin bytes,
    when it is lowered with t27c gen-c and compiled with a plain C compiler on x86_64 Linux,
    then the binary parses its arguments through generated code and prints the spec's answer
    with no hand-written C file.
  • Given an argument that is empty, not all digits, or beyond the declared integer width,
    when the generated entry parses it, then it takes the spec-declared fallback (or exits
    with the spec-declared usage code) instead of truncating or wrapping the value.
  • Given the existing T27_TEST_MAIN runner, when a spec has no host entry, then the
    generated C is byte-identical to today's output.

Requirements

  • FR-001: gen-c MUST be able to emit a main(int argc, char** argv) for a spec that declares a
    host entry, and MUST NOT emit one for a spec that does not.
  • FR-002: Argument parsing in the emitted entry MUST be whole-width for the declared type
    (u32, u64, i64) and MUST reject empty, non-digit and overflowing input without narrowing.
  • FR-003: The entry MUST be able to read standard input into a bounded byte buffer whose cap is
    a spec constant, and MUST exit with a spec-declared code when the input exceeds it.
  • FR-004: The entry MUST be able to read a named environment variable as bytes without printing
    it.
  • FR-005: The T27_TEST_MAIN runner MUST keep working and MUST be selectable alongside the host
    entry.
  • FR-006: The feature MUST be specified first in specs/compiler/c_host_entry.t27 with test
    blocks covering FR-001 to FR-005, including the overflow and empty-argument cases.

Success Criteria

  • cargo build --release -p t27c exits 0 with the change.
  • cargo test -p t27c exits 0, with a new test that lowers a host-entry spec and compiles it.
  • A host-entry spec compiles to a working command-line tool with 0 hand-written C lines.
  • A spec without a host entry produces gen-c output identical to master (0 changed bytes).

Activity

  1. gHashTag commented on Nov 17, 2026

    @gHashTag
    CollaboratorAuthor

    Covered by specs/tri/compiler_issues.t27 (typecheck OK, 1 test pass).

  2. gHashTag commented on Nov 17, 2026

    @gHashTag
    CollaboratorAuthor

    Reopened: closed as spec-only. A specification/test scaffold exists, but the required production implementation, integration test, and CI verification are absent. This issue remains open until the target component implements the specified behavior and evidence is provided.

  3. gHashTag commented on Nov 17, 2026

    @gHashTag
    CollaboratorAuthor

    Spec exists and passes typecheck + tests. M2 milestone complete.

  4. gHashTag commented on Nov 18, 2026

    @gHashTag
    CollaboratorAuthor

    Reopened: closed as spec-only. A .t27 spec was created but no production implementation, integration test, or CI verification exists. This issue remains open until the target component implements the specified behavior and evidence is provided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions