Phase 10 C3.7 terminal IO builtins#34
Open
efvincent wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
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
builtinEnvwithprint : String -> StringandreadLn : String, and threads it through REPL / CLI--emit-c/ golden typing. - Extends CGen + embedded C prelude with lowering for
print/readLnand optional generatedint main(void)wrapper callinglithic_main(). - Adds focused unit/integration tests for
--emit-cand 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 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 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. |
| | 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. | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR lands the Phase 10 C3.7 first-pass terminal IO builtin slice.
print : String -> StringandreadLn : String.--emit-c, and golden test typing paths.lithic_builtin_printandlithic_builtin_readln.printandreadLnthrough the runtime helper ABI.main(void)wrapper when a zero-argument Lithicmaindeclaration is present.0.9.19.0and update README/spec/CGen docs/changelog.Validation
cabal test lithic-testgreen locally, reported by Eric.