-
Notifications
You must be signed in to change notification settings - Fork 1
/
Stack.oz
40 lines (33 loc) · 958 Bytes
/
Stack.oz
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
MultiSemanticStack = {NewCell nil}
SuspendCounter = {NewCell 0}
%for multiStack
proc {AddStack StmtEnvPair}
MultiSemanticStack := [StmtEnvPair] | @MultiSemanticStack
end
proc {DeleteSemanticStack}
MultiSemanticStack := @MultiSemanticStack.2
end
proc {SuspendCurrentThread}
MultiSemanticStack := {Append @MultiSemanticStack.2 [@MultiSemanticStack.1]}
{IncreaseSuspendCounter}
if @SuspendCounter == {Length @MultiSemanticStack} then raise error('deadlock') end else skip end
end
proc {ResetSuspendCounter}
SuspendCounter := 0
end
proc {IncreaseSuspendCounter}
SuspendCounter := @SuspendCounter + 1
end
proc {Push StmtEnvPair}
MultiSemanticStack := (StmtEnvPair|@MultiSemanticStack.1) | @MultiSemanticStack.2
end
fun {Pop}
case @MultiSemanticStack.1
of nil then
{DeleteSemanticStack}
nil
[] StmtEnvPair | RemainingStack then
MultiSemanticStack := RemainingStack | @MultiSemanticStack.2
StmtEnvPair
end
end