-- version control marker $Id: cgtest12.occ,v 1.5 1996/11/05 12:16:45 svd Exp $

PROC cgtest12 (CHAN OF BYTE keyb, scr, err)
  #INCLUDE "cgmain.occ"

  PROTOCOL NANY IS ANY:

  SEQ
    init ("CG test 12", "Protocols")

    --{{{  unnamed protocols               (P000 - P099)
    title ("Testing channel communication")
    --{{{  ANY                             (P000 - P009)
    --CHAN OF ANY c, d :
    CHAN OF NANY c, d :
    INT x :
    BYTE y :
    SEQ
      PAR
        c ! 0
        c ? x
      check (x, 0, "P001")
      PAR
        c ! 'a'
        c ? y
      check (INT y, INT 'a', "P002")
      PAR
        d ! 'a'
        d ? y
      check (INT y, INT 'a', "P003")
    
    --}}}
    --{{{  INT                             (P010 - P019)
    CHAN OF INT c, d :
    INT x , y:
    SEQ
      PAR
        SEQ
          c ! 0
          c ! 1
        SEQ
          c ? x
          c ? y
      check (x, 0, "P011")
      check (y, 1, "P012")
    --}}}
    --{{{  BYTE                            (P020 - P029)
    CHAN OF BYTE c :
    BYTE x, y :
    SEQ
      PAR
        c ! 'a'
        c ? x
      PAR
        c ! 0 (BYTE)
        c ? y
      check (INT x, INT 'a', "P021")
      check (INT y, 0, "P022")
    --}}}
    --{{{  BOOL                            (P030 - P039)
    CHAN OF BOOL c :
    BOOL x, y :
    SEQ
      PAR
        c ! TRUE
        c ? x
      PAR
        c ! BOOL 0
        c ? y
      check (INT x, INT TRUE, "P031")
      check (INT y, 0, "P032")
    --}}}
    --{{{  []INT                           (P040 - P049)
    CHAN OF [5]INT c :
    VAL tbl IS [1,2,3,4,5] :
    [5]INT x :
    SEQ
      PAR
        c ! tbl
        c ? x
      check (x [2], 3, "P041")
    --}}}
    --{{{  arrays of channels              (P050 - P059)
    [5]CHAN OF INT c :
    VAL tbl IS [1,2,3,4,5] :
    [5]INT x :
    SEQ
      PAR i = 0 FOR 5
        PAR
          c [i] ! tbl [i]
          c [i] ? x [i]
      check (x [0], 1, "P051")
      check (x [4], 5, "P052")
    --}}}
    --{{{  variable array protocols        (P060 - P069)
    CHAN OF INT :: [] INT c :
    VAL tbl IS [1,2,3,4,5] :
    [10] INT x :
    INT y :
    SEQ
      PAR
        c ! SIZE tbl :: tbl
        c ? y :: x
      check (y,     5, "P061")
      check (x [3], 4, "P062")
    --}}}
    --{{{  There is some int64 testing in the Extended types test
    --}}}
    --}}}
    --{{{  simple protocols                (P100 - P199)
    title ("Testing simple protocols")
    --{{{  ANY                             (P100 - P109)
    PROTOCOL any IS ANY :
    CHAN OF any c, d :
    INT x :
    BYTE y :
    SEQ
      PAR
        c ! 0
        c ? x
      check (x, 0, "P100")
      PAR
        c ! 'a'
        c ? y
      check (INT y, INT 'a', "P101")
      PAR
        d ! 'a'
        d ? y
      check (INT y, INT 'a', "P102")
    --}}}
    --{{{  INT                             (P100 - P119)
    PROTOCOL test IS INT :
    CHAN OF test c, d :
    INT x , y:
    SEQ
      PAR
        SEQ
          c ! 0
          c ! 1
        SEQ
          c ? x
          c ? y
      check (x, 0, "P111")
      check (y, 1, "P112")
    --}}}
    --{{{  BYTE                            (P120 - P129)
    PROTOCOL test IS BYTE :
    CHAN OF test c :
    BYTE x, y :
    SEQ
      PAR
        c ! 'a'
        c ? x
      PAR
        c ! 0 (BYTE)
        c ? y
      check (INT x, INT 'a', "P121")
      check (INT y, 0, "P122")
    --}}}
    --{{{  BOOL                            (P130 - P139)
    PROTOCOL test IS BOOL :
    CHAN OF test c :
    BOOL x, y :
    SEQ
      PAR
        c ! TRUE
        c ? x
      PAR
        c ! BOOL 0
        c ? y
      check (INT x, INT TRUE, "P131")
      check (INT y, 0, "P132")
    --}}}
    --{{{  []INT                           (P140 - P149)
    PROTOCOL test IS [5]INT :
    CHAN OF test c :
    VAL tbl IS [1,2,3,4,5] :
    [5]INT x :
    SEQ
      PAR
        c ! tbl
        c ? x
      check (x [2], 3, "P141")
    --}}}
    --{{{  arrays of channels              (P150 - P159)
    PROTOCOL test IS INT :
    [5]CHAN OF test c :
    VAL tbl IS [1,2,3,4,5] :
    [5]INT x :
    SEQ
      PAR i = 0 FOR 5
        PAR
          c [i] ! tbl [i]
          c [i] ? x [i]
      check (x [0], 1, "P151")
      check (x [4], 5, "P152")
    --}}}
    --{{{  variable array protocols        (P160 - P169)
    PROTOCOL test IS INT :: [] INT :
    CHAN OF test c :
    VAL tbl IS [1,2,3,4,5] :
    [10]INT x :
    INT y :
    SEQ
      PAR
        c ! SIZE tbl :: tbl
        c ? y :: x
      check (y, 5, "P161")
      check (x [4], 5, "P162")
      PAR
        c ! 3 :: [10,11,12,13]
        c ? y :: x
      check (y, 3, "P163")
      check (x[2], 12, "P164")
      check (x[3], 4, "P165")   -- should not have changed
    --}}}
    --}}}
    --{{{  sequential protocols            (P200 - P299)
    title ("Testing sequential protocols")
    --{{{  INT ; INT                       (P200 - P209)
    PROTOCOL test IS INT ; INT :
    CHAN OF test c :
    INT x, y, z :
    SEQ
      PAR
        c ! 0 ; 10
        c ? x ; y
      check (x,  0, "P201")
      check (y, 10, "P202")
      PAR
        SEQ i = 0 FOR 5
          c ! i ; 1000 + i
        SEQ
          SEQ i = 0 FOR 4
            c ? x ; y
          c ? x ; z
      check (x, 4, "P203")
      check (y, 1003, "P204")
      check (z, 1004, "P205")
    --}}}
    --{{{  INT ; INT ; INT                 (P210 - P219)
    PROTOCOL test IS INT ; INT ; INT :
    CHAN OF test c :
    INT x, y , z:
    SEQ
      PAR
        c ! 0 ; 10 ; 15
        c ? x ; y ; z
      check (x,  0, "P211")
      check (y, 10, "P212")
      check (z, 15, "P213")
    --}}}
    --{{{  INT ; BYTE                      (P220 - P229)
    PROTOCOL test IS INT ; BYTE :
    CHAN OF test c :
    INT x :
    BYTE y :
    SEQ
      PAR
        c ! 0 ; 10 (BYTE)
        c ? x ; y
      check (x, 0, "P221")
      check (INT y, 10, "P222")
    --}}}
    --{{{  INT ; INT :: [] BYTE ; BOOL     (P230 - P239)
    PROTOCOL test IS INT ; INT :: [] BYTE ; BOOL :
    CHAN OF test c :
    INT x, y, z :
    BOOL b :
    VAL tbl IS "hello" :
    [10] BYTE a :
    SEQ
      PAR
        c ! -15 ; SIZE tbl :: tbl ; TRUE
        c ? x ; y :: a ; b
      check (x, -15, "P231")
      check (y, 5, "P232")
      check (INT a[3], INT 'l', "P233")
      check (INT b , INT TRUE , "P234")
    --}}}
    --}}}
    --{{{  variant protocols               (P300 - P399)
    title ("Testing variant protocols")
    --{{{  single tag                      (P300 - P309)
    PROTOCOL test
      CASE
        tag1 ; INT
    :
    CHAN OF test c :
    INT x :
    SEQ
      PAR
        c ! tag1 ; -67
        c ? CASE
          tag1 ; x
            check (x, -67, "P301")
      PAR
        c ! tag1 ; 123
        c ? CASE tag1 ; x
      check (x, 123, "P302")
      PAR
        c ! tag1 ; 57
        c ? CASE
          tag1 ; x
            check (x, 57, "P303")
    --}}}
    --{{{  two tags                        (P310 - P319)
    PROTOCOL test
      CASE
        tag1 ; INT
        tag2 ; INT
    :
    CHAN OF test c :
    INT x :
    SEQ
      PAR
        c ! tag1 ; -67
        c ? CASE
          tag1 ; x
            check (x, -67, "P311")
          tag2 ; x
            check (0, 1, "P312")
      PAR
        c ! tag1 ; 123
        c ? CASE tag1 ; x
      check (x, 123, "P313")
      PAR
        SEQ
          c ! tag1 ; 57
          c ! tag2 ; 42
        SEQ i = 0 FOR 2
          c ? CASE
            tag1 ; x
              check (x, 57, "P314")
            tag2 ; x
              check (x, 42, "P315")
    --}}}
    --{{{  multiple tags                   (P320 - P339)
    PROTOCOL test
      CASE
        tag1 ; INT
        tag2 ; INT ; INT
        tag3 ; INT :: [] BYTE
        tag4
    :
    CHAN OF test c :
    INT x, y :
    VAL word IS "word" :
    [10] BYTE a :
    SEQ
      PAR
        --{{{  output 4 messages
        SEQ
          c ! tag1 ; 42
          c ! tag3 ; SIZE word :: word
          c ! tag4
          c ! tag2 ; 10 ; 20
        --}}}
        --{{{  receive 4 messages
        SEQ i = 0 FOR 4
          c ? CASE
            tag1 ; x
              check (x, 42, "P321")
            tag2 ; x ; y
              SEQ
                check (x, 10, "P325")
                check (y, 20, "P326")
            tag3 ; y :: a
              SEQ
                check (y, 4, "P322")
                check (INT a [2], INT 'r', "P323")
            tag4
              check (0, 0, "P324")
        --}}}
      PAR
        c ! tag2 ; 45 ; 57
        --{{{  test correct message sent
        c ? CASE
          tag2 ; x ; x
            check (x, 57, "P327")
          tag1 ; x
            check (0, 1, "P328")
          tag3 ; y :: a
            check (0, 1, "P329")
          tag4
            check (0, 1, "P330")
        --}}}
    --}}}
    --{{{  ALT input                       (P350 - P359)
    PROTOCOL p
      CASE
        tag1 ; INT
        tag2
    :
    CHAN OF p c1 :
    CHAN OF INT c2 :
    INT x , y :
    SEQ
      PAR
        SEQ
          c1 ! tag1 ; 13
          c2 ! 42
        ALT
          c2 ? x
            check (0, 1, "P351")  -- should not be performed
          c1 ? CASE
            tag1 ; x
              SEQ
                check (x, 13, "P352")
                c2 ? y
                check (y, 42, "P353")
            tag2
              check (0, 1, "P354") -- should not be performed
      check (x, 13, "P355")
    --}}}
    --{{{  more ALT input                  (P360 - P369)
    PROTOCOL p
      CASE
        tag1 ; INT
        tag2
    :
    CHAN OF p c1 :
    CHAN OF INT c2 :
    INT x , y, z, a, b :
    SEQ
      PAR
        SEQ
          c1 ! tag2
          c2 ! 42
          c1 ! tag1 ; 13
        SEQ i = 0 FOR 3
          ALT
            c2 ? a
              x := i
            c1 ? CASE
              tag1 ; b
                y := i
              tag2
                z := i
      check (a, 42, "P361")
      check (b, 13, "P362")
      check (x,  1, "P363")
      check (y,  2, "P364")
      check (z,  0, "P365")
    --}}}
    --}}}
    --{{{  passing channel parameters      (P400 - P499)
    --{{{  output message
    title ("Passing channel parameters")
    --}}}
    --{{{  unnamed protocol                (P400 - P409)
    CHAN OF INT c :
    PROC out.int (CHAN OF INT c, VAL INT int)
      c ! int
    :
    PROC in.int (CHAN OF INT c, INT int)
      c ? int
    :
    INT x :
    SEQ
      PAR
        out.int (c, 42)
        c ? x
      check (x, 42, "P401")
      PAR
        in.int (c, x)
        c ! 101
      check (x, 101, "P402")
      PAR
        in.int (c, x)
        out.int (c, 54)
      check (x, 54, "P403")
    --}}}
    --{{{  simple protocol                 (P410 - P419)
    PROTOCOL p IS INT :
    CHAN OF p c :
    PROC out.int (CHAN OF p c, VAL INT int)
      c ! int
    :
    PROC in.int (CHAN OF p c, INT int)
      c ? int
    :
    INT x :
    SEQ
      PAR
        out.int (c, 42)
        c ? x
      check (x, 42, "P411")
      PAR
        in.int (c, x)
        c ! 101
      check (x, 101, "P412")
      PAR
        in.int (c, x)
        out.int (c, 54)
      check (x, 54, "P413")
    --}}}
    --{{{  sequential protocol             (P420 - P429)
    PROTOCOL p IS INT ; BYTE :
    CHAN OF p c :
    PROC out.int (CHAN OF p c, VAL INT int, VAL BYTE b)
      c ! int ; b
    :
    PROC in.int (CHAN OF p c, INT int, BYTE b)
      c ? int ; b
    :
    INT x :
    BYTE b :
    SEQ
      PAR
        out.int (c, 42, 'a')
        c ? x ; b
      check (x, 42, "P421")
      check (INT b, INT 'a', "P422")
      PAR
        in.int (c, x, b)
        c ! 101 ; 'z'
      check (x, 101, "P423")
      check (INT b, INT 'z', "P424")
      PAR
        in.int (c, x, b)
        out.int (c, 54, 'k')
      check (x, 54, "P425")
      check (INT b, INT 'k', "P426")
    --}}}
    --{{{  variable array protocol         (P430 - P439)
    PROTOCOL p IS INT :: [] BYTE :
    CHAN OF p c :
    PROC out.int (CHAN OF p c, VAL INT int, VAL [] BYTE b)
      c ! int :: b
    :
    PROC in.int (CHAN OF p c, INT int, [] BYTE b)
      c ? int :: b
    :
    INT x :
    [10] BYTE b :
    SEQ
      PAR
        out.int (c, 3, "hello")
        c ? x :: b
      check (x, 3, "P431")
      check (INT b [1], INT 'e', "P432")
      PAR
        in.int (c, x, b)
        c ! 8 :: "raddishy"
      check (x, 8, "P433")
      check (INT b [7], INT 'y', "P434")
      PAR
        in.int (c, x, b)
        out.int (c, 7, "blurgle")
      check (x, 7, "P435")
      check (INT b[4], INT 'g', "P436")
    --}}}
    --{{{  variant protocol                (P440 - P449)
    PROTOCOL p
      CASE
        tag1 ; INT :: [] BYTE
        tag2 ; BOOL
    :
    CHAN OF p c :
    PROC out.int (CHAN OF p c, VAL INT int, VAL [] BYTE b)
      c ! tag1 ; int :: b
    :
    PROC in.int (CHAN OF p c, INT int, [] BYTE b)
      c ? CASE tag1 ; int :: b
    :
    INT x :
    [10] BYTE b :
    BOOL boolean :
    SEQ
      PAR
        out.int (c, 3, "hello")
        c ? CASE tag1 ; x :: b
      check (x, 3, "P441")
      check (INT b [1], INT 'e', "P442")
      PAR
        in.int (c, x, b)
        c ! tag1 ; 8 :: "raddishy"
      check (x, 8, "P443")
      check (INT b [7], INT 'y', "P444")
      PAR
        in.int (c, x, b)
        out.int (c, 7, "blurgle")
      check (x, 7, "P445")
      check (INT b[4], INT 'g', "P446")
      PAR
        out.int (c, 3, "hello")
        c ? CASE
          tag1 ; x :: b
            check (0, 0, "P447")
          tag2 ; boolean
            check (INT boolean, 100, "P447")
      check (x, 3, "P448")
      check (INT b [1], INT 'e', "P449")
    --}}}
    --{{{  ANY
    PROC p (CHAN OF INT c)
      c ! 27
    :
    CHAN OF NANY cc :
    CHAN OF INT c RETYPES cc:
    PAR
      p(c)
      INT x :
      SEQ
        c ? x
        check(x, 27, "P450")
    --}}}
    
    --}}}
    --{{{  Bug 281
    PROC bug.281 ()
      PROTOCOL a
        CASE
          fred -- The compiler doesn't mind if this line is commented out
      :
      PROTOCOL b
        CASE
          --fred  -- Comment this out, and the compiler will crash
      :
      CHAN OF a c :
      PAR
        c ! fred
        INT x :
        SEQ
          x := -99
          ALT
            c ? CASE
              fred
                x := 99
          check (x, 99, "B281a")
    :
    bug.281 ()
    --}}}
    --{{{  Bug 283
    PROC bug.283 ()
      PROTOCOL prot
        CASE
          tag ; INT
      :
      INT w, x, y, z :
      SEQ
        z := 100
        CHAN OF prot c :
        PAR
          c ? CASE
            tag ; x
              y := z
          SEQ
            c ! tag ; 99
            w := z
        check(w, 100, "B283a")
        check(x,  99, "B283b")
        check(y, 100, "B283c")
        check(z, 100, "B283d")
    :
    bug.283 ()
    --}}}
    --{{{  Bug 289
    PROC bug.289 ()
      PROTOCOL CONTROL
        CASE
          tc.command; INT -- command from keyboard
      :
      PROC sink.control(CHAN OF CONTROL c, BOOL stop)
        WHILE NOT stop
          -- (1) If key is declared here then there is no error
          c ? CASE
            INT key :
            tc.command; key
              SKIP
      :
      BOOL s1, s2 :
      SEQ
        s1, s2 := TRUE, TRUE
        CHAN OF CONTROL c1, c2:
        PAR
          sink.control(c1, s1)
          sink.control(c2, s2)
        check.BOOL (s1, TRUE, "B289a")
        check.BOOL (s2, TRUE, "B289b")
    :
    bug.289()
    --}}}
    --{{{  Bug 314
    -- This test has been moved to a separate test in the 'rtrun' directory
    -- because it produces a warning about a PORT not being placed.
    -- This is 'dubious', so I am taking it out of the mainstream tests.
    -- Conor O'Neill; 24/03/93.
    --PROC bug.314()
    --  PORT OF INT port :
    --  PROC bug.314a()
    --    INT any :
    --    SEQ
    --      port ! 88
    --      port ? any
    --      check(any, 88, "B314a")
    --  :
    --  bug.314a()
    --:
    --bug.314()
    --}}}
    --{{{  Bug 706
    PROC bug.706()
      PROC init.i16(INT16 x, VAL INT16 y)
        x := y
      :
      CHAN OF INT16 :: []BYTE c :
      PAR
        INT16 len :
        [4]INT16 a :
        [10]BYTE buf :
        INT int :
        SEQ
          SEQ i = 0 FOR SIZE buf
            buf[i] := BYTE i
          len := -1(INT16)
          init.i16(len, 3(INT16))
          SEQ i = 0 FOR SIZE a
            a[i] := len
          c ! len :: buf
          int := 2
          c ! a[int] :: buf
          c ! len :: buf
        INT16 len :
        [10]BYTE buf :
        [4]INT16 a :
        INT int :
        SEQ
          SEQ i = 0 FOR SIZE buf
            buf[i] := BYTE(i + 99)
          len := -1(INT16)
          c ? len :: buf
          check (INT len, 3, "B706a")
          check (INT buf[2], 2, "B706b")
          len := -1(INT16)
          c ? len :: buf
          check (INT len, 3, "B706c")
          check (INT buf[2], 2, "B706d")
          SEQ i = 0 FOR SIZE a
            a[i] := -1(INT16)
          int := 2
          c ? a[int] :: buf
          check (INT a[int], 3, "B706e")
          check (INT buf[2], 2, "B706f")
          SEQ i = 0 FOR 3
            check(INT buf[i], i, "B706g")
          SEQ i = 3 FOR (SIZE buf) - 3
            check(INT buf[i], i+99, "B706h")
    :
    bug.706()
    --}}}
    --{{{  Bug 743
    PROC bug.743()
      PROTOCOL prot IS [3]INT :
      CHAN OF prot c :
      PAR
        INT x :
        SEQ
          x := 2
          c ! [x, x+1, x+x]
        [3]INT y :
        SEQ
          c ? y
          check(y[0], 2, "B743a")
          check(y[1], 3, "B743b")
          check(y[2], 4, "B743c")
    :
    bug.743()
    --}}}
    --{{{  bug 864
    PROC bug.864()
      PROC init.INT32(INT32 x, VAL INT32 n)
        x := n
      :
      PROC init.INT64(INT64 x, VAL INT64 n)
        x := n
      :
      PROC check.INT32(VAL INT32 x, y, VAL []BYTE msg)
        check(INT x, INT y, msg)
      :
      PROC check.INT64(VAL INT64 x, y, VAL []BYTE msg)
        check(INT x, INT y, msg)
      :
      CHAN OF INT32::[]BYTE c32 :
      CHAN OF INT32 d32 :
      CHAN OF INT64::[]BYTE c64 :
      CHAN OF INT64 d64 :
      PAR
        VAL msg IS "0123456789" :
        SEQ
          c32 ! INT32 (SIZE msg) :: msg
          c32 ! INT32 (SIZE msg) :: msg
          d32 ! -1(INT32)
          d32 ! -1(INT32)
    
          c64 ! INT64 (SIZE msg) :: msg
          c64 ! INT64 (SIZE msg) :: msg
          d64 ! -1(INT64)
          d64 ! -1(INT64)
        [10]BYTE buffer :
        INT32 int32 :
        INT64 int64 :
        SEQ
          c32 ? int32 :: buffer
          check.INT32(int32, 10(INT32), "B864a")
          init.INT32(int32, -1(INT32))
          c32 ? int32 :: buffer
          check.INT32(int32, 10(INT32), "B864b")
          init.INT32(int32, 0(INT32))
          d32 ? int32
          check.INT32(int32, -1(INT32), "B864c")
          init.INT32(int32, 0(INT32))
          d32 ? int32
          check.INT32(int32, -1(INT32), "B864d")
    
          c64 ? int64 :: buffer
          check.INT64(int64, 10(INT64), "B864e")
          init.INT64(int64, -1(INT64))
          c64 ? int64 :: buffer
          check.INT64(int64, 10(INT64), "B864f")
          init.INT64(int64, 0(INT64))
          int64 := 0(INT64)
          d64 ? int64
          check.INT64(int64, -1(INT64), "B864g")
          init.INT64(int64, 0(INT64))
          d64 ? int64
          check.INT64(int64, -1(INT64), "B864h")
    :
    bug.864()
    --}}}
    --{{{  bug 1238
    PROC bug.1238()
      PROTOCOL MESSAGE IS [2]INT16 :
    
      CHAN OF MESSAGE c :
      PAR
        INT16 actuator.number :
        SEQ
          actuator.number := -1(INT16)
          c ! [ actuator.number, 27(INT16) ]
          --VAL x IS [ actuator.number, 27(INT16) ] :
          --c ! x
        [2]INT16 buf :
        SEQ
          c ? buf
          check(INT buf[0], -1, "B1238a")
          check(INT buf[1], 27, "B1238b")
    :
    bug.1238()
    --}}}
    --{{{  bug 1294
    PROC bug.1294()
      INT16 i16 :
      PROTOCOL protocol IS INT16 :: []BYTE :
      PROC set.INT16(INT16 var, VAL INT16 val)
        var := val
      :
      PROC local ()
        CHAN OF protocol c :
        PAR
          c ! i16 :: "hello there"
          [30]BYTE buffer :
          INT16 len :
          SEQ
            c ? len :: buffer
            check(INT len, 5, "B1294a")
      :
      SEQ
        i16 := -1(INT16) -- ensure the high bytes are set
        set.INT16(i16, 5(INT16))
        local()
    :
    bug.1294()
    --}}}
    --{{{  bug 1297
    PROC bug.1297()
      CHAN OF INT::[]BYTE c :
      PAR
        BYTE b :
        INT i :
        SEQ
          b := 'b'
          i := 2
          c ! 2 :: ['a', b]
          c ! i :: ['a', b]
        INT j :
        [2]BYTE buf :
        SEQ
          c ? j :: buf
          check(j,          2,       "B1297a")
          check(INT buf[0], INT 'a', "B1297b")
          check(INT buf[1], INT 'b', "B1297c")
          c ? j :: buf
          check(j,          2,       "B1297d")
          check(INT buf[0], INT 'a', "B1297e")
          check(INT buf[1], INT 'b', "B1297f")
    :
    bug.1297()
    --}}}
    --{{{  bug 1298
    PROC bug.1298()
      CHAN OF INT::[]INT c :
      PAR
        INT i :
        SEQ
          i := 2
          c ! 2 :: [77, i]
          c ! i :: [77, i]
        INT j :
        [2]INT buf :
        SEQ
          c ? j :: buf
          check(j,      2,  "B1298a")
          check(buf[0], 77, "B1298b")
          check(buf[1], 2,  "B1298c")
          c ? j :: buf
          check(j,      2,  "B1298d")
          check(buf[0], 77, "B1298e")
          check(buf[1], 2,  "B1298f")
    :
    bug.1298()
    --}}}
    --{{{  bug 1455-a
    PROC bug.1455a()
      PROTOCOL protocol IS INT::[]BYTE :
      CHAN OF protocol c :
      PAR
        [10]BYTE packet :
        INT len :
        SEQ
          SEQ i = 0 FOR SIZE packet
            packet[i] := BYTE i
          len := 5
          c ! len :: [packet FROM 0 FOR len * 2]
        [10]BYTE packet :
        INT len :
        SEQ
          c ? len :: packet
          check(len, 5, "B1455aa")
          SEQ i = 0 FOR len
            check(INT packet[i], i, "B1455ab")
    :
    bug.1455a()
    --}}}
    --{{{  bug 1455-b
    PROC bug.1455b()
      VAL size  IS 20 :
      VAL small IS 10 :
      PROC local.check(VAL INT exp, len, [size]BYTE array, VAL []BYTE str)
        SEQ
          check(exp, 0, str)
          check(len, small, str)
          SEQ i = 0 FOR small
            SEQ
              check(INT array[i], size - i, str)
              array[i] := BYTE #FF
      :
      PROTOCOL protocol IS INT ; INT :: []BYTE :
      CHAN OF protocol c :
      PAR
        INT len, exp :
        [size]BYTE array :
        SEQ
          SEQ i = 0 FOR SIZE array
            array[i] := BYTE (size - i)
          len := small
          exp := 0
          c ! exp ; len :: array
          c ! exp ; len :: [array FROM 0 FOR len]
          c ! exp ; len :: [array FROM 0 FOR len+exp]
          c ! exp ; len :: [array FROM 0 FOR len+exp]
          --c ! 999 ; 0 :: array
    
        INT len, exp:
        [size]BYTE array :
        SEQ
          exp := small
          c ? exp ; len :: [array FROM exp FOR size]
          --CHAN OF ANY c RETYPES c :
          --SEQ
          --  c ? exp
          --  check(exp, 999, "B1455baa")
          --  x IS [array FROM exp FOR size] :
          --  SEQ
          --    check(exp, 999, "B1455bab")
          --    c ? len
          --    check(exp, 999, "B1455bac")
          --    c ? [x FROM 0 FOR len]
          --    check(exp, 999, "B1455bad")
          local.check(exp, len, array, "B1455ba")
          exp := size
          c ? exp ; len :: [array FROM 0 FOR exp + size]
          local.check(exp, len, array, "B1455bb")
          exp := size
          c ? exp ; len :: [array FROM exp FOR exp + size]
          local.check(exp, len, array, "B1455bc")
          exp := size
          ALT
            c ? exp ; len :: [array FROM exp FOR exp + size]
              local.check(exp, len, array, "B1455bd")
    
          -- This is illegal; we consider the counted array input to happen
          -- with both the length and array in parallel; thus we can't
          -- 'short-circuit' the array if the length is zero.
          --exp := size
          --c ? exp ; len :: [array FROM exp FOR 20]
          --check(exp, 999, "B1455be")
          --check(len, 0,   "B1455bf")
    :
    bug.1455b()
    --}}}
    --{{{  bug 1626
    PROC bug.1626()
      PROC bug.1626.test([]CHAN OF NANY ins, []INT32 pr, VAL INT inlink)
        [10]INT16 packet16 :
        SEQ
          SEQ i = 0 FOR SIZE packet16
            packet16[i] := INT16 i
          ins[inlink] ? [packet16 FROM 0 FOR INT pr[4]]
          SEQ i = 0 FOR 5
            check(INT packet16[i], i+10, "B1626a")
          SEQ i = 5 FOR (SIZE packet16) - 5
            check(INT packet16[i], i, "B1626b")
      :
      [3]CHAN OF NANY chans :
      PAR
        [5]INT32 pr:
        SEQ
          pr := [1(INT32), 2(INT32), 3(INT32), 4(INT32), 5(INT32)]
          bug.1626.test(chans, pr, 2)
        chans[2] ! [10(INT16), 11(INT16), 12(INT16), 13(INT16), 14(INT16)]
    :
    bug.1626()
    --}}}
    --{{{  bug INSdi01894
    PROC bug.INSdi01894()
      CHAN OF INT::[]BYTE c :
      PAR
        PROC send(CHAN OF INT::[]BYTE c, VAL INT x)
          [2]INT length :
          VAL MSG IS "hello" :
          SEQ
            length := [99, 22]
            length[x] := 5
            c ! length[0] :: MSG
        :
        send(c, 0)
        [10]BYTE buf :
        [2]INT length :
        SEQ
          c ? length[0] :: buf
          check(length[0], 5, "B1894a")
          check.BYTE(buf[3], 'l', "B1894b")
    :
    bug.INSdi01894()
    --}}}
    finish ()
:
