Category : Modula II Source Code
Archive   : M2TUTOR.ZIP
Filename : COROUT.MOD

 
Output of file : COROUT.MOD contained in archive : M2TUTOR.ZIP
(* Chapter 15 - Program 1 *)
MODULE Corout;

FROM InOut IMPORT WriteCard, WriteString, WriteLn;

FROM SYSTEM IMPORT WORD, PROCESS, ADR, SIZE,
NEWPROCESS, TRANSFER;

VAR main, Process1, Process2 : PROCESS;
WorkSpace1, WorkSpace2 : ARRAY[1..300] OF WORD;

PROCEDURE MainProcess;
VAR Index : CARDINAL;
BEGIN
FOR Index := 1 TO 5 DO
WriteString('This is loop');
WriteCard(Index,2);
IF Index > 2 THEN
TRANSFER(Process1,Process2);
WriteString(' and back to main loop');
END;
WriteLn;
END; (* of FOR loop *)
WriteString('End of the MainProcess loop');
WriteLn;
TRANSFER(Process1,main);
END MainProcess;

PROCEDURE SubProcess;
BEGIN
LOOP
WriteString(' in SubProcess');
TRANSFER(Process2,Process1);
WriteString(' back');
END;
END SubProcess;

BEGIN (* Main Module Body *)
NEWPROCESS(MainProcess,ADR(WorkSpace1),SIZE(WorkSpace1),
Process1);
NEWPROCESS(SubProcess,ADR(WorkSpace2),SIZE(WorkSpace2),
Process2);
TRANSFER(main,Process1);
WriteString('End of the program');
WriteLn;
END Corout.




(* Result of execution

This is loop 1
This is loop 2
This is loop 3 in SubProcess and back to main loop
This is loop 4 back in SubProcess and back to main loop
This is loop 5 back in SubProcess and back to main loop
End of the MainProcess loop
End of the program

*)



  3 Responses to “Category : Modula II Source Code
Archive   : M2TUTOR.ZIP
Filename : COROUT.MOD

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/