Support global variables and constants in kitc#11
Merged
walker84837 merged 2 commits intomainfrom Jan 28, 2026
Merged
Conversation
Add parsing, type inference, and codegen for global variables and constants. This allows users to declare globals at module scope, including typed and inferred variables, with optional initializers. Summary of changes: - Introduce GlobalDecl in AST to represent globals - Extend parser to handle `var` and `const` at module level - Update TypeInferencer to infer global variable types - Update SymbolTable to track global variables - Modify codegen to emit global variable declarations in C - Add `examples/globals_*` and corresponding expected outputs - Add tests in `kitc/tests/examples.rs` for global examples
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.
This PR adds full support for global variables and constants in Kit. Users can now declare module-level
varandconstwith optional type annotations and initializers.The AST, parser, type inference, and symbol table have been updated to handle globals, and code generation now emits proper C declarations for them.
To validate this feature, comprehensive examples and tests have been added. These changes make the language more expressive, allowing shared state across functions and aligning Kit with standard programming practices for global variables.