--
--	cgtest83.occ -- fixed-sized MOBILE types
--	Copyright (C) 2001-2002 Fred Barnes <frmb2@ukc.ac.uk>
--
--	This program is free software; you can redistribute it and/or modify
--	it under the terms of the GNU General Public License as published by
--	the Free Software Foundation; either version 2 of the License, or
--	(at your option) any later version.
--
--	This program is distributed in the hope that it will be useful,
--	but WITHOUT ANY WARRANTY; without even the implied warranty of
--	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
--	GNU General Public License for more details.
--
--	You should have received a copy of the GNU General Public License
--	along with this program; if not, write to the Free Software
--	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
--



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

  #INCLUDE "cgmain.occ"
  #INCLUDE "cgreal.occ"

  --{{{  tests
  PROC test0 ()
    MOBILE INT x, y:
    MOBILE BYTE c, d:
    SEQ
      x := 20
      check.INT (id.INT (x), 20, "test0.0")
      y := x
      check.INT (y, 20, "test0.1")
      c := 'a'
      d := c PLUS 5
      check.BYTE (id.BYTE (d), 'f', "test0.2")
      CHAN MOBILE BYTE ch:
      PAR
        ch ! d
        ch ? c
      check.BYTE (id.BYTE (c), 'f', "test0.3")
  :
  PROC test1 ()
    MOBILE REAL64 x:
    SEQ
      x := 5.0
      check.REAL64 (id.REAL64 (x), 5.0, "test1.0")
      INITIAL MOBILE REAL64 y IS CLONE x:
      check.REAL64 (id.REAL64 (y), 5.0, "test1.1")
      check.REAL64 (id.REAL64 (x), 5.0, "test1.2")
      CHAN MOBILE REAL64 c:
      MOBILE REAL64 y:
      PAR
        SEQ
          x := (x + 1.0)
          c ! CLONE x
          x := (x + 1.0)
          c ! x
        SEQ
          c ? y
          check.REAL64 (id.REAL64 (y), 6.0, "test1.3")
          c ? y
          check.REAL64 (id.REAL64 (y), 7.0, "test1.4")
  :
  PROC test2 ()
    MOBILE REAL32 a, b, c:
    SEQ
      a := 0.125
      b := (2.0 * a)
      c := b
      c := (c + a)
      check.REAL32 (id.REAL32 (c), 0.375, "test2.0")
      check.REAL32 (id.REAL32 (c * 2.0), 0.75, "test2.1")
      CHAN MOBILE REAL32 ch:
      PAR
        ch ! c
        ch ? a
      check.REAL32 (id.REAL32 (a), 0.375, "test2.2")
  :
  PROC test3 ()
    MOBILE REAL32 a, b:
    MOBILE REAL64 c, d:
    SEQ
      c := 2.5
      a := REAL32 TRUNC id.REAL64 (c)
      b := (a / 2.5)
      d := REAL64 ROUND id.REAL32 (b)
      check.REAL32 (b, 1.0, "test3.0")
      check.REAL64 (d, 1.0, "test3.1")
  :
  PROC test4 ()
    MOBILE [8]BYTE array:
    SEQ
      array := "hellowor"
      check.BYTE (array[3], 'l', "test4.0")
      check.BYTE (array[7], 'r', "test4.1")
      [array FROM 4 FOR 4] := [i = 0 FOR 4 | 'a' + (BYTE i)]
      check.BYTE (array[6], 'c', "test4.2")
  :
  PROC test5 ()
    MOBILE [3]REAL64 point:
    MOBILE [2]INT screen:
    SEQ
      point[0] := 1.0
      point[1] := 1.0
      point[2] := 1.0
      screen[0] := INT ROUND (point[0] / point[2])
      screen[1] := INT ROUND (point[1] / point[2])
      check.INT (id.INT (screen[0]), 1, "test5.0")
      check.INT (id.INT (screen[1]), 1, "test5.1")
  :
  PROC test6 ()
    DATA TYPE WIBBLE
      MOBILE RECORD
        INT x:
        INT y:
        [16]BYTE name:
        INT len:
        REAL32 small.real:
        REAL64 big.real:
    :

    WIBBLE a, b:
    SEQ
      a[x] := 4
      a[y] := 9
      [a[name] FOR 4] := "fred"
      a[len] := 4
      check.INT (id.INT (a[x]), 4, "test6.0")
      check.INT (id.INT (a[y]), 9, "test6.1")
      check.BYTE (id.BYTE (a[name][3]), 'd', "test6.2")
      b := a
      check.INT (id.INT (b[y]), 9, "test6.3")
      CHAN WIBBLE c:
      PAR
        SEQ
          b[big.real] := 1234.5678
          c ! b
        c ? a
      check.INT (id.INT (a[x]), 4, "test6.4")
      check.REAL64 (id.REAL64 (a[big.real]), 1234.5678, "test6.5")
      CHAN WIBBLE c:
      PAR
        c ! CLONE a
        c ? b
      check.REAL64 (id.REAL64 (b[big.real]), 1234.5678, "test6.6")
      check.INT (a[x], 4, "test6.7")
  :
  PROC test7 ()
    DATA TYPE WIBBLE
      RECORD
        INT x:
        INT y:
        REAL64 real:
    :

    MOBILE WIBBLE a, b:
    SEQ
      a[x] := 42
      a[y] := a[x] + 6
      check.INT (id.INT (a[y]), 48, "test7.0")
      a[real] := 5.0
      b := CLONE a
      check.REAL64 (id.REAL64 (b[real]), 5.0, "test7.1")
      CHAN WIBBLE nm.c:
      CHAN MOBILE WIBBLE m.c:
      PAR
        SEQ
          a[real] := 42.0
          m.c ! a
          nm.c ? a
        SEQ
          m.c ? b
          nm.c ! b
      check.REAL64 (id.REAL64 (a[real]), 42.0, "test7.2")
      check.REAL64 (id.REAL64 (b[real]), 42.0, "test7.3")
  :
  PROC test8 ()
    CHAN MOBILE INT c, d:
    PAR
      --{{{  first
      MOBILE INT a:
      SEQ
        a := 5
        c ! a
      --}}}  
      --{{{  second
      MOBILE INT b:
      SEQ
        b := 4
        d ! b
      --}}}  
      --{{{  alt
      SEQ i = 0 FOR 2
        PRI ALT
          MOBILE INT e:
          c ? e
            check.INT (id.INT (e), 5, "test8.0")
          MOBILE INT f:
          d ? f
            check.INT (id.INT (f), 4, "test8.1")
      --}}}  
  :
  --}}}  
  SEQ
    init ("CG test 83", "fixed sized MOBILEs")
    title ("basic types")
    test0 ()
    test1 ()
    test2 ()
    test3 ()
    title ("array types")
    test4 ()
    test5 ()
    title ("record types")
    test6 ()
    test7 ()
    title ("alternatives")
    test8 ()
    finish ()
:


