changed PascalIO.Get behaviour and used Allocate instead of ALLOCATE
This commit is contained in:
parent
9dccd59665
commit
021619910e
|
@ -13,7 +13,7 @@ IMPLEMENTATION MODULE CSP;
|
||||||
|
|
||||||
FROM random IMPORT Uniform;
|
FROM random IMPORT Uniform;
|
||||||
FROM SYSTEM IMPORT BYTE, ADDRESS, NEWPROCESS, TRANSFER;
|
FROM SYSTEM IMPORT BYTE, ADDRESS, NEWPROCESS, TRANSFER;
|
||||||
FROM Storage IMPORT ALLOCATE, DEALLOCATE;
|
FROM Storage IMPORT Allocate, Deallocate;
|
||||||
IMPORT Traps;
|
IMPORT Traps;
|
||||||
|
|
||||||
CONST WorkSpaceSize = 1000;
|
CONST WorkSpaceSize = 1000;
|
||||||
|
@ -163,8 +163,8 @@ IMPLEMENTATION MODULE CSP;
|
||||||
BEGIN
|
BEGIN
|
||||||
Pop(free, newprocess);
|
Pop(free, newprocess);
|
||||||
IF newprocess = NIL THEN
|
IF newprocess = NIL THEN
|
||||||
ALLOCATE(newprocess,SIZE(ProcessDescriptor));
|
Allocate(newprocess,SIZE(ProcessDescriptor));
|
||||||
ALLOCATE(newprocess^.wsp, WorkSpaceSize)
|
Allocate(newprocess^.wsp, WorkSpaceSize)
|
||||||
END;
|
END;
|
||||||
WITH newprocess^ DO
|
WITH newprocess^ DO
|
||||||
father := cp;
|
father := cp;
|
||||||
|
@ -198,7 +198,7 @@ IMPLEMENTATION MODULE CSP;
|
||||||
PROCEDURE InitChannel(VAR ch: Channel);
|
PROCEDURE InitChannel(VAR ch: Channel);
|
||||||
(* Initialize the channel ch *)
|
(* Initialize the channel ch *)
|
||||||
BEGIN
|
BEGIN
|
||||||
ALLOCATE(ch, SIZE(ChannelDescriptor));
|
Allocate(ch, SIZE(ChannelDescriptor));
|
||||||
WITH ch^ DO
|
WITH ch^ DO
|
||||||
InitQueue(senders);
|
InitQueue(senders);
|
||||||
owner := NIL;
|
owner := NIL;
|
||||||
|
@ -227,7 +227,7 @@ IMPLEMENTATION MODULE CSP;
|
||||||
BEGIN
|
BEGIN
|
||||||
WITH ch^ DO
|
WITH ch^ DO
|
||||||
Push(cp, senders);
|
Push(cp, senders);
|
||||||
ALLOCATE(cp^.msgadr, SIZE(data));
|
Allocate(cp^.msgadr, SIZE(data));
|
||||||
m := cp^.msgadr;
|
m := cp^.msgadr;
|
||||||
cp^.msglen := HIGH(data);
|
cp^.msglen := HIGH(data);
|
||||||
FOR i := 0 TO HIGH(data) DO
|
FOR i := 0 TO HIGH(data) DO
|
||||||
|
@ -276,7 +276,7 @@ IMPLEMENTATION MODULE CSP;
|
||||||
Push(cp, ready);
|
Push(cp, ready);
|
||||||
Push(aux, ready)
|
Push(aux, ready)
|
||||||
END;
|
END;
|
||||||
DEALLOCATE(aux^.msgadr, aux^.msglen+1);
|
Deallocate(aux^.msgadr, aux^.msglen+1);
|
||||||
DoTransfer
|
DoTransfer
|
||||||
END
|
END
|
||||||
END Receive;
|
END Receive;
|
||||||
|
@ -338,7 +338,7 @@ IMPLEMENTATION MODULE CSP;
|
||||||
BEGIN
|
BEGIN
|
||||||
InitQueue(free);
|
InitQueue(free);
|
||||||
InitQueue(ready);
|
InitQueue(ready);
|
||||||
ALLOCATE(cp,SIZE(ProcessDescriptor));
|
Allocate(cp,SIZE(ProcessDescriptor));
|
||||||
WITH cp^ DO
|
WITH cp^ DO
|
||||||
sons := 0;
|
sons := 0;
|
||||||
father := NIL
|
father := NIL
|
||||||
|
|
|
@ -17,7 +17,7 @@ IMPLEMENTATION MODULE PascalIO;
|
||||||
FROM Streams IMPORT Stream, StreamKind, StreamMode, StreamResult,
|
FROM Streams IMPORT Stream, StreamKind, StreamMode, StreamResult,
|
||||||
InputStream, OutputStream, OpenStream, CloseStream,
|
InputStream, OutputStream, OpenStream, CloseStream,
|
||||||
EndOfStream, Read, Write, StreamBuffering;
|
EndOfStream, Read, Write, StreamBuffering;
|
||||||
FROM Storage IMPORT ALLOCATE;
|
FROM Storage IMPORT Allocate;
|
||||||
FROM SYSTEM IMPORT ADR;
|
FROM SYSTEM IMPORT ADR;
|
||||||
|
|
||||||
TYPE charset = SET OF CHAR;
|
TYPE charset = SET OF CHAR;
|
||||||
|
@ -98,7 +98,7 @@ IMPLEMENTATION MODULE PascalIO;
|
||||||
Xtext := Xtext^.next;
|
Xtext := Xtext^.next;
|
||||||
END;
|
END;
|
||||||
IF Xtext = NIL THEN
|
IF Xtext = NIL THEN
|
||||||
ALLOCATE(Xtext,SIZE(IOstream));
|
Allocate(Xtext,SIZE(IOstream));
|
||||||
Xtext^.next := head;
|
Xtext^.next := head;
|
||||||
head := Xtext;
|
head := Xtext;
|
||||||
END;
|
END;
|
||||||
|
@ -125,14 +125,20 @@ IMPLEMENTATION MODULE PascalIO;
|
||||||
WITH InputText^ DO
|
WITH InputText^ DO
|
||||||
IF type # Preading THEN Error(Preading); END;
|
IF type # Preading THEN Error(Preading); END;
|
||||||
IF NOT done THEN
|
IF NOT done THEN
|
||||||
Get(InputText);
|
IF EndOfStream(stream, result) THEN
|
||||||
|
eof := TRUE;
|
||||||
|
ch := 0C;
|
||||||
|
ELSE
|
||||||
|
Read(stream, ch, result);
|
||||||
done := TRUE;
|
done := TRUE;
|
||||||
END;
|
END;
|
||||||
|
END;
|
||||||
RETURN ch;
|
RETURN ch;
|
||||||
END;
|
END;
|
||||||
END NextChar;
|
END NextChar;
|
||||||
|
|
||||||
PROCEDURE Get(InputText: Text);
|
PROCEDURE Get(InputText: Text);
|
||||||
|
VAR dummy: CHAR;
|
||||||
BEGIN
|
BEGIN
|
||||||
WITH InputText^ DO
|
WITH InputText^ DO
|
||||||
IF type # Preading THEN Error(Preading); END;
|
IF type # Preading THEN Error(Preading); END;
|
||||||
|
@ -140,11 +146,8 @@ IMPLEMENTATION MODULE PascalIO;
|
||||||
Traps.Message("unexpected EOF");
|
Traps.Message("unexpected EOF");
|
||||||
HALT;
|
HALT;
|
||||||
END;
|
END;
|
||||||
IF EndOfStream(stream, result) THEN
|
IF done THEN done := FALSE;
|
||||||
eof := TRUE;
|
ELSE dummy := NextChar(InputText);
|
||||||
ch := 0C;
|
|
||||||
ELSE
|
|
||||||
Read(stream, ch, result);
|
|
||||||
END;
|
END;
|
||||||
END;
|
END;
|
||||||
END Get;
|
END Get;
|
||||||
|
|
|
@ -8,7 +8,7 @@ IMPLEMENTATION MODULE Processes [1];
|
||||||
|
|
||||||
FROM SYSTEM IMPORT ADDRESS, TSIZE, NEWPROCESS, TRANSFER;
|
FROM SYSTEM IMPORT ADDRESS, TSIZE, NEWPROCESS, TRANSFER;
|
||||||
|
|
||||||
FROM Storage IMPORT ALLOCATE;
|
FROM Storage IMPORT Allocate;
|
||||||
|
|
||||||
FROM Traps IMPORT Message;
|
FROM Traps IMPORT Message;
|
||||||
|
|
||||||
|
@ -28,8 +28,8 @@ IMPLEMENTATION MODULE Processes [1];
|
||||||
wsp: ADDRESS;
|
wsp: ADDRESS;
|
||||||
BEGIN
|
BEGIN
|
||||||
s0 := cp;
|
s0 := cp;
|
||||||
ALLOCATE(wsp, n);
|
Allocate(wsp, n);
|
||||||
ALLOCATE(cp, TSIZE(ProcessDescriptor));
|
Allocate(cp, TSIZE(ProcessDescriptor));
|
||||||
WITH cp^ DO
|
WITH cp^ DO
|
||||||
next := s0^.next;
|
next := s0^.next;
|
||||||
s0^.next := cp;
|
s0^.next := cp;
|
||||||
|
@ -94,7 +94,7 @@ IMPLEMENTATION MODULE Processes [1];
|
||||||
END Init;
|
END Init;
|
||||||
|
|
||||||
BEGIN
|
BEGIN
|
||||||
ALLOCATE(cp, TSIZE(ProcessDescriptor));
|
Allocate(cp, TSIZE(ProcessDescriptor));
|
||||||
WITH cp^ DO
|
WITH cp^ DO
|
||||||
next := cp;
|
next := cp;
|
||||||
ready := TRUE;
|
ready := TRUE;
|
||||||
|
|
|
@ -14,7 +14,7 @@ IMPLEMENTATION MODULE Semaphores [1];
|
||||||
*)
|
*)
|
||||||
|
|
||||||
FROM SYSTEM IMPORT ADDRESS, NEWPROCESS, TRANSFER;
|
FROM SYSTEM IMPORT ADDRESS, NEWPROCESS, TRANSFER;
|
||||||
FROM Storage IMPORT ALLOCATE;
|
FROM Storage IMPORT Allocate;
|
||||||
FROM random IMPORT Uniform;
|
FROM random IMPORT Uniform;
|
||||||
FROM Traps IMPORT Message;
|
FROM Traps IMPORT Message;
|
||||||
|
|
||||||
|
@ -37,8 +37,8 @@ IMPLEMENTATION MODULE Semaphores [1];
|
||||||
wsp: ADDRESS;
|
wsp: ADDRESS;
|
||||||
BEGIN
|
BEGIN
|
||||||
s0 := cp;
|
s0 := cp;
|
||||||
ALLOCATE(wsp, n);
|
Allocate(wsp, n);
|
||||||
ALLOCATE(cp, SIZE(Process));
|
Allocate(cp, SIZE(Process));
|
||||||
WITH cp^ DO
|
WITH cp^ DO
|
||||||
next := s0^.next;
|
next := s0^.next;
|
||||||
s0^.next := cp;
|
s0^.next := cp;
|
||||||
|
@ -67,7 +67,7 @@ IMPLEMENTATION MODULE Semaphores [1];
|
||||||
PROCEDURE NewSema(n: CARDINAL): Sema;
|
PROCEDURE NewSema(n: CARDINAL): Sema;
|
||||||
VAR s: Sema;
|
VAR s: Sema;
|
||||||
BEGIN
|
BEGIN
|
||||||
ALLOCATE(s, SIZE(Semaphore));
|
Allocate(s, SIZE(Semaphore));
|
||||||
s^.level := n;
|
s^.level := n;
|
||||||
RETURN s;
|
RETURN s;
|
||||||
END NewSema;
|
END NewSema;
|
||||||
|
@ -110,7 +110,7 @@ IMPLEMENTATION MODULE Semaphores [1];
|
||||||
RETURN FALSE;
|
RETURN FALSE;
|
||||||
END Runnable;
|
END Runnable;
|
||||||
BEGIN
|
BEGIN
|
||||||
ALLOCATE(cp, SIZE(Process));
|
Allocate(cp, SIZE(Process));
|
||||||
WITH cp^ DO
|
WITH cp^ DO
|
||||||
next := cp;
|
next := cp;
|
||||||
waiting := NIL;
|
waiting := NIL;
|
||||||
|
|
|
@ -44,7 +44,7 @@ IMPLEMENTATION MODULE Streams;
|
||||||
IF NOT Storage.Available(SIZE(IOB)) THEN
|
IF NOT Storage.Available(SIZE(IOB)) THEN
|
||||||
RETURN;
|
RETURN;
|
||||||
END;
|
END;
|
||||||
Storage.ALLOCATE(stream,SIZE(IOB));
|
Storage.Allocate(stream,SIZE(IOB));
|
||||||
stream^.next := head;
|
stream^.next := head;
|
||||||
head := stream;
|
head := stream;
|
||||||
END;
|
END;
|
||||||
|
|
Loading…
Reference in a new issue