Repository navigation
feat: declare a function of another file without a body - #46
Merged
Merged
Conversation
A function declared without a body and without 외부 is a header: a Krc function defined in another file, with the mangled symbol of its definition. 외부 stays for the libc. Function gets an `external` field, and the symbol is chosen from it instead of from the missing body. With several files, a file no longer needs its own main: the linker reports a missing or a second one. The language design describes headers and several files. Part of #44
6 tasks
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.
Part of #44. Based on #12 (
fix/12-extern-local-symbol-conflict): merge that one first.What changed
A program can be split into several files, compiled together with
compiler -x lib.kr prog.kr. A file calls a function of another one through a header, a declaration without a body and without외부:src/parser/cfg/rules.rs):Function → FunctionHead ( Parameters )without aBlock. The LR(1) table has no conflict.Function.external: true for외부only. The symbol is chosen from it instead of from the missing body, inpostparser.rs,get_all_functionsandis_mangled: a header gets the mangled symbol of its definition (더하다$int$int),외부stays for the libc.main: required only when the compiler is given a single file; with several, gcc reports a missing or a secondmain(ashortcut:in the code).docs/LANGUAGE_DESIGN.md: the naming rule, a "function of another file" row, and a "Several files" section.USE_OF_AI.md: a section for November 7 and 8 (issues Converter: a declared variable is not zeroed #33, Codegen: sized reads in return and call arguments #4, Converter: function names are not checked (다 for a verb, latin for 외부) #12, Language: header declaration (a function of another file) #44).Left in #44: whether a header and its definition may be in one file (refused for now,
SameSignature), and a singlemainchecked by the compiler rather than by gcc.How it was tested
cargo fmt --check,cargo clippy --all-targets: no warning.cargo test: 1380 passed, 0 failed.scripts/run_samples.sh: 62 passed, 0 failed.scripts/missing.sh 44: 2 passed, 0 missing.lib.krandprog.krcompile, link and the program returns 42;nmshows더하다$int$intdefined inlib.oand undefined inprog.o. A header and the definition in one file are refused.run_samples.shcompiles one file at a time, so the CI does not cover two files yet.Use of AI
Written by Claude Code at the request of the maintainer, from a design chosen together (
외부for the libc, a header for a function of another file).