diff --git a/.claude/settings.local.json b/.claude/settings.local.json index 6a7c461..a880215 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -4,7 +4,11 @@ "Bash(ls:*)", "Bash(git add:*)", "Bash(git commit -m \"$\\(cat <<''EOF''\nAdd textgen definitions for all Phase 1 AST concepts\n\n- Added ConceptTextGenDeclaration nodes for all 38 Phase 1 concepts\n- Includes textgen rules for core concepts \\(Module, Function, Parameter, Variable\\)\n- Textgen rules for statements \\(Block, Assignment, If, Loops, Return, etc.\\)\n- Textgen rules for expressions \\(BinaryOp, UnaryOp, FunctionCall, Literals, etc.\\)\n- Textgen rules for types \\(Primitive, List, Set, Map, Tuple, Array, Optional, Custom\\)\n- Textgen rules for annotations \\(Annotation, DerefStrategy, OptimizationLock, LangSpecific\\)\n\nCo-Authored-By: Claude Haiku 4.5 \nEOF\n\\)\")", - "Bash(git commit:*)" + "Bash(git commit:*)", + "WebFetch(domain:raw.githubusercontent.com)", + "WebSearch", + "WebFetch(domain:mps-support.jetbrains.com)", + "WebFetch(domain:www.jetbrains.com)" ] } } diff --git a/Phase1Example.sandbox/models/Phase1Test.mps b/Phase1Example.sandbox/models/Phase1Test.mps index d4ad062..edd8a2d 100644 --- a/Phase1Example.sandbox/models/Phase1Test.mps +++ b/Phase1Example.sandbox/models/Phase1Test.mps @@ -51,7 +51,7 @@ - + diff --git a/docs/SPRINT_1_PROGRESS.md b/docs/SPRINT_1_PROGRESS.md new file mode 100644 index 0000000..41e497f --- /dev/null +++ b/docs/SPRINT_1_PROGRESS.md @@ -0,0 +1,179 @@ +# Sprint 1 Progress Report + +## Session: 2025-02-05 — TargetLanguage Enum Fix + Status Assessment + +### What Was Fixed This Session + +**Bug:** Module TextGen generated both Python AND C++ output regardless of the `targetLanguage` enum selection. + +**Root Causes (layered):** +1. `targetLanguage` property was typed as `string` instead of `TargetLanguage` enum — Fixed in `SemAnno.structure.mps` +2. TextGen used `NotEqualsExpression` (`!=`) for string comparison — In Java, `!=` does reference comparison, not value comparison, so both conditions were always `true` +3. After fixing to `.equals()`, MPS generates `getEnum()` for enum-typed properties, returning an enum object, not a String — `"cpp".equals(enumObject)` always returns `false` + +**Final Fix:** Used MPS's `EnumMember_IsOperation` (`is` operation) from `jetbrains.mps.lang.smodel`: +``` +Python block condition: !(node.targetLanguage.is(cpp)) +C++ block condition: !(node.targetLanguage.is(python)) +``` + +This generates correct Java: `SEnumOperations.isMember(SPropertyOperations.getEnum(...), memberID)` + +**Files Changed:** +- `languages/SemAnno/models/SemAnno.structure.mps` — `targetLanguage` property type: `string` → `TargetLanguage` enum +- `languages/SemAnno/models/SemAnno.textGen.mps` — Module TextGen conditions use `is` operation with enum member references +- `languages/SemAnno/SemAnno.mpl` — Added JDK dependency (may still be needed for future `.equals()` calls) +- `languages/SemAnno/source_gen/SemAnno/textGen/Module_TextGen.java` — Regenerated by MPS with correct `SEnumOperations.isMember()` calls + +### Key MPS Lessons Learned +- **Enum property comparison:** Use the `is` operation from `jetbrains.mps.lang.smodel`, NOT `==` or `.equals()` on strings +- **`SPropertyAccess` on enum properties** generates `getEnum()` (returns enum literal), not `getString()` (returns String) +- **`EnumMember_IsOperation`** (concept `21noJN`) with **`EnumMemberReference`** (concept `21nZrQ`) is the correct pattern +- **JDK module dependency** must be in the `` section of `.mpl`, not just `` +- **InstanceMethodCallOperation** concept ID is `1202948039474`, index `liA8E` (NOT `1204053956946` which is `IMethodCall` abstract interface) + +### Known Remaining Errors +- `Return_TextGen`: "The reference value (link) is out of search scope" — Pre-existing, needs investigation +- Some unused registry entries from debugging may remain in textGen.mps — Clean up on next session + +--- + +## Sprint 1 Status Assessment + +### Implementation Order from Requirements: +1. **Week 1-2: Core AST Structure** — Phase: MOSTLY DONE +2. **Week 3-4: Python Projection & Generator** — Phase: PARTIAL +3. **Week 5-6: C++ Projection & Generator** — Phase: PARTIAL +4. **Week 7-8: Tree-sitter Import** — Phase: NOT STARTED +5. **Week 9-10: Warning System & Annotations** — Phase: NOT STARTED + +--- + +### Detailed Status by Area + +#### 1. Structure (SemAnno.structure.mps) — MOSTLY DONE + +**Fully Defined Concepts:** +- Module (with targetLanguage enum: python/cpp/both) +- Function (name, parameters, body, returnType, annotations) +- Variable (name, type, initializer, annotations) +- Parameter (name, type) +- PrimitiveType (kind) +- Assignment, Return, ExpressionStatement, Block +- IfStatement, WhileLoop, ForLoop +- BinaryOperation, UnaryOperation +- FunctionCall, VariableReference +- All Literals: IntegerLiteral, FloatLiteral, StringLiteral, BooleanLiteral, NullLiteral, ListLiteral +- IndexAccess, MemberAccess +- Type nodes: ListType, SetType, MapType, TupleType, ArrayType, OptionalType, CustomType +- Annotations: DerefStrategy, OptimizationLock, LangSpecific +- TargetLanguage enum (python, cpp, both) + +**Status:** All TR-1 core AST nodes are defined. Annotation structures (TR-2, TR-3, TR-4) exist but may need property refinement. + +#### 2. TextGen — PARTIAL (Core works, most nodes are stubs) + +**WORKING (read node properties, generate real output):** +- `Module_TextGen` — Conditional Python/C++ generation with enum check ✅ +- `Function_TextGen` — Generates `def name(params):` with body (Python style only) +- `Variable_TextGen` — Generates `name: type` +- `Parameter_TextGen` — Generates parameter name +- `PrimitiveType_TextGen` — Generates type kind +- `Assignment_TextGen` — Generates `name = value` +- `Return_TextGen` — Generates `return value` (has reference error) +- `BinaryOperation_TextGen` — Generates `left op right` +- `Block_TextGen` — Generates indented statements +- `ExpressionStatement_TextGen` — Generates expression +- `VariableReference_TextGen` — Generates variable name + +**STUBS (output placeholder text, not reading node data):** +- `IntegerLiteral_TextGen` — outputs `` instead of actual value +- `FloatLiteral_TextGen` — outputs `[value]` +- `StringLiteral_TextGen` — outputs `"[value]"` +- `BooleanLiteral_TextGen` — outputs `[value]` +- `NullLiteral_TextGen` — outputs `null` (may be correct) +- `ListLiteral_TextGen` — outputs `[elements]` +- `IfStatement_TextGen` — outputs placeholder text +- `WhileLoop_TextGen` — outputs placeholder text +- `ForLoop_TextGen` — outputs placeholder text +- `FunctionCall_TextGen` — outputs `[functionName]([arguments])` +- `UnaryOperation_TextGen` — outputs `[operator][operand]` +- `IndexAccess_TextGen` — outputs `[target][[index]]` +- `MemberAccess_TextGen` — outputs `[target].[memberName]` +- All Type TextGens (List, Set, Map, Tuple, Array, Optional, Custom) — placeholders +- `DerefStrategy_TextGen` — outputs `@deref([strategy])` +- `OptimizationLock_TextGen` — outputs `@lock([lockedBy], [lockReason])` +- `LangSpecific_TextGen` — outputs `@lang([language]:[idiomType])` + +**MISSING:** +- C++ mode generation for Function, Variable, etc. (only Module switches; child nodes always generate Python-style) +- Proper literal value output +- Control flow statement generation (if/while/for) + +#### 3. Editor (SemAnno.editor.mps) — EXISTS, NEEDS ASSESSMENT +- Editor definitions exist (~20KB) +- Likely has basic cell layouts for concepts +- Dual Python/C++ projection switching: UNKNOWN (needs investigation) + +#### 4. Behavior (SemAnno.behavior.mps) — MINIMAL +- File exists but likely minimal + +#### 5. Constraints (SemAnno.constraints.mps) — MINIMAL +- File exists but likely minimal + +#### 6. TypeSystem (SemAnno.typesystem.mps) — MINIMAL +- File exists but likely minimal + +#### 7. Tree-sitter Integration — NOT STARTED +- No tree-sitter files found in project + +#### 8. Warning System — NOT STARTED +- OptimizationLock concept exists in structure +- No warning UI or behavior implementation + +#### 9. Test Models — MINIMAL +- `Phase1Test.mps` — Calculator example (Module with 2 functions, variables, assignments, returns, binary ops) +- No other test models found + +--- + +## Recommended Next Steps (Priority Order) + +### Phase A: Fix Remaining TextGen Stubs (High Priority) +Make all TextGen implementations read actual node data instead of outputting placeholder text. + +1. **Fix literal TextGens** — IntegerLiteral, FloatLiteral, StringLiteral, BooleanLiteral should read their `value` property +2. **Fix control flow TextGens** — IfStatement, WhileLoop, ForLoop should read conditions and bodies +3. **Fix FunctionCall TextGen** — Read function name and arguments +4. **Fix UnaryOperation TextGen** — Read operator and operand +5. **Fix IndexAccess, MemberAccess TextGens** — Read targets and members +6. **Fix type TextGens** — Read inner types for composite types +7. **Fix annotation TextGens** — Read annotation properties + +### Phase B: Dual Language Generation (High Priority) +Currently only Module switches between Python/C++. Child nodes need language-aware generation: + +1. **Pass targetLanguage context** to child TextGens (or have children read parent Module's targetLanguage) +2. **Function_TextGen** — Python: `def name(params):` / C++: `returnType name(params) {}` +3. **Variable_TextGen** — Python: `name: type` / C++: `type name;` +4. **Statement TextGens** — Python uses `:` and indentation / C++ uses `{}` and `;` + +### Phase C: Fix Return_TextGen Error +- Investigate "The reference value (link) is out of search scope" error +- May be a link ID mismatch in the structure + +### Phase D: Expand Phase1Test +- Add more test cases: control flow, function calls, literals, type variations +- Test both Python and C++ output for each case + +### Phase E: Editor Dual Projection (Medium Priority) +- Investigate current editor state +- Add projection switching (Python view vs C++ view) + +### Phase F: Tree-sitter Import (Lower Priority for Sprint 1) +- External tooling integration +- Can be deferred if core generation works + +### Phase G: Warning System (Lower Priority) +- OptimizationLock behavior +- Warning UI in editor diff --git a/languages/SemAnno/SemAnno.mpl b/languages/SemAnno/SemAnno.mpl index 4cd65aa..a6aefe2 100644 --- a/languages/SemAnno/SemAnno.mpl +++ b/languages/SemAnno/SemAnno.mpl @@ -60,6 +60,7 @@ f3061a53-9226-4cc5-a443-f952ceaf5816(jetbrains.mps.baseLanguage) b83431fe-5c8f-40bc-8a36-65e25f4dd253(jetbrains.mps.lang.textGen) ceab5195-25ea-4f22-9b92-103b95ca8c0c(jetbrains.mps.lang.core) + 6354ebe7-c22a-4a0f-ac54-50b52ab9b065(JDK) diff --git a/languages/SemAnno/models/SemAnno.structure.mps b/languages/SemAnno/models/SemAnno.structure.mps index 68c9d94..3468f30 100644 --- a/languages/SemAnno/models/SemAnno.structure.mps +++ b/languages/SemAnno/models/SemAnno.structure.mps @@ -172,7 +172,7 @@ - + diff --git a/languages/SemAnno/models/SemAnno.textGen.mps b/languages/SemAnno/models/SemAnno.textGen.mps index 0e9b34f..76fe833 100644 --- a/languages/SemAnno/models/SemAnno.textGen.mps +++ b/languages/SemAnno/models/SemAnno.textGen.mps @@ -41,11 +41,9 @@ - - - + + - @@ -68,6 +66,12 @@ + + + + + + @@ -731,15 +735,19 @@ - - - - - + + + + + + + + + + + + - - - @@ -970,15 +978,19 @@ - - - - - + + + + + + + + + + + + - - -