Transputer occam Message Protocols Variant

Поділитися
Вставка
  • Опубліковано 11 вер 2024
  • -- Try It Online Occam Emulator
    -- tio.run/#
    -- tio.run/#occam-pi
    -- VARIANT PROTOCOL
    -- INMOS Limited occam 2 Reference Manual, 4.3.4 variant channels, page 32
    -- start of variant.protocol, example of CASE statement for variant channel
    -- VARIANT as in various or variable
    PROTOCOL STUDENT IS INT; [20]BYTE: -- sequential protocol, student number, student last name
    PROTOCOL PUPIL -- Channel One
    CASE -- Define CASEs b, is, s, case name is sent with every message
    b; BYTE -- one BYTE
    is; INT::[]BYTE -- counted array, integer, string
    s; STUDENT -- sequential protocol, STUDENT
    : -- end of PROTOCOL PUPIL
    #INCLUDE "course.module"
    PROC msend4 (CHAN PUPIL ch.one)
    BYTE a:
    [20]BYTE b:
    [256]BYTE c:
    INT d, e:
    SEQ
    a := 'A' -- BYTE
    d := 9 -- counted array length
    [c FROM 0 FOR d] := "razzmataz" -- array
    e := 12345 -- student number
    b := " " -- put in spaces
    [b FROM 0 FOR 5] := "Jones" -- student name
    ch.one ! b; a -- send BYTE
    ch.one ! is; d::c -- send counted array
    ch.one ! s; e; b -- send sequential protocol
    : -- end of msend4
    PROC getit4 (CHAN PUPIL ch.one, CHAN BYTE out!)
    PROC crlf () -- out ! cr lf
    SEQ
    out ! '*c'
    out ! '*n'
    : -- end of crlf
    PROC space () -- out ! space
    SEQ
    out ! ' '
    : -- end of space
    BYTE b1:
    [20]BYTE b:
    [256]BYTE c:
    INT d, e, counter, maxcount:
    PROC get.message () -- execute specific PROTOCOL b, is or s
    SEQ
    ch.one ? CASE -- CASE STATEMENT
    b; b1 -- single BYTE
    SEQ -- CHAN out is of type BYTE
    out.string("Single BYTE ", 0, out) -- output Single BYTE
    out ! b1
    crlf ()
    is; d::c -- counted array: integer, byte vector
    SEQ
    out.string("INT and String ", 0, out)
    SEQ i = 0 FOR d -- output string
    SEQ
    out ! c[i]
    crlf ()
    s; e; b
    SEQ
    out.string("Student # and Last Name ", 0, out) -- student number
    out.int(e, 0, out)
    space ()
    SEQ i = 0 FOR 20 -- student Last Name, no spaces
    SEQ
    IF
    (b[i]=' ')
    SKIP
    TRUE
    out ! b[i]
    crlf ()
    : -- end of get.message
    SEQ
    counter := 0
    maxcount := 3 -- number of messages received
    WHILE maxcount AFTER counter -- same as WHILE count less than maxcount
    SEQ
    get.message () -- get variant protocol message
    counter := counter + 1 -- increment counter
    : -- end of getit4
    PROC variant.protocol (CHAN BYTE out)
    CHAN PUPIL ch.one:
    PAR
    msend4(ch.one)
    getit4(ch.one, out)
    : -- end of PROCedure variant.protocol

КОМЕНТАРІ • 2