Heap.dcl 543 Bytes
Newer Older
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
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
definition module Heap

import StdEnv

:: Heap v = {heap::!.HeapN v}
:: HeapN v
:: Ptr v = {pointer::!.(PtrN v)};
:: PtrN v = Ptr !v !(HeapN v);

newHeap		:: .Heap v

nilPtr		:: Ptr v

isNilPtr 	:: !(Ptr v) -> Bool

newPtr		:: !v !*(Heap v) -> (!.Ptr v,!.Heap v)

readPtr		:: !(Ptr v) !*(Heap v) -> (!v,!.Heap v)

writePtr	:: !(Ptr v) !v !*(Heap v) -> .Heap v

sreadPtr	:: !(Ptr v) !(Heap v) -> v

ptrToInt 	:: !(Ptr w) -> Int

(<:=) infixl 
(<:=) heap ptr_and_val :== writePtr ptr val heap 
where
	(ptr, val) = ptr_and_val

instance == Ptr a