diff options
Diffstat (limited to 'js/scripting-lang/ALIGNMENT_PLAN.md')
-rw-r--r-- | js/scripting-lang/ALIGNMENT_PLAN.md | 245 |
1 files changed, 245 insertions, 0 deletions
diff --git a/js/scripting-lang/ALIGNMENT_PLAN.md b/js/scripting-lang/ALIGNMENT_PLAN.md new file mode 100644 index 0000000..f71d01d --- /dev/null +++ b/js/scripting-lang/ALIGNMENT_PLAN.md @@ -0,0 +1,245 @@ +# Baba Yaga Implementation Alignment Plan + +## 🎯 Goal: Achieve 90%+ Test Compatibility + +Based on the comprehensive test analysis, here's a practical plan to align the JavaScript and C implementations of Baba Yaga. + +## 📊 Current Status Breakdown + +### JavaScript Implementation (28/34 tests passing - 82%) +**Strengths:** +- ✅ All unit tests pass (23/23) +- ✅ All integration tests pass (4/4) +- ✅ Strong core language support + +**Weaknesses:** +- ❌ Array literal syntax (`[]`) not supported +- ❌ List concatenation (`concat`) not implemented +- ❌ Built-in function naming conflicts (`apply`) +- ❌ Advanced lambda calculus patterns limited + +### C Implementation (25/34 tests passing - 74%) +**Strengths:** +- ✅ Basic arithmetic and logic work well +- ✅ Function definitions supported +- ✅ Case expressions working +- ✅ Some Turing completeness tests pass + +**Weaknesses:** +- ❌ IO operations (`..out`, `..assert`) incomplete +- ❌ Function references (`@function`) not supported +- ❌ Advanced table operations limited +- ❌ Via operator missing +- ❌ Embedded functions not supported + +## 🚀 Three-Phase Alignment Strategy + +### Phase 1: Core Compatibility (Target: 26/34 tests passing) +**Focus**: Fix critical features that prevent basic language usage + +#### 1.1 Fix C Implementation Core Issues + +**Priority 1: IO Operations** +- **File**: `c/src/interpreter.c` or equivalent +- **Issue**: `..out` and `..assert` directives failing +- **Action**: Implement proper directive handling +- **Tests Fixed**: `05_io_operations.txt` + +**Priority 2: Function References** +- **File**: `c/src/parser.c` and `c/src/interpreter.c` +- **Issue**: `@function` syntax not parsed +- **Action**: Add support for function reference operator +- **Tests Fixed**: `08_first_class_functions.txt`, `16_function_composition.txt` + +#### 1.2 Fix JavaScript Implementation Core Issues + +**Priority 1: Array Literals** +- **File**: `js/parser.js` and `js/lang.js` +- **Issue**: `[]` syntax not supported +- **Action**: Add array literal parsing and evaluation +- **Tests Fixed**: Multiple Turing completeness tests + +**Priority 2: List Operations** +- **File**: `js/lang.js` (standard library) +- **Issue**: `concat` function missing +- **Action**: Implement array concatenation operator/function +- **Tests Fixed**: `05_loops_and_state.txt`, others + +#### 1.3 Fix Test Naming Conflicts + +**Priority 1: Rename Conflicting Identifiers** +- **Files**: `tests/turing-completeness/01_basic_proof.txt` +- **Issue**: `apply` conflicts with built-in function +- **Action**: Rename to `apply_func` or `call_func` +- **Tests Fixed**: `01_basic_proof.txt` + +### Phase 2: Feature Expansion (Target: 30/34 tests passing) +**Focus**: Add advanced features to bring implementations closer to parity + +#### 2.1 C Implementation Advanced Features + +**Priority 1: Table Enhancements** +- **Files**: `c/src/parser.c`, `c/src/table.c` +- **Issue**: Complex table literals and operations +- **Action**: Improve table parsing and access methods +- **Tests Fixed**: `17_table_enhancements.txt`, `19_embedded_functions.txt` + +**Priority 2: Via Operator** +- **Files**: `c/src/lexer.c`, `c/src/parser.c` +- **Issue**: Pipeline operator `via` not implemented +- **Action**: Add via operator token and evaluation +- **Tests Fixed**: `20_via_operator.txt` + +#### 2.2 JavaScript Implementation Advanced Features + +**Priority 1: Lambda Calculus Support** +- **Files**: `js/parser.js`, `js/lang.js` +- **Issue**: Advanced pattern matching in lambda expressions +- **Action**: Improve parser for complex lambda patterns +- **Tests Fixed**: `06_lambda_calculus.txt`, `07_complex_algorithms.txt` + +### Phase 3: Full Compatibility (Target: 32+/34 tests passing) +**Focus**: Polish and optimize for complete feature parity + +#### 3.1 Complex Algorithm Support +- **Both implementations**: Improve handling of recursive algorithms +- **Tests Fixed**: Remaining Turing completeness tests + +#### 3.2 Integration Test Compatibility +- **Both implementations**: Ensure complex feature interactions work +- **Tests Fixed**: `integration_03_functional_programming.txt` + +## 🛠️ Immediate Action Items (Week 1) + +### 1. Quick Wins - Test File Modifications + +Create compatibility versions of failing tests that work with current implementations: + +```bash +# Create modified test files +cp tests/turing-completeness/01_basic_proof.txt tests/turing-completeness/01_basic_proof_compat.txt +cp tests/turing-completeness/05_loops_and_state.txt tests/turing-completeness/05_loops_and_state_compat.txt +``` + +**Modify these files to:** +- Replace `apply` with `apply_func` +- Replace `[]` with table-based alternatives +- Replace `concat` with table merging operations +- Simplify advanced lambda calculus patterns + +### 2. Critical C Implementation Fixes + +**File: `c/src/interpreter.c`** +```c +// Add support for ..out directive +case TOKEN_DOT_DOT_OUT: + // Implement output handling + printf("%s\n", evaluate_expression(expr)); + break; + +// Add support for ..assert directive +case TOKEN_DOT_DOT_ASSERT: + // Implement assertion checking + if (!evaluate_boolean_expression(expr)) { + error("Assertion failed"); + } + break; +``` + +**File: `c/src/parser.c`** +```c +// Add support for @ function references +case TOKEN_AT: + advance(); // consume @ + // Parse function reference + return create_function_reference(current_token.value); +``` + +### 3. Critical JavaScript Implementation Fixes + +**File: `js/parser.js`** +```javascript +// Add support for array literals +parsePrimary() { + if (this.match('LEFT_BRACKET')) { + return this.parseArrayLiteral(); + } + // ... existing code +} + +parseArrayLiteral() { + const elements = []; + if (!this.check('RIGHT_BRACKET')) { + do { + elements.push(this.expression()); + } while (this.match('COMMA')); + } + this.consume('RIGHT_BRACKET', "Expected ']' after array elements"); + return { type: 'ArrayLiteral', elements }; +} +``` + +## 📋 Weekly Milestone Tracking + +### Week 1: Foundation +- [ ] Fix C IO operations +- [ ] Fix C function references +- [ ] Fix JS array literals +- [ ] Create compatibility test files +- **Target**: 26/34 tests passing on both implementations + +### Week 2: Advanced Features +- [ ] Implement C table enhancements +- [ ] Implement C via operator +- [ ] Improve JS lambda calculus support +- **Target**: 30/34 tests passing on both implementations + +### Week 3: Integration & Polish +- [ ] Fix remaining integration tests +- [ ] Optimize complex algorithms +- [ ] Performance tuning +- **Target**: 32+/34 tests passing on both implementations + +## 🎯 Success Criteria + +### Minimum Viable Compatibility (MVP) +- **Both implementations pass core unit tests (1-14)** +- **Both implementations pass basic integration tests** +- **Basic Turing completeness demonstrated** + +### Full Compatibility Goal +- **Both implementations pass 32+ of 34 tests** +- **Identical behavior on all supported features** +- **Clear documentation of any remaining differences** + +## 🔄 Iterative Testing Process + +After each fix: + +1. **Test Specific Feature**: + ```bash + ./tests/run_shared_tests.sh js unit | grep "Feature Name" + ./tests/run_shared_tests.sh c unit | grep "Feature Name" + ``` + +2. **Test Full Suite**: + ```bash + ./tests/run_shared_tests.sh js > js_results.txt + ./tests/run_shared_tests.sh c > c_results.txt + diff js_results.txt c_results.txt + ``` + +3. **Document Progress**: + - Update this plan with actual results + - Note any new issues discovered + - Adjust priorities based on findings + +## 💡 Key Principles + +1. **JavaScript as Reference**: All features must work in JS first +2. **Incremental Progress**: Fix one feature category at a time +3. **Test-Driven**: Every fix must be verified by passing tests +4. **Documentation**: Keep detailed records of changes and decisions +5. **Backward Compatibility**: Don't break existing working features + +The goal is systematic, measurable progress toward full implementation alignment, with JavaScript serving as the authoritative reference implementation. \ No newline at end of file |