Implement the following plan:
Plan: Support INT16, INT32, INT64 integer types (Issue #46)
Context
The parser doesn't recognize INT16, INT32, INT64 as type keywords, causing parse failures on real-world occam programs (e.g., cast.occ, commstime.occ). These are standard occam explicit-width integer types that need the same treatment as INT, BYTE, REAL32, REAL64.
Changes
1. Lexer — lexer/token.go
Add 3 new token types and keyword entries:
- Token enum (~line 82): Add
INT16_TYPE, INT32_TYPE, INT64_TYPE after REAL64_TYPE
- tokenNames map (~line 172): Add
"INT16", "INT32", "INT64" entries
- keywords map (~line 220): Add
"INT16": INT16_TYPE, "INT32": INT32_TYPE, "INT64": INT64_TYPE
2. Parser — parser/parser.go
isTypeToken() (~line 1978): Add || t == lexer.INT16_TYPE || t == lexer.INT32_TYPE || t == lexer.INT64_TYPE — this single change propagates to all ~17 call sites
- MOSTNEG/MOSTPOS parsing (~line 2795): Add
!p.peekTokenIs(lexer.INT16_TYPE) && !p.peekTokenIs(lexer.INT32_TYPE) && !p.peekTokenIs(lexer.INT64_TYPE) to the guard check
- Type conversion prefix (~line 2807): Add
lexer.INT16_TYPE, lexer.INT32_TYPE, lexer.INT64_TYPE to the case list
3. AST — ast/ast.go
No changes needed — types stored as strings.
4. Codegen — codegen/codegen.go
occamTypeToGoBase() (~line 1400): Add cases "INT16" → "int16", "INT32" → "int32", "INT64" → "int64"
occamTypeToGo() (~line 1421): Add same cases
generateMostExpr() (~line 926): Add cases for INT16/INT32/INT64 mapping to math.MinInt16/math.MaxInt16, etc.
exprNeedsMath() (~line 893): Current check is return e.ExprType != "BYTE" — INT16/32/64 all need math import, so no change needed (they won't match "BYTE")
5. Tests
- Parser unit tests (
parser/parser_test.go): Add test for INT16/INT32/INT64 variable declarations and type conversions
- Codegen unit tests (
codegen/codegen_test.go): Add test for INT16/INT32/INT64 code generation
- E2E tests (
codegen/e2e_test.go or codegen/e2e_types_test.go): Add test that declares INT16/32/64 variables, uses type conversions and MOSTNEG/MOSTPOS, compiles and runs
6. Documentation
- Update
TODO.md to mark INT16/INT32/INT64 as supported
Verification
go test ./... # all tests pass
./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 # course module still compiles
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/be722174-d55e-4926-9bb6-697f4111e01a.jsonl