Everything works. Here's a summary of what I did:
Results
The Game of Life example (historical-examples/life.occ) now transpiles and compiles cleanly (go vet passes).
Source code changes to life.occ
The program used functions from the "Programming in occam 2" book's standard library (write.string, write.formatted, DATA.ITEM protocol, terminal.keyboard, terminal.screen) which are different from the KRoC course module. I made these modifications:
- Added inline
write.string PROC — loops over bytes, replacing the book library's version
- Added
write.small.int PROC — outputs small integers as decimal digits for ANSI escape sequences
- Rewrote
clear.screen — outputs ESC [2J directly as individual bytes instead of using write.string with an embedded escape character
- Rewrote
move.cursor — outputs the ANSI cursor positioning sequence directly using write.small.int, eliminating the dependency on write.formatted, DATA.ITEM protocol, and data.int variant tag
- Added
terminal.keyboard and terminal.screen channel declarations — these were runtime-provided channels in the original occam 2 environment
Transpiler bug fixes (3 bugs)
-
VAL [n]TYPE abbreviations generated wrong Go type — VAL [8]INT nx IS [...] produced var nx int = []int{...} instead of var nx []int = []int{...}. Fixed by adding IsFixedArray flag to the AST Abbreviation struct and propagating it through parser → codegen.
-
ALT guard channels hardcoded to chan int — Guarded ALT cases created var _alt0 chan int = nil regardless of the actual channel type. Fixed by adding chanElemTypes tracking to the Generator, populated from channel declarations and proc parameters.
-
Both fixes apply to the package-level and function-scoped codegen paths.
Note
The program compiles but won't run interactively since terminal.keyboard and terminal.screen are declared as plain Go channels with nothing connected to stdin/stdout. Making it fully runnable would require adding I/O goroutines to bridge these channels to the terminal.