Skip to content

Support guarded ALT with boolean pre-conditions #67

@associate-1

Description

@associate-1

Difficulty: Medium — Parser must handle expr & prefix on ALT cases; codegen must conditionally enable/disable select cases (e.g., by setting channels to nil when the guard is false).

Summary

Occam ALT cases can have boolean guard pre-conditions using the & operator. A guard that evaluates to FALSE disables that ALT branch. Currently the parser does not support this syntax.

Occam syntax

ALT
  running & in ? x
    ... only considered if running is TRUE
  (NOT paused) & tim ? AFTER timeout
    ... only considered if paused is FALSE
  TRUE & stop ? any
    ... always considered

Proposed Go mapping

select {
case x = <-in:   // wrap in: if running { ... }
case <-time.After(...):  // wrap in: if !paused { ... }
case any = <-stop:       // always active
}

For reflect.Select-based ALT replicators, disabled guards can be handled by setting the channel to nil (which makes a select case block forever, effectively disabling it).

Affected files

  • bar.occ (lines 327, 338, 352, 399, 402)

Work required

  1. Parser: Before parsing a channel input in ALT, check for expr & guard prefix
  2. AST: Add a Guard expression field to ALT case nodes
  3. Codegen: Conditionally enable/disable select cases based on guard value

Part of #43.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions