Skip to content

Conversation

@walker84837
Copy link
Collaborator

This PR adds full support for global variables and constants in Kit. Users can now declare module-level var and const with 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.

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
@walker84837 walker84837 marked this pull request as ready for review January 22, 2026 02:54
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