An RTVal.T
represents a JunoValue.T
. RTVals
are used in the Juno
machine while it is running. The procedure Dispose
reclaims the space
for all RTVals.
INTERFACEInvariant: TheRTVal ; IMPORT JunoValue; TYPE T = ROOT BRANDED "RTVal" OBJECT END; TYPE Real = JunoValue.Real; TYPE Null = T BRANDED "Null" OBJECT END; Number <: NumberPublic; NumberPublic = T OBJECT val: Real END; Text <: TextPublic; TextPublic = T OBJECT val: TEXT END; Pair <: PairPublic; PairPublic = T OBJECT car, cdr: T END;
val
field of a Text
and the car
and cdr
fields of a
Pair
are required to be non-NIL. For Juno NIL, use the global variable
nil
:
VAR (* READONLY *) nil: Null; PROCEDURE FromReal(r: Real): Number;
Returns a newNumber
with valuer
.
PROCEDURE FromInt(i: INTEGER): Number;
Returns a newNumber
with valueFLOAT(i)
.
PROCEDURE FromText(txt: TEXT): Text;
Returns a newText
with valuetxt
. Requirestxt # NIL
.
PROCEDURE FromPair(car, cdr: T): Pair;
Returns a newPair
with elementscar
andcdr
. Requires bothcar
andcdr
to be non-NIL.
PROCEDURE FromJV(jv: JunoValue.T): T;
Returns the run-time value equivalent tojv
. Ifjv = NIL
, returnsNIL
. Ifjv
has typeNull
, returnsJunoValue.Nil
.
PROCEDURE ToJV(v: T): JunoValue.T;
Returns theJunoValue.T
equivalent to the run-time valuev
. Ifv = NIL
, returnsNIL
. Ifv
has typeJunoValue.Null
, returnsnil
.
PROCEDURE Equal(v, w: T): BOOLEAN;
Return TRUE iff v and w are equal.
PROCEDURE Mark();
Mark allT
's allocated prior to this call so they will not be collected on the next call toDispose
.
PROCEDURE Dispose();
Invalidate and reclaim allT
s allocated since the last call toMark
, and undo the effect of thatMark
. If there is no previousMark
, invalidate and reclaim allT
's allocated since the last call toDispose
. This never invalidatesnil
.
END RTVal.