Implement the following plan:
Phase 2: Full Course Module Transpilation (float_io.occ)
Context
The transpiler cleanly processes course_nofloat.module but produces 598 parse errors on the full course.module because float_io.occ uses 6 unimplemented constructs. All 598 errors trace to 4 parse-level root causes plus 2 codegen-only features.
Implementation Plan
Step 1: Lexer — bracket NEWLINE suppression + RETYPES keyword
lexer/lexer.go: Add [/] tracking to parenDepth so NEWLINEs inside [...] are suppressed (needed for multi-line array literals like VAL PowerTenFrac IS [#80000000, #A0000000, ...] :). Just add l.parenDepth++ on [ and l.parenDepth-- on ].
lexer/token.go: Add RETYPES keyword token + entries in tokenNames and keywords maps.
Step 2: AST — new node types
ast/ast.go: Add two nodes:
- ArrayLiteral (Expression) — Token, Elements []Expression
- RetypesDecl (Statement) — Token, IsVal, TargetType, IsArray, ArraySize, Name, Source
Step 3: Parser — untyped VAL abbreviations (~170 errors fixed)
parser/parser.go → parseAbbreviation(): After the [] open-array check (line 325-329), before the isTypeToken check (line 332), detect: if curToken is IDENT and peekToken is IS, it's an untyped abbreviation VAL <name> IS <expr> :. Parse with Type = "".
Step 4: Parser — array literal expressions (~340 errors fixed)
parser/parser.go → parseExpression() LBRACKET case (line 2591): After [, parse first expression, then:
- COMMA → array literal: continue parsing comma-separated elements until ]
- FROM → slice expression (existing logic)
- FOR → slice shorthand (existing logic)
- RBRACKET → single-element array literal
Step 5: Parser — RETYPES declarations (~7 errors fixed)
parser/parser.go → parseAbbreviation(): After parsing VAL [n]<type> <name>, if next token is RETYPES (instead of IS), parse as RetypesDecl. Handle both VAL INT X RETYPES X : and VAL [2]INT X RETYPES X :.
Step 6: Parser — multi-line expression continuation (~80 errors fixed)
parser/parser.go → parseBinaryExpr() (line 2680): After p.nextToken() past the operator, skip NEWLINE/INDENT tokens (tracking indent count). After parsing RHS, consume matching NEWLINE+DEDENT pairs to restore indent balance. This handles expr AND\n expr patterns.
Step 7: Codegen — untyped VAL + array literals
codegen/codegen.go:
- Package-level abbreviations with Type == "": emit var name = expr (omit type, let Go infer)
- ArrayLiteral: emit []int{e1, e2, ...} (all float_io.occ arrays are INT)
- Add ArrayLiteral case to containsX scanner functions
Step 8: Codegen — RETYPES
codegen/codegen.go:
- VAL INT X RETYPES X : → X := int(math.Float32bits(float32(X)))
- VAL [2]INT X RETYPES X : → _tmp := math.Float64bits(float64(X)); X := [2]int{int(uint32(_tmp)), int(uint32(_tmp >> 32))}
- Set needMath = true
Step 9: Codegen — transputer intrinsic helpers
codegen/codegen.go:
- Add transpIntrinsics map for LONGPROD/LONGDIV/LONGSUM/LONGDIFF/NORMALISE/SHIFTRIGHT/SHIFTLEFT
- In generateFuncCallExpr(): prefix intrinsic names with _
- Add containsIntrinsics() scanner → needMathBits flag → "math/bits" import
- Emit 7 Go helper functions (using uint64/uint32 arithmetic for 32-bit transputer semantics)
Step 10: Codegen — CAUSEERROR
codegen/codegen.go → generateProcCall(): If name is CAUSEERROR, emit panic("CAUSEERROR").
Step 11: Tests
- Parser unit tests: untyped VAL, array literal, RETYPES, multi-line expressions
- Codegen unit tests: array literal output, RETYPES output, intrinsic output, CAUSEERROR output
- E2E tests: untyped VAL usage, array literal indexing, multi-line boolean, intrinsic calls with known values
Step 12: Integration verification
go build -o occam2go .
./occam2go -I kroc/modules/course/libsrc -D TARGET.BITS.PER.WORD=32 -o /tmp/course_out.go kroc/modules/course/libsrc/course.module
go vet /tmp/course_out.go
go test ./...
Files Modified
| File |
Changes |
lexer/lexer.go |
[/] parenDepth tracking (2 lines) |
lexer/token.go |
RETYPES keyword (3 additions) |
ast/ast.go |
ArrayLiteral + RetypesDecl nodes |
parser/parser.go |
Untyped VAL, array literals, RETYPES, multi-line continuation |
codegen/codegen.go |
Array literal gen, RETYPES gen, intrinsic helpers, CAUSEERROR |
codegen/e2e_*_test.go |
New E2E tests |
codegen/codegen_test.go |
New unit tests |
parser/parser_test.go |
New parser tests |
If you need specific details from before exiting plan mode (like exact code snippets, error messages, or content you generated), read the full transcript at: /home/david/.claude/projects/-home-david-projects-code-associates-occam2go/c4302863-3896-4a30-bd1b-760356b188c1.jsonl