
#INCLUDE "course.module"
#INCLUDE "dynproc.module"

PROC testlib (VAL DPROCESS me, []CHAN OF ANY in, out)
  CHAN OF BYTE kyb RETYPES in[0]:
  CHAN OF BYTE scr RETYPES out[0]:
  CHAN OF BYTE err RETYPES out[1]:
  INITIAL DPROCESS me.copy IS me:
  INT me.int RETYPES me.copy:
  SEQ
    out.string ("This is a test of a bit of dynamic occam!*n", 0, scr)
    out.string ("me = ", 0, scr)
    out.int (me.int, 0, scr)
    scr ! '*n'
    BYTE ch:
    SEQ
      ch := '>'
      WHILE ch <> 'q'
        SEQ
          scr ! ch
          scr ! #FF
          kyb ? ch
:

PROC test.sort.cell (VAL DPROCESS me, []CHAN OF ANY in, out)
  CHAN OF INT data.in RETYPES in[0]:
  CHAN OF INT data.out RETYPES out[0]:
  INT value:
  SEQ
    data.in ? value
    IF
      value = (-1)
        data.out ! (-1)
      TRUE
        INITIAL BOOL running IS TRUE:
        WHILE running
          INT new.val:
          SEQ
            data.in ? new.val
            IF
              new.val = (-1)
                SEQ
                  running := FALSE
                  data.out ! value
                  data.out ! (-1)
              TRUE
                IF
                  new.val < value
                    data.out ! new.val
                  TRUE
                    SEQ
                      data.out ! value
                      value := new.val
:


PROC test.recursion (VAL DPROCESS me, []CHAN OF ANY in, out)
  INT v, res:
  SEQ
    CHAN OF INT chan.in RETYPES in[0]:
    CHAN OF INT chan.out RETYPES out[0]:
    SEQ
      chan.in ? v
      chan.out ! v
    IF
      v > 0
        INT libhandle:
        SEQ
          ccsp.libhandleof (me, libhandle)
          ccsp.run ("test.recursion", libhandle, in, out, res)
      TRUE
        SKIP
:



