RoseValuingImpl.Mesa
Spreitzer, October 25, 1985 8:11:01 pm PDT
DIRECTORY Core, IO, Rope, RoseBehavior, RoseControl, RoseValuing, RoseWireTypes;
RoseValuingImpl: CEDAR PROGRAM
IMPORTS IO, RoseControl
EXPORTS RoseValuing
=
BEGIN OPEN RoseValuing, RC: RoseControl, RWT: RoseWireTypes;
Ptr: TYPE = RC.Ptr;
RoseWire: TYPE = RC.RoseWire;
RoseWireType: TYPE = RC.RoseWireType;
NotificationRegistration: TYPE = REF NotificationRegistrationPrivate;
NotificationRegistrationPrivate: PUBLIC TYPE = RECORD [
ctlNR: RC.NotificationRegistration,
event: Event,
wire: Wire,
sim: Simulation,
format: Format,
notify: EventConsumerProc,
data: REF ANYNIL
];
GetBool: PUBLIC PROC [w: Wire, s: Simulation] RETURNS [b: BOOL] = {
rw: RoseWire = RC.LookupRoseWire[s, w];
Consume: PROC [rwt: RoseWireType, ptr: Ptr] = {
SELECT rwt FROM
RC.boolType => b ← RC.ReadBool[ptr];
RC.bitType => b ← SELECT RC.ReadSwitch[ptr].val FROM
L => FALSE,
H => TRUE,
X => ERROR,
ENDCASE => ERROR;
ENDCASE => ERROR;
};
RC.ExhibitValue[rw, Consume];
};
SetBool: PUBLIC PROC [w: Wire, s: Simulation, b: BOOL, fs: ForceScope] = {
rw: RoseWire = RC.LookupRoseWire[s, w];
Produce: PROC [rwt: RoseWireType, ptr: Ptr] = {
SELECT rwt FROM
RC.boolType => RC.WriteBool[ptr, b];
RC.bitType => RC.WriteSwitch[ptr, [s: ALL[none], val: IF b THEN H ELSE L]];
ENDCASE => ERROR;
};
RC.SetForce[rw, fs];
RC.ExhibitValue[rw, Produce];
};
GetLevel: PUBLIC PROC [w: Wire, s: Simulation] RETURNS [l: RoseBehavior.Level] = {
rw: RoseWire = RC.LookupRoseWire[s, w];
Consume: PROC [rwt: RoseWireType, ptr: Ptr] = {
SELECT rwt FROM
RC.boolType => l ← IF RC.ReadBool[ptr] THEN H ELSE L;
RC.bitType => l ← RC.ReadSwitch[ptr].val;
ENDCASE => ERROR;
};
RC.ExhibitValue[rw, Consume];
};
SetLevel: PUBLIC PROC [w: Wire, s: Simulation, l: RoseBehavior.Level, fs: ForceScope] = {
rw: RoseWire = RC.LookupRoseWire[s, w];
Produce: PROC [rwt: RoseWireType, ptr: Ptr] = {
SELECT rwt FROM
RC.boolType => RC.WriteBool[
ptr,
SELECT l FROM
L => FALSE,
H => TRUE,
X => ERROR,
ENDCASE => ERROR
];
RC.bitType => RC.WriteSwitch[ptr, [s: ALL[none], val: l]];
ENDCASE => ERROR;
};
RC.SetForce[rw, fs];
RC.ExhibitValue[rw, Produce];
};
formatName: ARRAY Format OF ROPE = [
idiosyncratic: "idiosyncratic",
num2: "2",
num4: "4",
num8: "8",
num16: "16"
];
GetRope: PUBLIC PROC [w: Wire, s: Simulation, f: Format] RETURNS [r: ROPE] = {
rw: RoseWire = RC.LookupRoseWire[s, w];
Consume: PROC [rwt: RoseWireType, ptr: Ptr] = {
fmt: RWT.Format = rwt.class.super.GetFormat[rwt, formatName[f]];
r ← fmt.FormatValue[rwt, fmt, ptr];
};
RC.ExhibitValue[rw, Consume];
};
SetRope: PUBLIC PROC [w: Wire, s: Simulation, f: Format, r: ROPE, fs: ForceScope] RETURNS [success: BOOL] = {
rw: RoseWire = RC.LookupRoseWire[s, w];
Produce: PROC [rwt: RoseWireType, ptr: Ptr] = {
fmt: RWT.Format = rwt.class.super.GetFormat[rwt, formatName[f]];
success ← fmt.ParseValue[rwt, fmt, ptr, IO.RIS[r]];
};
RC.SetForce[rw, fs];
RC.ExhibitValue[rw, Produce];
};
AddNotification
: PUBLIC
PROC [
event: Event,
wire: Wire,
sim: Simulation,
format: Format,
notify: EventConsumerProc,
data: REF ANYNIL]
RETURNS [registration: NotificationRegistration]
= {
rw: RoseWire = RC.LookupRoseWire[sim, wire];
registration ← NEW [NotificationRegistrationPrivate ← [
ctlNR: NIL,
event: event,
wire: wire,
sim: sim,
format: format,
notify: notify,
data: data
]];
registration.ctlNR ← RC.AddNotification[
event: event,
on: rw,
notify: Notify,
data: registration
];
};
Notify
: PROC [
event: Event,
on: RoseWire,
type: RoseWireType,
ptr: Ptr,
Valid for {NewQ, NewUD, NewVal}, but not {Perturbed, Found}.
data: REF ANY]
= {
nr: NotificationRegistration = NARROW[data];
r: ROPENIL;
SELECT event FROM
NewQ, NewUD, NewVal => {
fmt: RWT.Format = type.class.super.GetFormat[type, formatName[nr.format]];
r ← fmt.FormatValue[type, fmt, ptr];
};
Perturbed, Found => NULL;
ENDCASE => ERROR;
nr.notify[event, nr.wire, nr.sim, r, nr.data];
};
RemoveNotification: PUBLIC PROC [registration: NotificationRegistration] = {
nr: NotificationRegistration = NARROW[registration];
RC.RemoveNotification[nr.ctlNR];
};
END.