-- version control marker $Id: cgtest03.occ,v 1.4 1995/10/10 12:56:37 djb1 Exp $
-- Abbreviations

PROC cgtest3 (CHAN OF BYTE keyb, scr, err)

  #INCLUDE "cgmain.occ"

  VAL word IS "supercalifragilisticexpealidocious" :
  INT key :
  SEQ
    init ("CG test 3", "Abbreviations")

    --{{{  simple abbreviations           (A000 - A099)
    --{{{  output message
    title ("Simple abbreviations")
    --}}}
    SEQ
      --{{{  VAL abbreviations            (A000 - A009)
      INT x, y, z :
      SEQ
        x := 15
        y := 45
        z := 101
        VAL k IS x :
        check (k, 15, "A001")
        VAL j IS y :
        INT j :
        SEQ
          j := 47
          check (j, 47, "A002")
        VAL l IS z :
        INT z :
        SEQ
          z := 100
          check (l, 101, "A003")
        check (z, 101, "A004")
        VAL x IS y :
        check (x, 45, "A005")
        check (x, 15, "A006")
        check (y, 45, "A007")
        VAL a IS x :
        check (a, x, "A008")
      --}}}
      --{{{  COMMENT other abbreviations          (A010 - A019)
      --INT x, y, z :
      --#PRAGMA PERMITALIASES z
      --SEQ
        --x := 101
        --y := 23
        --z := 42
        --j IS y :
        --SEQ
          --j := 15
          --check (j, 15, "A011")
        --check   (y, 15, "A012")
        --x IS y :
        --x := 27
        --check (x, 101, "A013")
        --check (y,  27, "A014")
        --a IS x :
        --a IS y :
        --a IS z :
        --check (a, 42, "A015")
        --a IS x :
        --SEQ
          --a := a + 1
          --b IS a :
          --check (b, 102, "A016")
        --c IS z :
        ----#PRAGMA PERMITALIASES z
        --SEQ
          ----z := 175
          --check (c, 175, "A017")
          ----check (z, 175, "A018")
      --}}}
      --{{{  COMMENT nested abbreviations         (A020 - A039)
      --INT x, y, z, a :
      --#PRAGMA PERMITALIASES x, y
      --SEQ
        --x := 42
        --a := 99
        --a IS x :
        --SEQ
          --check (a, 42, "A021")
          --y := 54
          --a IS y :
          ----b IS y :
          --SEQ
            --check (a, 54, "A022")
            --{{{  COMMENT
            --b := b + 1
            --check (b, 55, "A023")
            --check (a, 55, "A024")
            --}}}
            --z := 10
            --b IS z :
            --check (b, 10, "A025")
            ----check (b, 55, "A026")
            --a IS a :
            --check (a, 55, "A027")
          --check (a, 42, "A028")
          ----check (x, 42, "A029")
        --check (a, 99, "A030")
        --check (x, 42, "A031")
      --}}}
      --{{{  COMMENT abbreviations before WHILE   (A040 - A049)
      --INT x :
      --#PRAGMA PERMITALIASES x
      --SEQ
        --x := 2
        --y IS x :
        --WHILE x > 0
          --IF
            --x = 2
              --x := 1
            --x = 1
              --SEQ
                --x := 0
                --check (y, 0, "A041")
      --}}}
    --}}}
    --{{{  subscript abbreviations        (A100 - A199)
    --{{{  output message
    title ("Subscript abbreviations")
    --}}}
    INT x , y, z :
    [5] BYTE b :
    SEQ
      x := 101
      VAL x IS word [5] :
      check (INT x, INT 'c', "A101")
      VAL temp IS word :
      VAL x IS temp [5] :
      check (INT x, INT 'c', "A102")
      y := 3
      VAL a IS y :
      VAL b IS word [3] :
      VAL c IS word [a] :
      VAL d IS word [y] :
      VAL e IS y + 1 :
      VAL f IS word [e] :
      SEQ
        check (INT b, INT 'e', "A103")
        check (INT c, INT 'e', "A104")
        check (INT d, INT 'e', "A105")
        check (INT f, INT 'r', "A106")
      x := 10
      VAL g IS word [x] :
      check (INT g, INT 'r', "A107")
    --}}}
    --{{{  slice abbreviations            (A200 - A299)
    --{{{  output message
    title ("Slice abbreviations")
    --}}}
    VAL last IS word [(SIZE word) - 1] :
    VAL x IS [word FROM 5 FOR 5] :
    SEQ
      check (INT x [3], INT 'i', "A201")
      --{{{  checks A202 to A206
      VAL y IS 10 :
      VAL z IS (SIZE  word) - y :
      VAL rest IS [word FROM y FOR z] :
      SEQ
        check (INT rest [(SIZE rest) - 1], INT last, "A202")
        VAL a1 IS [rest FROM 1 FOR z - 1] :
        VAL a2 IS [a1 FROM 1 FOR z - 2] :
        VAL a3 IS [a2 FROM 1 FOR z - 3] :
        VAL a4 IS [a3 FROM 1 FOR z - 4] :
        SEQ
          check (INT a1 [(SIZE a1) - 1], INT last, "A203")
          check (INT a2 [(SIZE a2) - 1], INT last, "A204")
          check (INT a3 [(SIZE a3) - 1], INT last, "A205")
          check (INT a4 [(SIZE a4) - 1], INT last, "A206")
      --}}}
    INT x, y, z :
    [SIZE word] BYTE this.word :
    SEQ
      x := 3
      y := 7
      this.word := word
      newword IS [this.word FROM x FOR y] :
      newword := "blurgle"
      check (INT this.word [4], INT 'l', "A207")
      --{{{  at present this range checks! (subscripted slices)
      check (INT [this.word FROM x FOR y] [4], INT 'g', "A208")
      --}}}
      check (INT this.word [2], INT 'p', "A209")
      check (INT this.word [10], INT 'r', "A210")
    --}}}
    --{{{  channel abbreviations          (A300 - A399)
    --{{{  output message
    title ("Channel abbreviations")
    --}}}
    --{{{  COMMENT
    --CHAN OF INT c :
    --[10] CHAN OF INT cs :
    --#PRAGMA PERMITALIASES cs
    --INT x, y, z :
    --SEQ
      --{{{  A301
      --PAR
        --c ! 42
        --d IS c :
        --SEQ
          --d ? x
          --check (x, 42, "A301")
      --}}}
      --{{{  A302
      --d IS c :
      --PAR
        --d ! 13
        --d ? x
      --check (x, 13, "A302")
      --}}}
      --{{{  A303
      --d IS c :
      --PAR
        --c ! 100
        --d ? x
      --check (x, 100, "A303")
      --}}}
      --{{{  A304
      --d IS cs [5] :
      --PAR
        --d ! 67
        --cs [5] ? x
      --check (x, 67, "A304")
      --}}}
      --{{{  A305
      --d IS cs [7] :
      --PAR
        --cs [7] ! 54
        --SEQ
          --d ? x
          --check (x, 54, "A305")
      --}}}
      --{{{  COMMENT A306
      --d IS cs [3] :
      ----#PRAGMA PERMITALIASES cs
      --PAR
        --cs [3] ! 12
        --ALT
          --ALT i = 0 FOR 10
            --(i <> 3) & cs [i] ? y
              --check (y, -y, "A306")
          --d ? x
            --check (x, 12, "A306")
      --}}}
      --{{{  A307
      --PAR
        --cs [0] ! 42
        --PAR i = 0 FOR 9
          --in IS cs [i] :
          --out IS cs [i+1] :
          --INT y :
          --SEQ
            --in ? y
            --out ! y
        --SEQ
          --cs [9] ? x
          --check (x, 42, "A307")
      --}}}
    --}}}
    --}}}
    --{{{  bug 320
    PROC bug.320()
      [100]INT mempool :
      INT sockid :
      SEQ
        sockid := 1
        []BYTE SCB RETYPES [mempool FROM sockid FOR 50] :
        INT16 scb.fport RETYPES [SCB FROM 26 FOR 2] :
        INT16 i16 :
        i16 := scb.fport
        check(sockid, 1, "B320a")
    :
    bug.320()
    --}}}
    --{{{  bug 592
    PROC bug.592()
      [10]INT16 x :
      SEQ
        SEQ i = 0 FOR SIZE x
          x[i] := INT16 (i+90)
        check(INT x[8], 98, "B592a")
        INT16 y IS x[8] :
        INT16 z IS x[3] :
        PROC q ()
          SEQ
            check(INT y, 98, "B592b")
            check(INT z, 93, "B592c")
            y := 57(INT16)
            z := -5(INT16)
            check(INT y, 57, "B592d")
            check(INT z, -5, "B592e")
            check(INT x[9], 99, "B592f")
            check(INT x[4], 94, "B592g")
        :
        SEQ
          check(INT y, 98, "B592h")
          check(INT z, 93, "B592i")
          q ()
          check(INT y, 57, "B592j")
          check(INT z, -5, "B592k")
        check(INT x[8], 57, "B592l")
        check(INT x[9], 99, "B592m")
        check(INT x[3], -5, "B592n")
        check(INT x[4], 94, "B592o")
    :
    bug.592()
    --}}}
    --{{{  bug 776
    PROC bug.776()
      [5]INT global.a :
      INT global.x, global.s :
      [2]INT global.b :
      PROC local ()
        [SIZE global.a]INT a :
        SEQ
          SEQ i = 0 FOR SIZE a
            a[i] := -i
    
          -- This test is testing whether the following defn of x
          -- is overwritten by 'result' bacause the compiler was mapping
          -- the complicated segment length before bringing x into mapping scope
          INT x IS a[0] :
          #IF DEFINED (COMPILER.TOCK)
          []INT b IS [a FROM 1 FOR x + 2]:
          #ELSE
          []INT b IS [a FROM 1 FOR (INT result :
                                    VALOF
                                      result := x + 2 -- evaluates to 2
                                      RESULT result
                                   )] :
          #ENDIF
          SEQ
            global.s := SIZE b
            global.x := x
            global.b := b
          global.a := a
      :
      SEQ
        local()
        SEQ
          check(global.s, 2, "B776a")
          check(global.x, 0, "B776b")
        SEQ i = 0 FOR SIZE global.a
          check(global.a[i], -i, "B776c")
        check(global.b[0], -1, "B776d")
        check(global.b[1], -2, "B776e")
    :
    bug.776()
    --}}}
    --{{{  bug 865
    PROC bug.865()
      CHAN OF INT c0, c1 :
      PAR
        c1 ! 88
        INT x :
        ALT
          d IS [c0] :  -- if it gets this wrong, it will most likely
          d[0] ? x     -- think the channel is ready
            check(0,  1, "B865a")
          d IS [c1] :
          d[0] ? x
            check(x, 88, "B865b")
    :
    bug.865()
    --}}}
    --{{{  bug 1135
    PROC bug.1135()
      [2]INT x : -- 2 words is small enough to ensure it goes into workspace
      SEQ
        x[0], x[1] := 99, 88
        y IS x[1] :
        z IS y :
        z := 77
        check(x[0], 99, "B1135a")
        check(x[1], 77, "B1135b")
    :
    bug.1135()
    --}}}
    --{{{  bug TS/2023
    PROC bug.TS.2023()
      CHAN OF INT c :
      PAR
        SEQ
          c ! 99
          d IS c :
          d ! 98
        INT x :
        SEQ
          c ? x
          check(x, 99, "B2023a")
          c ? x
          check(x, 98, "B2023b")
    :
    bug.TS.2023()
    --}}}
    --{{{  bug INSdi01968
    PROC bug.INSdi01968()
      INT a, b, c, d :
      PROC local()
        [2]INT x :
        SEQ
          x[0], x[1] := a, b
          y IS x[1] :
          z IS y :
          z := 7
          c := x[0]
          d := x[1]
      :
      SEQ
        a, b := 9, 8
        local()
        check(c, 9, "B01968a")
        check(d, 7, "B01968b")
    :
    bug.INSdi01968()
    --}}}
    finish ()
:
