Skip to content

Commit 5100319

Browse files
committed
Add array literals and X64 compilation proof of concept
- Add static and dynamic array declaration syntax - Implement array literal initialization [1, 2, 3, 4, 5] - Add array element access and assignment (arr[index]) - Implement Length() builtin function for arrays - Add X64 compilation proof of concept with in-memory execution - Generate working x64 machine code with runtime calls - Add 8 array operation tests (all passing) - Achieve 27/27 test suite success rate - Validate complex programs: factorial, prime detection, games - Establish dual execution paths: VM interpretation + X64 proof of concept
1 parent 958686e commit 5100319

10 files changed

+1605
-196
lines changed

ROADMAP.md

Lines changed: 273 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,273 @@
1+
# TinyPascal Development Roadmap
2+
3+
**🎯 Goal: Complete Modern Pascal Implementation (Excluding OOP)**
4+
5+
## ✅ Completed Features
6+
7+
### Core Infrastructure
8+
- [x] **UTF-8 Lexer** - Complete tokenizer with full Pascal syntax support
9+
- [x] **Recursive Descent Parser** - Full expression parsing with proper precedence
10+
- [x] **AST System** - Complete Abstract Syntax Tree with Visitor pattern
11+
- [x] **Type System** - Int64, UInt64, Float64, String, Boolean with conversions
12+
- [x] **Bytecode Engine** - Complete instruction set and bytecode generation
13+
- [x] **Virtual Machine** - Stack-based VM with full instruction execution
14+
- [x] **X64 Compilation** - Proof of concept native compilation with in-memory execution
15+
- [x] **Runtime System** - Built-in functions and native runtime support
16+
17+
### Language Features
18+
- [x] **Program Structure** - `program ProgramName; ... end.`
19+
- [x] **Variable Declarations** - `var x: Int; y: Float; s: String;`
20+
- [x] **Basic Types** - Int (Int64), UInt (UInt64), Float (Double), String (UTF-8), Boolean
21+
- [x] **Literals** - Integer, float, string, boolean literals
22+
- [x] **Arithmetic Operators** - `+`, `-`, `*`, `/` with proper precedence
23+
- [x] **Comparison Operators** - `=`, `<>`, `<`, `<=`, `>`, `>=`
24+
- [x] **Logical Operators** - `and`, `or`, `not`
25+
- [x] **Assignment** - `:=` operator
26+
- [x] **Expressions** - Complex nested expressions with parentheses
27+
- [x] **Control Flow** - `if/then/else`, `while/do`, `for/to/do`
28+
- [x] **Built-in Functions** - `PrintLn`, `Print`, `IntToStr`, `StrToInt`, `FloatToStr`, `StrToFloat`
29+
- [x] **Comments** - `//`, `{ }`, `(* *)` style comments
30+
31+
### Array Support (New!)
32+
- [x] **Static Arrays** - `array[1..10] of Int`
33+
- [x] **Dynamic Arrays** - `array of Int` (declaration and Length() working)
34+
- [x] **Array Literals** - `[1, 2, 3, 4, 5]`
35+
- [x] **Array Element Access** - `arr[index]` for reading elements
36+
- [x] **Array Element Assignment** - `arr[index] := value`
37+
- [x] **Length() Function** - Get array size with `Length(arr)`
38+
39+
### Development Tools
40+
- [x] **Comprehensive Test Suite** - 27+ test cases covering all features
41+
- [x] **Bytecode Disassembler** - Debug and inspect generated bytecode
42+
- [x] **Error Handling** - Parse errors with line/column information
43+
- [x] **Performance Tracking** - VM execution statistics
44+
45+
---
46+
47+
## 🚧 In Progress
48+
- [ ] **Current Session Focus** - *To be updated based on current work*
49+
50+
---
51+
52+
## 📋 Planned Features
53+
54+
### Phase 1: Data Types & Collections 🏗️
55+
56+
#### Arrays (Partial - Core Features Working)
57+
- [ ] **Multi-dimensional Arrays** - `array[1..5, 1..10] of Int`
58+
- [ ] **Array Operations** - Assignment (`arr1 := arr2`), comparison, slicing
59+
- [ ] **Dynamic Array Functions** - `SetLength`, `High`, `Low`
60+
61+
#### Records/Structures
62+
- [ ] **Record Types** - `type Person = record Name: String; Age: Int; end;`
63+
- [ ] **Record Variables** - Declaration and field access
64+
- [ ] **Nested Records** - Records containing other records
65+
- [ ] **Record Assignment** - Deep copy semantics
66+
- [ ] **With Statements** - `with Person do begin Name := 'John'; end;`
67+
68+
#### Enumerations
69+
- [ ] **Enum Types** - `type Color = (Red, Green, Blue);`
70+
- [ ] **Enum Variables** - Declaration and assignment
71+
- [ ] **Enum Operations** - Ord, Succ, Pred functions
72+
- [ ] **Enum Ranges** - `Red..Blue`
73+
74+
#### Sets
75+
- [ ] **Set Types** - `set of Color`
76+
- [ ] **Set Operations** - Union (`+`), intersection (`*`), difference (`-`)
77+
- [ ] **Set Membership** - `in` operator
78+
- [ ] **Set Literals** - `[Red, Green]`
79+
80+
### Phase 2: Enhanced Control Flow 🔄
81+
82+
#### Case Statements
83+
- [ ] **Integer Case** - `case x of 1: ...; 2: ...; else ...; end;`
84+
- [ ] **Character Case** - Case on character values
85+
- [ ] **Enum Case** - Case on enumeration values
86+
- [ ] **String Case** - Case on string values (modern Pascal)
87+
- [ ] **Range Cases** - `1..5: ...;`
88+
89+
#### Advanced Loops
90+
- [ ] **Repeat..Until** - `repeat ... until condition;`
91+
- [ ] **For..In Loops** - `for item in array do ...` (modern Pascal)
92+
- [ ] **Break Statement** - Exit loop early
93+
- [ ] **Continue Statement** - Skip to next iteration
94+
- [ ] **Exit Statement** - Exit from procedure/function
95+
96+
### Phase 3: User-Defined Routines 📚
97+
98+
#### Procedures
99+
- [ ] **Procedure Declaration** - `procedure DoSomething;`
100+
- [ ] **Parameters** - Value parameters (`x: Int`)
101+
- [ ] **Var Parameters** - Reference parameters (`var x: Int`)
102+
- [ ] **Const Parameters** - Read-only parameters (`const x: Int`)
103+
- [ ] **Local Variables** - Local var declarations
104+
- [ ] **Nested Procedures** - Procedures inside procedures
105+
106+
#### Functions
107+
- [ ] **Function Declaration** - `function Add(a, b: Int): Int;`
108+
- [ ] **Return Values** - `Result` variable and explicit returns
109+
- [ ] **Function Calls** - In expressions and statements
110+
- [ ] **Recursive Functions** - Self-calling functions
111+
112+
#### Advanced Routine Features
113+
- [ ] **Function Overloading** - Same name, different parameters
114+
- [ ] **Default Parameters** - `procedure Test(x: Int = 10);`
115+
- [ ] **Variable Parameters** - `array of const` support
116+
- [ ] **Inline Functions** - `inline` directive (modern Pascal)
117+
118+
### Phase 4: Constants & Advanced Types 🔧
119+
120+
#### Constants
121+
- [ ] **Typed Constants** - `const Pi: Float = 3.14159;`
122+
- [ ] **Untyped Constants** - `const MaxItems = 100;`
123+
- [ ] **Array Constants** - `const Colors: array[1..3] of String = ('Red', 'Green', 'Blue');`
124+
- [ ] **Record Constants** - Constant record initialization
125+
126+
#### Pointers
127+
- [ ] **Pointer Types** - `^Int`, `Pointer`
128+
- [ ] **Pointer Operations** - `@` (address of), `^` (dereference)
129+
- [ ] **Dynamic Memory** - `New`, `Dispose`, `GetMem`, `FreeMem`
130+
- [ ] **Nil Pointer** - `nil` constant
131+
132+
#### Advanced Types
133+
- [ ] **Type Aliases** - `type TInteger = Int;`
134+
- [ ] **Subrange Types** - `type TDigit = 0..9;`
135+
- [ ] **Variant Records** - Records with variant parts
136+
137+
### Phase 5: String Enhancements 📝
138+
139+
#### String Operations
140+
- [ ] **String Concatenation** - `+` operator for strings
141+
- [ ] **String Indexing** - `s[1]` for character access
142+
- [ ] **String Functions** - `Length`, `Copy`, `Pos`, `Delete`, `Insert`
143+
- [ ] **String Comparison** - Case-sensitive and case-insensitive
144+
- [ ] **String Formatting** - `Format` function
145+
- [ ] **String Interpolation** - Modern string formatting (if desired)
146+
147+
#### Character Handling
148+
- [ ] **Char Type** - Single character type
149+
- [ ] **Character Functions** - `UpCase`, `Chr`, `Ord`
150+
- [ ] **Character Sets** - Character classification
151+
152+
### Phase 6: File I/O & System 💾
153+
154+
#### File Operations
155+
- [ ] **Text Files** - `TextFile` type and operations
156+
- [ ] **Binary Files** - `File` type for binary data
157+
- [ ] **File Functions** - `Assign`, `Reset`, `Rewrite`, `Close`
158+
- [ ] **File I/O** - `ReadLn`, `WriteLn`, `Read`, `Write` for files
159+
- [ ] **File Status** - `EOF`, `IOResult` functions
160+
161+
#### System Functions
162+
- [ ] **Date/Time** - `Now`, `Date`, `Time` functions
163+
- [ ] **Math Functions** - `Sin`, `Cos`, `Sqrt`, `Abs`, `Round`, `Trunc`
164+
- [ ] **Random Numbers** - `Random`, `Randomize`
165+
- [ ] **System Info** - `ParamCount`, `ParamStr`
166+
167+
### Phase 7: Error Handling 🛡️
168+
169+
#### Exception Handling
170+
- [ ] **Try..Except** - `try ... except ... end;`
171+
- [ ] **Try..Finally** - `try ... finally ... end;`
172+
- [ ] **Raise Statement** - `raise Exception.Create('Error');`
173+
- [ ] **Exception Types** - Built-in exception hierarchy
174+
- [ ] **Exception Information** - Message, stack trace
175+
176+
### Phase 8: Advanced Language Features 🚀
177+
178+
#### Generics (Without Classes)
179+
- [ ] **Generic Procedures** - `procedure Test<T>(x: T);`
180+
- [ ] **Generic Functions** - `function Max<T>(a, b: T): T;`
181+
- [ ] **Generic Types** - `type TArray<T> = array of T;`
182+
- [ ] **Type Constraints** - Constraining generic parameters
183+
184+
#### Anonymous Functions
185+
- [ ] **Anonymous Procedures** - `procedure(x: Int) begin ... end`
186+
- [ ] **Anonymous Functions** - `function(x: Int): Int begin Result := x * 2; end`
187+
- [ ] **Lambda Expressions** - Simplified syntax
188+
189+
#### Modern Syntax
190+
- [ ] **Inline Variables** - `var x := 10;` (type inference)
191+
- [ ] **For..In with Index** - `for var i := Low(arr) to High(arr) do`
192+
- [ ] **Multiple Assignment** - If feasible
193+
- [ ] **String Case Insensitive** - Case statements on strings
194+
195+
### Phase 9: Units & Modularity 📦
196+
197+
#### Unit System
198+
- [ ] **Unit Declaration** - `unit MyUnit;`
199+
- [ ] **Interface Section** - Public declarations
200+
- [ ] **Implementation Section** - Private implementation
201+
- [ ] **Uses Clause** - Unit dependencies
202+
- [ ] **Unit Initialization** - Initialization/finalization sections
203+
204+
#### Conditional Compilation
205+
- [ ] **Compiler Directives** - `{$IFDEF}`, `{$IFNDEF}`, `{$ELSE}`, `{$ENDIF}`
206+
- [ ] **Compiler Defines** - Built-in and custom defines
207+
- [ ] **Platform Directives** - Platform-specific compilation
208+
209+
### Phase 10: Performance & Optimization ⚡
210+
211+
#### Compiler Optimizations
212+
- [ ] **Constant Folding** - Compile-time expression evaluation
213+
- [ ] **Dead Code Elimination** - Remove unused code
214+
- [ ] **Inline Expansion** - Inline function calls
215+
- [ ] **Loop Optimizations** - Optimize loop constructs
216+
217+
#### Native Compilation Enhancements
218+
- [ ] **Complete X64 Backend** - Full instruction set support
219+
- [ ] **Resource Embedding** - Embed compiled code in host executables
220+
- [ ] **Runtime Code Loading** - Load and execute machine code from files/resources
221+
- [ ] **Calling Convention Support** - Multiple calling conventions
222+
- [ ] **Host Integration** - Seamless integration with host applications
223+
224+
---
225+
226+
## 🎯 Development Priorities
227+
228+
### Phase Priority Order
229+
1. **Phase 1 (Data Types)** - Foundation for complex programs
230+
2. **Phase 3 (User Routines)** - Essential for any real programming
231+
3. **Phase 2 (Control Flow)** - Enhanced program structure
232+
4. **Phase 4 (Constants/Types)** - Advanced type system
233+
5. **Phase 5 (Strings)** - Better text handling
234+
6. **Phase 6 (File I/O)** - System integration
235+
7. **Phase 7 (Exceptions)** - Robust error handling
236+
8. **Phase 8 (Advanced)** - Modern language features
237+
9. **Phase 9 (Units)** - Large program organization
238+
10. **Phase 10 (Optimization)** - Performance improvements
239+
240+
### Immediate Next Steps (Recommendations)
241+
1. **Records** - Essential data structures (arrays mostly done)
242+
2. **User-defined Procedures/Functions** - Enable modular programming
243+
3. **Case Statements** - Common control structure
244+
4. **Advanced Array Operations** - Complete array functionality
245+
246+
---
247+
248+
## 📝 Notes
249+
250+
### Design Decisions
251+
- **No OOP** - Focus on procedural/functional programming
252+
- **UTF-8 Strings** - Modern text handling
253+
- **Strong Typing** - Type safety with explicit conversions
254+
- **Modern Pascal Syntax** - Include beneficial modern features
255+
- **Performance** - Both bytecode VM and native compilation support
256+
257+
### Testing Strategy
258+
- Add comprehensive tests for each new feature
259+
- Maintain existing test coverage
260+
- Performance benchmarks for major features
261+
- Cross-platform compatibility (where applicable)
262+
263+
### Documentation
264+
- Update this TODO after each session
265+
- Document new language features
266+
- Provide examples for each feature
267+
- Maintain syntax reference
268+
269+
---
270+
271+
**Last Updated:** June 2025
272+
**Current Focus:** Arrays implemented (core functionality working)
273+
**Next Session:** Records/Structures or User-Defined Procedures

0 commit comments

Comments
 (0)