Skip to content

Latest commit

 

History

History
102 lines (86 loc) · 6.58 KB

File metadata and controls

102 lines (86 loc) · 6.58 KB

occam2go — Implementation Status

Fully Implemented

Core Constructs

  • SEQ — Sequential execution, with replicators (SEQ i = 0 FOR n) and optional STEP
  • PAR — Parallel execution via goroutines + sync.WaitGroup, with replicators
  • IF — Multi-branch conditionals, maps to if/else if chains, with replicators; supports multi-statement bodies (declarations scoped before process)
  • WHILE — Loops, maps to Go for loops; supports multi-statement bodies
  • CASE — Pattern matching with multiple cases and ELSE branch; supports multi-statement bodies
  • ALT / PRI ALT — Channel alternation, maps to Go select; supports boolean guards, timer timeouts, multi-statement bodies, and replicators (ALT i = 0 FOR n using reflect.Select). PRI ALT treated identically (Go has no priority select).
  • PRI PAR — Priority parallel, treated identically to PAR (Go goroutines have no priority)
  • SKIP — No-op process
  • STOP — Error + deadlock

Data Types & Declarations

  • INT, INT16, INT32, INT64, BYTE, BOOL, REAL, REAL32, REAL64 — Scalar types (INT16/32/64 map to int16/32/64, REAL/REAL64 map to float64, REAL32 maps to float32)
  • Variable declarationsINT x, y, z:
  • Arrays[n]TYPE arr: with index expressions; multi-dimensional [n][m]TYPE with nested init loops; mixed-dimension abbreviations [][n]TYPE and [][]TYPE
  • ChannelsCHAN OF TYPE c: with send (!) and receive (?); CHAN BYTE shorthand (without OF)
  • Channel arrays[n]CHAN OF TYPE cs: with indexed send/receive; multi-dimensional [n][m]CHAN OF TYPE with nested init loops; []CHAN, [][]CHAN, etc. proc params
  • Channel directionCHAN OF INT c? (receive-only) and CHAN OF INT c! (send-only); direction annotations at call sites (out!, in?) accepted and ignored
  • TimersTIMER tim: with reads and AFTER expressions
  • AbbreviationsVAL INT x IS 1:, INT y IS z:, untyped VAL x IS expr: — named constants and aliases
  • INITIAL declarationsINITIAL INT x IS 42: — mutable variables with initial values
  • Byte literals'A', '0' with occam escape sequences (*n, *c, *t)
  • Hex integer literals#FF, #80000000

Procedures & Functions

  • PROC — Declaration with VAL, reference, CHAN OF, and open array ([]TYPE) parameters
  • PROC calls — With automatic &/* for reference params, pass-through for channels
  • FUNCTION (IS form)INT FUNCTION square(VAL INT x) IS x * x
  • FUNCTION (VALOF form) — Local declarations + VALOF body + RESULT
  • Multi-result FUNCTIONsINT, INT FUNCTION f(...) returning multiple values via RESULT a, b
  • Nested PROCs/FUNCTIONs — Local definitions inside a PROC body, compiled as Go closures
  • KRoC-style colon terminators — Optional : at end of PROC/FUNCTION body
  • INLINE modifierINT INLINE FUNCTION f(...) — accepted and ignored (optimization hint only)
  • Built-in printprint.int, print.bool, print.string, print.newline

Expressions & Operators

  • Arithmetic+, -, *, /, \ (modulo)
  • Comparison=, <>, <, >, <=, >=
  • LogicalAND, OR, NOT
  • Bitwise/\, \/, ><, ~, <<, >>
  • AFTER — As boolean expression (maps to >)
  • Parenthesized expressions
  • Array indexingarr[i], arr[expr], multi-dimensional grid[i][j]
  • String literals — Double-quoted strings
  • Type conversionsINT expr, INT16 expr, INT32 expr, INT64 expr, BYTE expr, BOOL expr, REAL32 expr, REAL64 expr (including BOOL↔numeric conversions, and ROUND/TRUNC qualifiers for float↔int conversions)
  • Checked arithmeticPLUS, MINUS, TIMES — modular (wrapping) operators
  • MOSTNEG/MOSTPOS — Type min/max constants for INT, INT16, INT32, INT64, BYTE, REAL32, REAL64
  • SIZE operatorSIZE arr, SIZE "str" maps to len()
  • Array slices[arr FROM n FOR m] with slice assignment
  • Array literals[1, 2, 3] — inline array/table expressions
  • Multi-assignmenta, b := f(...) including indexed targets like x[0], x[1] := x[1], x[0]
  • Multi-line expression continuation — Binary operators and := at end of line continue expression on next line

Protocols

  • SimplePROTOCOL SIG IS INT (type alias)
  • SequentialPROTOCOL PAIR IS INT ; BYTE (struct)
  • VariantPROTOCOL MSG CASE tag; TYPE ... (interface + concrete types), including dotted tag names (bar.data, bar.terminate)

Records

  • RECORD — Struct types with field access via bracket syntax (p[x])

Type Reinterpretation & Intrinsics

  • RETYPES — Bit-level type reinterpretation (VAL INT X RETYPES X : for float32→int, VAL [2]INT X RETYPES X : for float64→int pair)
  • Transputer intrinsicsLONGPROD, LONGDIV, LONGSUM, LONGDIFF, NORMALISE, SHIFTLEFT, SHIFTRIGHT — extended-precision arithmetic as Go helper functions
  • CAUSEERROR — Error-raising primitive, maps to panic("CAUSEERROR")

Preprocessor

  • #IF / #ELSE / #ENDIF — Conditional compilation with TRUE, FALSE, DEFINED(), NOT, equality
  • #DEFINE — Symbol definition
  • #INCLUDE — File inclusion with search paths and include guards
  • #COMMENT / #PRAGMA / #USE — Ignored (blank lines)
  • Predefined symbolsTARGET.BITS.PER.WORD = 64

Tooling

  • gen-module — Generate .module files from KRoC SConscript build files

Not Yet Implemented

Required for shared_screen module (extends course module)

Feature Notes Used in
DATA TYPE X IS TYPE: Simple type alias (e.g. DATA TYPE COLOUR IS BYTE:). shared_screen.inc
DATA TYPE X RECORD Alternative record syntax (vs current RECORD X). shared_screen.inc
Counted array protocol BYTE::[]BYTE — length-prefixed array in protocols. shared_screen.inc, shared_screen.occ
RESULT param qualifier RESULT INT len on PROC params (output-only, like a write-only reference). float_io.occ

Other language features

Feature Notes
PRI ALT / PRI PAR Priority variants of ALT and PAR. Implemented — treated as ALT/PAR (Go has no priority select).
PLACED PAR Assigning processes to specific hardware.
PORT OF Hardware port mapping.
VAL []BYTE abbreviations VAL []BYTE cmap IS "0123456789ABCDEF": — named string constants.
#PRAGMA DEFINED Compiler hint to suppress definedness warnings. Can be ignored.