Really can't understand why my program isn't working

319 Views Asked by At

I've really spent a lot of time working at this problem and googling around to find a solution, but I can't seem to find what's wrong.

I've learning how to code occam and have the following program:

PROC light (CHAN OF BYTE screen, CHAN OF INT light.change)
  INT light.on :
  WHILE TRUE
    SEQ
      light.change ? light.on
      IF
        light.on = 1
          screen ! 'y'
        TRUE
          SKIP
:

PROC test(CHAN OF BYTE keyboard, scr)
  CHAN OF INT to.light :
  INITIAL INT on IS 1(INT) :
  BYTE b :
  SEQ
    light(scr, to.light)
    WHILE TRUE
      SEQ
        keyboard ? b
        IF
          b = 'o'
            to.light ! on
          TRUE
            SKIP
:

All I'm trying to do is communicate from one process to another when I press the 'o' key.

The error message I'm getting from the (KRoC) compiler is:

Error at lift.occ:11
Program failed, state = e, eflags = 00000000

which is the light.on = 1 line.

As far as I can see, the light PROC will wait for some input on its light.change channel and will then assign it to its light.on variable. The program will then proceed to a conditional statement IF, where the light.on = 1 line should in this case evaluate to true. But instead I get this error.

I have tried using the -verbose flag, but the compiler says that you can't use it for .occ files.

Does anyone know how or if I can get more detailed info from the compiler?

Any help on this would be greatly appreciated.

Thanks

1

There are 1 best solutions below

1
On BEST ANSWER

The above code compiles for me and when run reaches deadlock

james:conc$ occbuild --program light.occ 
james:conc$ light
KRoC: deadlock: no valid processes found in workspace(s)

KRoC: program deadlocked (no processes to run)

I can also get it to run in verbose mode as below

occbuild -v --program light.occ 

On a different note you might want to change your structure. Try having three PROC's

PROC is.light.on(CHAN BYTE screen! , CHAN INT light.control)
  WHILE TRUE
...output to terminal if light is on or off

PROC light.switch(CHAN BYTE keyboard? , CHAN INT light.control)
  WHILE TRUE
...use the keyboard to turn light on and off

PROC light(CHAN BYTE keyboard? , screen!)
  CHAN INT light.control:--0 for light on;1 for light off
  PAR
    light.switch(keyboard? , light.control!)
    is.light.on(screen! , light.control?)