Skip to content

Conversation

@ochsec
Copy link
Owner

@ochsec ochsec commented Nov 10, 2025

No description provided.

claude and others added 4 commits November 10, 2025 02:38
Implemented a transpiler following the REVISED_STRATEGY.md approach:
- Converts W language code to idiomatic Rust source code
- Leverages Rust's compilation process for safety guarantees
- Maps W types directly to Rust stdlib types

Key Features:
- Function definitions with type annotations (Square[x: int] := x * x)
- Function calls with nested composition
- List support (List → Vec)
- Map support (Map → HashMap)
- Binary operations (arithmetic, comparison)
- Proper type inference and return type generation
- PascalCase → snake_case naming conversion
- Debug formatting for complex types

Implementation Details:
- Added peek_token() to lexer for lookahead parsing
- Fixed := token recognition in lexer
- Unified function call/definition parser with disambiguation
- Proper expression vs statement generation
- Automatic main() wrapper for standalone expressions

Examples:
- hello_world.w: Basic Print functionality
- list_example.w: Vec generation and debug printing
- arithmetic.w: Binary operations
- multiple_args.w: Multiple function arguments
- function_def.w: Function definition transpilation

See TRANSPILER_DEMO.md for complete documentation and examples.
Implements full set of Rust primitive types following Rust's defaults:
- Integer literals now default to i32 (not i64) like Rust
- Float literals default to f64 like Rust
- Support for all Rust integer types (i8, i16, i32, i64, i128, isize)
- Support for all Rust unsigned types (u8, u16, u32, u64, u128, usize)
- Support for both f32 and f64 floats
- Backward compatible type names (int→i32, float→f64)

Changes:
- Updated AST Type enum with 20+ primitive types
- Enhanced parser to recognize all type keywords (Int8, UInt32, etc.)
- Fixed lexer to parse identifiers with digits (UInt8, Int64, etc.)
- Updated code generator to map all types correctly
- Changed Expression::Number from i64 to i32
- Updated Token::Number from i64 to i32
- Enhanced documentation with complete type mapping table

Examples added:
- types_demo.w: UInt8 parameters
- types_i64.w: Int64 usage
- types_float32.w: Float32 usage
- comprehensive_types.w: Working demonstration

This aligns the transpiler with Rust's type system conventions
and gives users fine-grained control over integer sizes.
Implements all fundamental Rust container types with generic syntax:
- Array[T, N] → [T; N] (fixed-size arrays)
- Slice[T] → &[T] (slice references)
- HashSet[T] → HashSet<T>
- BTreeMap[K, V] → BTreeMap<K, V> (sorted maps)
- BTreeSet[T] → BTreeSet<T> (sorted sets)

Previously only List[T] and Map[K,V] were supported.

Implementation Details:
- Extended AST Type enum with 5 new container variants
- Enhanced parser with parse_generic_type() for generic syntax
- Added expect_token() helper for cleaner parsing
- Parser now handles type parameters in brackets
- Array type includes size parameter (usize)
- Updated code generator to map all container types to Rust

Type Syntax Examples:
- List[Int32] → Vec<i32>
- Array[UInt8, 256] → [u8; 256]
- Slice[UInt8] → &[u8]
- HashSet[String] → HashSet<String>
- BTreeMap[Int32, String] → BTreeMap<i32, String>
- BTreeSet[Int64] → BTreeSet<i64>

All type mappings verified with test examples.
Documentation updated with complete container type table.

Files Modified:
- src/ast.rs: Added 5 new Type variants
- src/parser.rs: Added generic type parsing logic
- src/rust_codegen.rs: Added type mappings for all containers
- TRANSPILER_DEMO.md: Updated with container type documentation

Test Files Added:
- examples/containers_*.w: Individual container type tests
- examples/all_containers.w: Comprehensive demonstration
@ochsec ochsec merged commit 33541dd into main Nov 10, 2025
1 check passed
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.

3 participants