Skip to content

Phase 10 C3.7 terminal IO builtins#34

Open
efvincent wants to merge 1 commit into
mainfrom
feat/phase10-c3-7-io-main-print-readln
Open

Phase 10 C3.7 terminal IO builtins#34
efvincent wants to merge 1 commit into
mainfrom
feat/phase10-c3-7-io-main-print-readln

Conversation

@efvincent
Copy link
Copy Markdown
Owner

Summary

This PR lands the Phase 10 C3.7 first-pass terminal IO builtin slice.

  • Add shared builtin typing environment entries for print : String -> String and readLn : String.
  • Thread the builtin environment through REPL, CLI --emit-c, and golden test typing paths.
  • Add C prelude helpers for lithic_builtin_print and lithic_builtin_readln.
  • Lower print and readLn through the runtime helper ABI.
  • Emit a C main(void) wrapper when a zero-argument Lithic main declaration is present.
  • Add focused CGen and CLI emit-c coverage for the new IO path.
  • Bump version to 0.9.19.0 and update README/spec/CGen docs/changelog.

Validation

  • cabal test lithic-test green locally, reported by Eric.
  • Editor diagnostics clean for touched source, test, and cabal files.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a first-pass “terminal IO builtins” slice to the typed pipelines and C backend, by introducing print / readLn into the shared type environment and lowering them to C prelude helpers, plus emitting a generated C main(void) wrapper when a zero-arg Lithic main declaration exists.

Changes:

  • Introduces builtinEnv with print : String -> String and readLn : String, and threads it through REPL / CLI --emit-c / golden typing.
  • Extends CGen + embedded C prelude with lowering for print/readLn and optional generated int main(void) wrapper calling lithic_main().
  • Adds focused unit/integration tests for --emit-c and CGen covering wrapper emission and builtin helper calls; bumps version + updates docs/changelog.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
test/Test/Golden.hs Switch golden typing pipeline to use the shared builtinEnv.
test/Test/CLIEmitC.hs Adds CLI --emit-c integration coverage for def main = print readLn and asserts wrapper/helper emission.
test/Test/CGen.hs Adds unit tests for C main wrapper emission and builtin lowering, with gcc compile checks.
src/Compiler/TypeChecker.hs Adds builtinEnv (and builtinSpan) for shared builtin typing entries.
src/Compiler/REPL.hs Starts REPL environment from builtinEnv instead of empty env.
src/Compiler/CGenPrelude.c Adds runtime helper implementations for lithic_builtin_print and lithic_builtin_readln.
src/Compiler/CGen.hs Adds optional generated C main(void) wrapper; lowers print/readLn through runtime helpers.
README.md Documents the new IO builtins and the main wrapper behavior for --emit-c and REPL.
lithic.cabal Bumps version to 0.9.19.0.
docs/phase10-c-codegen.md Updates Phase 10 C codegen progress notes to include C3.7 IO builtins direction/status.
docs/language-spec.md Updates living spec version/scope; documents builtin term environment entries.
CHANGELOG.md Adds 0.9.19.0 entry describing the builtin slice, tests, and validation notes.
app/Main.hs Threads builtinEnv through the CLI --emit-c typing path.

Comment thread src/Compiler/CGen.hs
Comment on lines 214 to +217
CVar _ varName ->
blk [c| return $varName; |]
case cgenBuiltinValue varName of
Just builtinExpr -> blk [c| return ($retTy)$builtinExpr; |]
Nothing -> blk [c| return $varName; |]
Comment on lines +395 to +399
while ((ch = fgetc(stdin)) != EOF) {
if (ch == '\n' || ch == '\r') {
break;
}

Comment thread docs/phase10-c-codegen.md
Comment on lines +3 to +6
Status: C2.2 call/case/variant/select lowering merged on main (PR #28) + C4.3 fixture-level emit/compile integration landed (2026-05-23) + C3.1 compile-time prelude template embedding and C3.2 first-pass prelude safety hardening landed + expanded C4.4 compile/link/run sanity gate (2026-05-24) + C3.3 helper-contract depth landed (2026-05-25) + C3.4 record-init failure propagation and CLI long-field fixture coverage landed (2026-05-25) + C3.5 case-expression and expression-value lowering depth landed (2026-05-26) + C3.6 arithmetic lowering landed (2026-05-27) + C3.7 first-pass terminal IO builtin lowering in progress (2026-05-27)
Branch: feat/phase10-c3-7-io-main-print-readln

Next prep checkpoint: `docs/phase10-c3-6-prep.md`.
Next prep checkpoint: C3.7 terminal IO builtin validation.
Comment thread docs/language-spec.md
| Name | Type | Implementation Status | Notes |
| --- | --- | --- | --- |
| `print` | `String -> String` | Implemented | First-pass terminal IO builtin. C lowering writes the string to stdout without appending a newline and returns the original string handle. |
| `readLn` | `String` | Implemented | First-pass terminal IO builtin. C lowering reads one line from stdin, stopping on carriage return or newline. |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants