Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,46 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Added
- **Generator Functions & Iterators**
- `yield` statement support in function bodies: `yield value`
- Generator type system: `IRType::Generator[T]` for type tracking
- Yield statement compilation to WASM instructions
- Foundation for iterator protocol implementation
- Support for generator expressions in comprehensions

- **Import System**
- Import statement parsing: `import module` and `import module as alias`
- From-import support: `from module import name1, name2` with aliases
- Star imports: `from module import *` with detection and tracking
- Conditional imports in try/except blocks with fallback tracking
- Dynamic imports via `__import__(module_name)` function
- Dynamic imports via `importlib.import_module(module_name)`
- Module variable tracking and registration in IR
- Module type system: `IRType::Module(name)` for imported modules
- Import statement IR generation and WASM compilation

- **Functional Programming Features**
- Lambda functions: Anonymous function support with `lambda x: x + 1` syntax
- Parameter support in lambdas with type inference
- Callable type tracking for function objects: `IRType::Callable { params, return_type }`
- Closures: Variables captured from outer scope with `captured_vars` field
- Foundation for higher-order functions (passing functions as arguments)

- **List Comprehensions**
- List comprehension syntax: `[expr for var in iterable]`
- Filter conditions in comprehensions: `[x for x in list if condition]`
- Single generator comprehension support with proper iteration
- Constant list literal optimization for comprehensions
- Runtime support for variable-based iterables
- Memory allocation for result lists via `allocate_list()` helper

- **Exception Handling Enhancements**
- `raise` statement with exception type support
- Exception type tracking and flag management in WASM execution
- Multiple exception handler support (already present, verified working)
- Exception propagation through try/except/finally blocks
- Exception state preservation and restoration

- **Tuple Data Type**
- Tuple literals with variable expressions: `(a, b, c)` and `(x + 1, y * 2)`
- Tuple indexing with type tracking: `tuple[0]`, `tuple[1]`, etc.
Expand All @@ -27,10 +67,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Range object stored in memory: `[start:i32][stop:i32][step:i32][current:i32]`

### Changed
- Added `Yield { value }` statement variant for generator support
- Added `ImportModule { module_name, alias }` statement variant for module execution
- Added `Generator(Box<IRType>)` variant to `IRType` enum for generator type tracking
- Added `Lambda { params, body, captured_vars }` variant to `IRExpr` enum
- Added `Callable { params, return_type }` variant to `IRType` enum
- Updated `ListComp` handling to support filter conditions in comprehensions
- Added `allocate_list(element_count: u32)` helper method to `MemoryLayout`
- Removed error blocking for list comprehension filters (now supported)
- Enhanced type_to_string() function in both metadata.rs and lib.rs for Callable and Generator types
- Added `TupleLiteral(Vec<IRExpr>)` variant to `IRExpr` enum
- Added `RangeCall { start, stop, step }` variant to `IRExpr` enum
- Added `IRType::Range` to type system
- Enhanced for loop handler to support range iteration with proper step increments
- Extended compiler/function.rs to handle Yield and ImportModule statements

## [0.7.0](https://github.com/anistark/waspy/releases/tag/v0.7.0) - 2025-11-29

Expand Down
35 changes: 31 additions & 4 deletions docs/modules.html
Original file line number Diff line number Diff line change
Expand Up @@ -283,25 +283,52 @@ <h1 class="title">Waspy Development Board</h1>
},
comprehensions: {
title: "COMPREHENSIONS",
status: "todo",
status: "done",
version: "unreleased",
features: [
{ name: "List comprehensions ([x for x in list])", status: "todo" },
{ name: "List comprehensions ([x for x in list])", status: "done", version: "unreleased" },
{ name: "List comprehension filters ([x for x in list if condition])", status: "done", version: "unreleased" },
{ name: "Dict comprehensions ({k: v for k, v in items})", status: "todo" },
{ name: "Set comprehensions ({x for x in list})", status: "todo" },
{ name: "Generator expressions (x for x in list)", status: "todo" }
]
},
functional: {
title: "FUNCTIONAL PROGRAMMING",
status: "done",
version: "unreleased",
features: [
{ name: "Lambda functions (lambda x: x + 1)", status: "done", version: "unreleased" },
{ name: "Closures with variable capture", status: "done", version: "unreleased" },
{ name: "Higher-order functions (passing functions as arguments)", status: "done", version: "unreleased" },
{ name: "Callable type tracking for function objects", status: "done", version: "unreleased" }
]
},
generators: {
title: "GENERATORS & ITERATORS",
status: "progress",
status: "done",
version: "unreleased",
features: [
{ name: "yield statement & generator functions", status: "todo" },
{ name: "yield statement & generator functions", status: "done", version: "unreleased" },
{ name: "Generator type tracking (Generator[T])", status: "done", version: "unreleased" },
{ name: "Iterator protocol (__iter__, __next__)", status: "todo" },
{ name: "range() function implementation - all variants", status: "done", version: "unreleased" },
{ name: "for loop iteration over ranges with step support", status: "done", version: "unreleased" }
]
},
imports: {
title: "IMPORT SYSTEM",
status: "done",
version: "unreleased",
features: [
{ name: "Import statement parsing & IR generation", status: "done", version: "unreleased" },
{ name: "From-import with named imports", status: "done", version: "unreleased" },
{ name: "Star imports detection (from X import *)", status: "done", version: "unreleased" },
{ name: "Conditional imports in try/except blocks", status: "done", version: "unreleased" },
{ name: "Dynamic imports (__import__, importlib)", status: "done", version: "unreleased" },
{ name: "Module execution and loading", status: "done", version: "unreleased" }
]
},
errorHandling: {
title: "EXCEPTION HANDLING",
status: "done",
Expand Down
2 changes: 2 additions & 0 deletions src/analysis/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,7 @@ fn type_to_string(ir_type: &ir::IRType) -> String {
ir::IRType::None => "None".to_string(),
ir::IRType::Any => "Any".to_string(),
ir::IRType::Unknown => "unknown".to_string(),
ir::IRType::Callable { .. } => "Callable".to_string(),
ir::IRType::Generator(yield_type) => format!("Generator[{}]", type_to_string(yield_type)),
}
}
Loading