Value
Value: TYPE ~ REF ValueRep;
ValueRep:
PUBLIC
TYPE ~
RECORD [
typeIndex: TypeIndex,
variant:
SELECT kind: *
FROM
var => [],
simple => [ordinalValue: OrdinalValue],
structure => [valueList: LIST OF Value]
ENDCASE
];
SimpleValue: TYPE ~ REF simple ValueRep;
StructureValue: TYPE ~ REF structure ValueRep;
VarValue: TYPE ~ REF var ValueRep;
BuildSimpleValue:
PUBLIC
PROC [typeIndex: TypeIndex, ordinalValue: OrdinalValue]
RETURNS [Value] ~ {
RETURN [NEW[ValueRep ← [typeIndex, simple[ordinalValue]] ]];
};
BuildVarValue:
PUBLIC
PROC [typeIndex: TypeIndex]
RETURNS [Value] ~ {
RETURN [NEW[ValueRep ← [typeIndex, var[]] ]];
};
IsSimpleValue:
PUBLIC
PROC [value: Value]
RETURNS [
BOOLEAN] ~ {
RETURN [( value.kind = simple )];
};
IsVarValue:
PUBLIC
PROC [value: Value]
RETURNS [
BOOLEAN] ~ {
RETURN [( value.kind = var )];
};
PrintSimpleValue:
PROC [value: SimpleValue, s:
STREAM] ~ {
PutF[s, "simple["];
[] ← PrintOrdinalValue[value.ordinalValue, s];
PutF[s, "]"];
};
PrintStructureValue:
PROC [value: StructureValue, s:
STREAM] ~ {
valueList: LIST OF Value ← value.valueList;
PutF[s, "structure["];
FOR valueList ← value.valueList, valueList.rest
WHILE ( valueList #
NIL )
DO
IF ( valueList # value.valueList ) THEN PutF[s, ", "];
PrintValue[valueList.first, s];
ENDLOOP;
PutF[s, "]"];
};
PrintValue:
PUBLIC
PROC [value: Value, s:
STREAM] ~ {
PutF[s, "[type: "];
[] ← PrintTypeIndex[value.typeIndex, s];
PutF[s, " data: "];
WITH value
SELECT
FROM
value: SimpleValue => PrintSimpleValue[value, s];
value: StructureValue => PrintStructureValue[value, s];
value: VarValue => PrintVarValue[value, s];
ENDCASE => ERROR;
PutF[s, "]"];
};
PrintVarValue:
PROC [value: VarValue, s:
STREAM] ~ {
PutF[s, "var"];
};
ValueGetOrdinal:
PUBLIC
PROC [value: Value]
RETURNS [OrdinalValue] ~ {
WITH value
SELECT
FROM
value: SimpleValue => RETURN [value.ordinalValue];
ENDCASE => ERROR;
};
ValueGetType:
PUBLIC
PROC [value: Value]
RETURNS [TypeIndex] ~ {
RETURN [value.typeIndex];
};
}...