Skip to content

Fix Game of Life example compilation (#72)#89

Merged
associate-1 merged 2 commits intomainfrom
fix/life-occ-compilation-72
Feb 23, 2026
Merged

Fix Game of Life example compilation (#72)#89
associate-1 merged 2 commits intomainfrom
fix/life-occ-compilation-72

Conversation

@associate-1
Copy link
Member

Summary

  • Fixed VAL [n]TYPE abbreviation codegen: VAL [8]INT nx IS [...] was generating var nx int = []int{...} — now correctly generates var nx []int = []int{...}. Added IsFixedArray flag to AST Abbreviation struct, propagated through parser and both codegen paths.
  • Fixed ALT guard channel type: Guarded ALT cases were hardcoding var _alt0 chan int = nil regardless of actual channel type. Added chanElemTypes map to track channel element types from declarations and proc parameters, used during ALT codegen.
  • Adapted life.occ: Replaced dependencies on the "Programming in occam 2" book standard library (write.string, write.formatted, DATA.ITEM protocol, data.int) with inline helper PROCs and direct ANSI escape byte output. Added terminal.keyboard/terminal.screen channel declarations.

The program now transpiles and passes go vet cleanly.

Test plan

  • All existing tests pass (go test ./...)
  • ./occam2go -o /tmp/life.go historical-examples/life.occ transpiles without errors
  • go vet /tmp/life.go passes
  • Course module still transpiles and vets cleanly

🤖 Generated with Claude Code

Three transpiler bugs fixed:
- VAL [n]TYPE abbreviations generated wrong Go type (int instead of []int)
- ALT guard channels hardcoded to chan int regardless of actual channel type
- Added chanElemTypes tracking to resolve channel element types from
  declarations and proc parameters

Adapted life.occ to remove dependencies on the "Programming in occam 2"
book standard library (write.string, write.formatted, DATA.ITEM protocol)
by defining inline helper PROCs and rewriting ANSI escape output directly.
Added terminal.keyboard/terminal.screen channel declarations.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Wrap the main body in PROC life (CHAN BYTE keyboard?, screen!, error!)
so the transpiler generates the stdin/stdout/stderr harness automatically.
Add channel direction annotations to all PROCs that pass through the
keyboard/screen channels.

Fix ALT guard variables to use <-chan (receive-only) instead of chan
(bidirectional), since ALT always receives. This allows directional
channels from the entry harness to be assigned to guard variables.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@associate-1 associate-1 merged commit 814db69 into main Feb 23, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants