diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f6e413..70792b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,16 @@ # TeapotLang Changelog -Every commit in the `Sim20004/teapot-lang` repository is represented below, from the initial repository creation through the latest commit. Descriptions summarise the changes made by each commit. PLEASE add changes to the top and not the bottom, look at the dates to ensure you've done it correctly. +This changelog records notable changes to TeapotLang. Entries are listed newest first; merge commits and routine maintenance may be grouped with the changes they contain. # Unreleased +* 2026-11-27: Audited and updated the project documentation to reflect the current compiler, semantic analyser, CLI, and development roadmap. +* 2026-11-17: Applied Ruff cleanup and updated the pull-request template. +* 2026-11-17: Added property-based tests for simple numeric literals. +* 2026-11-14: Added property-based tests for balanced parentheses, numeric literals, and simple identifier names. +* 2026-11-09: Added parser tests for the `true` and `false` Boolean literals. +* 2026-11-07: Added branch-coverage tests and pinned the Ruff version used by CI. +* 2026-11-05: Adjusted type flexibility and expression-inference behaviour. * 2026-11-08: Added parser tests for the `true` and `false` boolean literals, covering standalone assignments, variable declarations and binary expressions. * 2026-11-07: Added tests to fill coverage gaps * 2026-11-04: Fixed format, fixed various failing tests due to: addition of parameter in various functions, deprecation and removal of bounds checking code for future rewrite, and change of other code, and then fixed formatting again in three commits. diff --git a/README.md b/README.md index 5190477..c3dc8fc 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ Semantic analysis Future stages ``` -The current implementation includes the lexer, parser, abstract syntax tree (AST), and semantic-analysis infrastructure. The pipeline is being extended towards the language specification. +The current implementation includes the lexer, parser, AST, symbol-table construction, and an initial second semantic pass. The type checker validates supported variable declarations and initialisers, literal types and bounds, selected binary expressions, identifier references in inferred expressions, and return expressions in functions and operators. This is a partial implementation, not complete static analysis. The following distinctions matter: @@ -124,7 +124,7 @@ A keyword being recognised, or an AST node existing, does not necessarily mean t ### What is not implemented yet? -Code generation and a complete executable runtime remain future work. TeapotLang therefore cannot yet compile a program into a finished executable through a complete end-to-end pipeline. +Assignment value checking, function-call argument validation, complete mutability and conversion rules, member resolution, full operator-overload resolution, code generation, and a complete executable runtime remain future work. TeapotLang therefore cannot yet compile a program into a finished executable through a complete end-to-end pipeline. The language specification may describe capabilities beyond those currently supported. Check the [language reference](docs/language-reference.md) before relying on a particular feature. diff --git a/ROADMAP.md b/ROADMAP.md index cba17be..62ac3ab 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -1,178 +1,96 @@ -TeapotLang Roadmap - -TeapotLang is currently in Alpha. - -This roadmap describes the planned direction of the language and may change as development progresses. - -Current Status - -TeapotLang is currently focused on building the core language infrastructure and compiler pipeline. - -Alpha - -* [x] Lexer -* [x] Parser -* [x] AST infrastructure -* [x] Struct declarations -* [x] Enum declarations -* [x] Function declarations -* [x] Operator overloading infrastructure -* [x] Symbol table -* [x] First-pass semantic analysis -* [ ] Complete semantic analysis -* [ ] Complete type checking -* [ ] Improve compiler diagnostics -* [ ] Stabilise the language specification - -⸻ - -Phase 1: Language Foundations - -The first priority is making the core language well-defined and reliable. - -* [ ] Complete semantic analysis -* [ ] Complete type checking -* [ ] Finalise variable and declaration rules -* [ ] Finalise function and parameter rules -* [ ] Finalise struct semantics -* [ ] Finalise enum semantics -* [ ] Finalise operator overloading rules -* [ ] Improve scope and symbol resolution -* [ ] Define compile-time error behaviour -* [ ] Expand the language specification -* [ ] Document all core language features - -⸻ - -Phase 2: Compiler Infrastructure - -Build the infrastructure required to turn valid TeapotLang programs into executable code. - -* [ ] Design intermediate representation -* [ ] Implement IR generation -* [ ] Implement backend architecture -* [ ] Add target architecture support -* [ ] Implement code generation -* [ ] Implement linking/runtime integration -* [ ] Add compiler optimisation infrastructure -* [ ] Improve compiler error messages -* [ ] Add source-location tracking throughout compilation - -⸻ - -Phase 3: Memory Management - -TeapotLang supports different memory-management models through compiler directives. - -* [ ] Finalise memory-management semantics -* [ ] Implement automatic memory management -* [ ] Implement manual memory management -* [ ] Define ownership/lifetime behaviour where applicable -* [ ] Improve memory-related diagnostics -* [ ] Document memory-management behaviour - -⸻ - -Phase 4: Standard Library - -Build a useful standard library around the language. - -* [ ] Core utilities -* [ ] Strings -* [ ] Collections -* [ ] File I/O -* [ ] Environment/process APIs -* [ ] Error handling utilities -* [ ] Standard library documentation -* [ ] Stable standard-library API - -⸻ - -Phase 5: Developer Experience - -Make TeapotLang pleasant to use outside the compiler itself. - -* [ ] Improve compiler diagnostics -* [ ] Add a formatter -* [ ] Add language-server support -* [ ] Add editor integrations -* [ ] Improve CLI tooling -* [ ] Add project/package management -* [ ] Improve documentation -* [ ] Add tutorials and examples -* [ ] Create a comprehensive language reference - -⸻ - -Phase 6: Ecosystem - -Move from a language implementation to an ecosystem. - -* [ ] Package registry -* [ ] Package publishing tooling -* [ ] Dependency management -* [ ] Third-party libraries -* [ ] Community examples -* [ ] Community tooling -* [ ] Plugin/extension system where appropriate - -⸻ - -Stability - -Before reaching a stable release, TeapotLang should have: - -* [ ] A stable language specification -* [ ] Stable compiler behaviour -* [ ] Stable standard library APIs -* [ ] Predictable error reporting -* [ ] Cross-platform support -* [ ] Reproducible builds -* [ ] Comprehensive documentation -* [ ] Migration guidance between releases -* [ ] Versioning policy -* [ ] Backwards-compatibility policy - -⸻ - -Release Targets - -Alpha - -Goal: Rapid language and compiler development. - -Focus: - -* Core language features -* Parser and AST -* Semantic analysis -* Type checking -* Compiler architecture - -Breaking changes are expected. - -Beta - -Goal: Feature-complete language suitable for wider testing. - -Focus: - -* Stable language semantics -* Compiler reliability -* Standard library -* Developer tooling -* Documentation -* Cross-platform support - -Breaking changes should become increasingly rare. - -1.0 - -Goal: A stable TeapotLang release suitable for production use. - -Requirements: - -* Stable specification -* Stable compiler -* Stable standard library -* Documented compatibil +# TeapotLang roadmap + +TeapotLang is in alpha. This roadmap describes the intended direction of the project, not a promise of release dates. Items marked complete refer only to the scope stated in that item; they do not imply that the whole language feature is finished. + +## Current status + +The lexer, parser, AST, CLI, and initial semantic-analysis infrastructure are implemented. Semantic analysis currently has a declaration-and-scope pass followed by a partial type-checking pass. The compiler does not yet generate executable code or provide a language runtime. + +### Alpha foundations + +- [x] Lexer and token definitions +- [x] Parser and AST infrastructure +- [x] Core declaration syntax for variables, functions, structs, enums, errors, and operators +- [x] Initial symbol table and parent/child scope lookup +- [x] Declaration registration and duplicate-name detection +- [x] Initial semantic type checks for supported declarations, literals, expressions, and callable returns +- [ ] Complete semantic analysis and type checking +- [ ] Assignment value and mutability validation +- [ ] Function-call argument validation +- [ ] Condition and control-flow validation +- [ ] Complete member, cast, and operator-overload resolution +- [ ] Finalise core language semantics and specification + +## Phase 1: Language foundations + +Make the core language rules reliable and unambiguous. + +- [ ] Define and implement assignment compatibility and mutability rules +- [ ] Validate function-call argument counts and types +- [ ] Validate conditions and control-flow requirements +- [ ] Complete type conversions and cast validation +- [ ] Resolve struct fields and enum members +- [ ] Define and implement operator-overload resolution +- [ ] Complete return-path and callable validation +- [ ] Finalise variable, function, struct, enum, and error semantics +- [ ] Improve semantic diagnostics and source locations +- [ ] Keep the language reference aligned with implemented behaviour + +## Phase 2: Compiler infrastructure + +Build the stages needed to produce executable programs. + +- [ ] Design an intermediate representation +- [ ] Implement IR generation and lowering +- [ ] Design a backend interface +- [ ] Select and support an initial target architecture +- [ ] Implement code generation +- [ ] Integrate linking and runtime support +- [ ] Add compiler optimisation infrastructure + +## Phase 3: Memory management + +The source directives currently record a selected mode; they do not implement memory management. + +- [ ] Finalise memory-management semantics +- [ ] Define ownership, aliasing, and lifetime rules +- [ ] Implement automatic memory management +- [ ] Implement manual memory management +- [ ] Add memory-related diagnostics and tests + +## Phase 4: Runtime and standard library + +- [ ] Design and implement the runtime +- [ ] Add core utilities and input/output +- [ ] Add strings and collections +- [ ] Add filesystem and process APIs +- [ ] Add runtime error-handling facilities +- [ ] Document and stabilise standard-library APIs + +## Phase 5: Developer experience + +- [ ] Improve CLI diagnostics and tooling +- [ ] Add a formatter +- [ ] Add language-server support +- [ ] Add editor integrations +- [ ] Add project and package management +- [ ] Add tutorials and practical examples + +## Phase 6: Ecosystem + +- [ ] Design package publishing and dependency management +- [ ] Establish a package registry +- [ ] Encourage third-party libraries and community examples +- [ ] Consider a plugin or extension system where it is useful + +## Before a stable 1.0 release + +- [ ] Stable language specification and compiler behaviour +- [ ] Usable runtime and standard library +- [ ] Predictable diagnostics +- [ ] Cross-platform support +- [ ] Reproducible builds and release process +- [ ] Migration guidance and compatibility policy +- [ ] Complete user and developer documentation + +Breaking language and compiler changes are expected during alpha. Priorities may change as implementation and language design develop. diff --git a/docs/README.md b/docs/README.md index 4410c53..abd8b37 100644 --- a/docs/README.md +++ b/docs/README.md @@ -66,11 +66,12 @@ The documentation uses several terms to avoid confusing language design with com | Term | Meaning | | --------------- | ----------------------------------------------------------------------------------------------------- | -| **Implemented** | The relevant compiler behaviour exists | -| **Parsed** | The parser constructs an AST representation | -| **Recognised** | The lexer recognises the syntax | -| **Represented** | A compiler data structure exists, but the feature may not be parser-supported | -| **Design** | The feature belongs to the intended language model but is not currently established by implementation | +| **Implemented** | The relevant behaviour exists in the compiler stage being described. This does not imply that later stages or runtime support are complete. | +| **Partial** | Some semantic or compiler behaviour exists, but important validation or execution rules remain unfinished. | +| **Parsed** | The parser constructs an AST representation, but later compiler stages may not support it. | +| **Recognised** | The lexer recognises the syntax, but the parser may not accept it. | +| **Represented** | A compiler data structure exists, but the feature may not be parser-supported. | +| **Design** | The feature belongs to the intended language model but is not implemented yet. | A keyword, token, or AST dataclass does **not** by itself mean that a feature is usable. diff --git a/docs/development.md b/docs/development.md index ddfef52..8b907d0 100644 --- a/docs/development.md +++ b/docs/development.md @@ -35,12 +35,21 @@ After installing the package: teapot examples/hello.tp ``` -The CLI accepts: +The CLI accepts an input `.tp` file and the following options: ```text - input (positional) Input TeapotLang source file. Required. --t, --trace Enable compiler diagnostic output. - --version Display the compiler version. +-t, --trace, --debug Enable compiler trace output. +-q, --quiet Suppress informational and trace output. +-v, --verbose Increase informational output (repeat for more detail). + --color {auto,always,never} + Control terminal colours. + --diagnostic-format {text,json} + Select human-readable or JSON diagnostics. + --diagnostic-detail {concise,normal,full} + Select diagnostic detail. + --log-file PATH Write trace and diagnostic output to a file. + --no-log Disable log-file output. + --version Display the compiler version. ``` For example: @@ -136,20 +145,17 @@ The AST is the interface between parsing and later compiler stages. When adding `src/teapot/semantic/pass1.py` performs the first stage of semantic analysis. -The current implementation includes: +The first pass in `src/teapot/semantic/pass1.py` currently provides: -* `Symbol`; -* `SymbolTable`; -* parent/child scope lookup; -* global scope construction; -* variable declaration registration; -* function declaration registration; -* function scopes; -* struct declaration registration; +* global, function, operator, struct, enum, error, and nested block scopes; +* symbol registration for variables, functions, parameters, structs and fields, enums and members, errors and members, and operators and arguments; +* parent-scope lookup and child-scope shadowing; * duplicate declaration detection; and -* function parameter metadata. +* checks that assignment targets name an existing identifier. -The analyser currently has a first-pass symbol-table phase and a second-pass type-checking phase. The second-pass `TypeChecker` is present but does not yet implement type-checking rules. +The second pass in `src/teapot/semantic/pass2.py` is an initial type checker, not an empty placeholder. It currently validates built-in variable datatypes, literal Python types and numeric bounds, supported variable initialisers, selected binary-expression combinations, identifier references used by supported expressions, and return-expression compatibility inside functions and operators. It also traverses the supported nested control-flow bodies. + +Important gaps remain: assignment right-hand-side compatibility, function-call argument count and types, complete mutability enforcement, condition typing, member and field resolution, complete cast rules, and proper overload resolution are not implemented. Unknown or unsupported expression forms may remain untyped rather than being rejected. Semantic failures raise `SemanticError`. @@ -292,7 +298,7 @@ Pass 2 The exact division between passes may evolve as implementation continues. -Current symbol-table behaviour should be tested independently from future type-checking behaviour. +Keep tests for symbol-table construction separate from tests for the current, deliberately partial type-checking rules. When adding a semantic rule, test both accepted and rejected programs, including nested scopes where relevant. ## Trace output diff --git a/docs/language-reference.md b/docs/language-reference.md index 4c860b4..94378d7 100644 --- a/docs/language-reference.md +++ b/docs/language-reference.md @@ -197,7 +197,7 @@ cui64 The parser records mutability information for the mutable and constant forms. -Semantic enforcement of mutability and complete type checking are still under development. +Mutability enforcement is not implemented. The second semantic pass performs partial type checking for supported declarations, initialisers, expressions, and callable return values; it is not a complete type checker. ## Arrays @@ -265,7 +265,7 @@ For example: count += 1. ``` -The semantic analyser does not yet perform complete type or mutability validation for assignments. +The first semantic pass rejects assignment to an undeclared identifier. The second pass does not yet check the assigned expression's type or enforce target mutability. ## Functions @@ -313,7 +313,7 @@ exit value. The expression must be followed by a period. -Complete return-type checking is not currently implemented. +The second semantic pass checks the inferred type of supported return expressions against the declared return type for functions and operators. Unsupported expressions may remain unchecked, and return-path analysis is not implemented. ## Visibility @@ -508,15 +508,15 @@ The semantic analyser does not yet enforce conversion rules. The parser uses the following precedence levels. Higher numbers bind more tightly: -| Level | Operators | | | -| ----: | -------------------- | - | - | -| 6 | `**` | | | -| 5 | `%`, `/`, `*` | | | -| 4 | `+`, `-` | | | -| 3 | `<`, `<=`, `>`, `>=` | | | -| 2 | `==`, `~=` | | | -| 1 | `&&` | | | -| 0 | ` | | ` | +| Level | Operators | +| ----: | --------- | +| 6 | `**` | +| 5 | `%`, `/`, `*` | +| 4 | `+`, `-` | +| 3 | `<`, `<=`, `>`, `>=` | +| 2 | `==`, `~=` | +| 1 | `&&` | +| 0 | `||` | Parentheses explicitly group expressions. @@ -526,7 +526,7 @@ The parser constructs an AST and does not evaluate expressions. ## Semantic analysis -Semantic analysis currently builds symbol tables. +Semantic analysis has two passes. The first builds symbol tables and scopes. The second performs an initial, partial set of type checks. The first pass registers declarations including: @@ -547,9 +547,9 @@ For example, declaring the same name twice in one scope is rejected. Shadowing in a child scope is supported by the current symbol-table implementation. -Assignments to undeclared identifiers and duplicate declarations in the same scope -are rejected. The second-pass type checker is present but does not yet implement -full name resolution or type checking. +Assignments to undeclared identifier targets and duplicate declarations in the same scope are rejected. The second pass validates built-in variable datatypes, literal types and bounds, supported initialisers, selected binary expressions, identifiers used by supported expressions, and callable return expressions. It traverses nested function/operator bodies and their supported control-flow blocks. + +This is not complete semantic analysis. Assignment value compatibility, function-call argument validation, condition typing, complete mutability and cast rules, member resolution, and full overload resolution remain unfinished. Expression forms that the type checker does not understand may be left unchecked. ## Diagnostics @@ -569,9 +569,9 @@ teapot examples/hello.tp --trace The following features are not currently complete: -* full type checking; -* identifier resolution; -* function-call validation; +* complete type checking; +* complete name resolution across all expression forms; +* function-call argument validation; * mutability enforcement; * complete reference semantics; * overload resolution; diff --git a/docs/language-specification.md b/docs/language-specification.md index 5120b07..249c998 100644 --- a/docs/language-specification.md +++ b/docs/language-specification.md @@ -227,7 +227,7 @@ The intended semantic rules include: * constant values must obey their immutability rules; and * references must satisfy reference rules. -Only declaration registration and duplicate-name detection are currently implemented. +The first semantic pass registers declarations and scopes and detects duplicate names. The second pass has begun type checking for supported built-in declarations, initialisers, expressions, and callable returns; complete type and mutability rules remain unfinished. ## 8. References @@ -386,9 +386,9 @@ Functions return values using `exit`: exit value. ``` -The intended language should verify that the returned expression is compatible with the function's declared return type. +The intended language should verify that every returned expression is compatible with the callable's declared return type and that required return paths are complete. -The current parser constructs return AST nodes, but complete return checking is not implemented. +The current second semantic pass checks supported return expressions in functions and operators. It does not perform return-path analysis, and unsupported expression forms may remain unchecked. ## 14. Visibility @@ -613,9 +613,9 @@ The intended responsibilities include: * entry-point validation; * and other language invariants. -The current implementation has begun this process with symbol-table construction. +The current implementation has two semantic passes. The first constructs symbol tables and scopes; the second performs an initial set of type checks. -The current first pass: +The first pass: ```text Program @@ -629,7 +629,7 @@ Program Duplicate declarations in the same scope currently produce `SemanticError`. -Full name resolution and type checking remain future work. +Name lookup is implemented for identifiers encountered by the supported expression-inference paths. Type inference and checking are partial: the checker validates supported declarations and initialisers, selected binary expressions, and callable return expressions. Assignment value compatibility, function-call argument validation, condition typing, full mutability rules, member resolution, complete cast semantics, and full operator-overload resolution remain future work. ## 25. Diagnostics @@ -687,9 +687,10 @@ The current repository can be summarised as follows: | Nested symbol lookup | Implemented | | Duplicate declaration detection | Implemented | | Function scopes | Implemented | -| Name resolution | In progress | -| Type checking | Not yet implemented | -| Mutability checking | Not yet implemented | +| Name resolution | Partial, for supported expression forms | +| Type inference | Partial | +| Type checking | Partial, for declarations, initialisers, binary expressions, and callable returns | +| Mutability checking | Not implemented | | Complete semantic validation | Not yet implemented | | Code generation | Not implemented | | Runtime | Not implemented |