Repository navigation
Description
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)
- Write a spec with
fn verdict(a: u64, b: u64) -> u32and atestblock. t27c gen-cit: the output hasverdict()and aT27_TEST_MAINrunner, nothing else.- To call
verdictfrom a shell on an x86_64 host, a hand C file must decodeargv[1]and
argv[2]intouint64_t, callverdict, andprintfthe 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 witht27c gen-cand 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_MAINrunner, 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_MAINrunner 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.t27withtest
blocks covering FR-001 to FR-005, including the overflow and empty-argument cases.
Success Criteria
cargo build --release -p t27cexits 0 with the change.cargo test -p t27cexits 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
gHashTag commentedon Nov 17, 2026
Covered by specs/tri/compiler_issues.t27 (typecheck OK, 1 test pass).
gHashTag commentedon Nov 17, 2026
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.
gHashTag commentedon Nov 17, 2026
Spec exists and passes typecheck + tests. M2 milestone complete.
gHashTag commentedon Nov 18, 2026
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.