MispTime.Mesa
Spreitzer, July 30, 1985 2:13:42 pm PDT
DIRECTORY BasicTime, IO, Misp, Rope, Tempus;
MispTime: CEDAR PROGRAM
IMPORTS BasicTime, IO, Misp, Tempus =
BEGIN
LORA: TYPE = LIST OF REF ANY;
ROPE: TYPE = Rope.ROPE;
RefTime: TYPE = Misp.RefTime;
NewTime: PROC [time: BasicTime.GMT] RETURNS [rt: RefTime] =
{rt ← NEW [Misp.TimeRec ← [time]]};
EvalTimeDiff: PROC [args: LORA, environment: Misp.Environment, data: REF ANYNIL, stack: Misp.Stack] RETURNS [cooked: REF ANY] --Misp.EvalProc-- = {
rt1: RefTime ← NARROW[args.first];
rt2: RefTime ← NARROW[args.rest.first];
cooked ← NEW [INT ← BasicTime.Period[from: rt1.t, to: rt2.t]]};
EvalTimeUpdate: PROC [args: LORA, environment: Misp.Environment, data: REF ANYNIL, stack: Misp.Stack] RETURNS [cooked: REF ANY] --Misp.EvalProc-- = {
rt1: RefTime ← NARROW[args.first];
i: INT ← Misp.ToInt[args.rest.first, environment, stack];
cooked ← NewTime[BasicTime.Update[rt1.t, i]]};
EvalTimeNow: PROC [args: LORA, environment: Misp.Environment, data: REF ANYNIL, stack: Misp.Stack] RETURNS [cooked: REF ANY] --Misp.EvalProc-- = {
cooked ← NewTime[BasicTime.Now[]]};
EvalTimeFmt: PROC [args: LORA, environment: Misp.Environment, data: REF ANYNIL, stack: Misp.Stack] RETURNS [cooked: REF ANY] --Misp.EvalProc-- = {
rt: RefTime ← NARROW[args.first];
r: ROPE;
r ← IO.PutFR["%g", IO.time[rt.t] !BasicTime.OutOfRange => {r ← "?time out of range?"; CONTINUE}];
cooked ← r};
EvalTimeParse: PROC [args: LORA, environment: Misp.Environment, data: REF ANYNIL, stack: Misp.Stack] RETURNS [cooked: REF ANY] --Misp.EvalProc-- = {
rope: ROPENARROW[args.first];
cooked ← NewTime[Tempus.Parse[rope].time]};
DefineRopeStuff: PROC [env: Misp.Environment] = {
Misp.Defun[env, $timeDiff, EvalTimeDiff];
Misp.Defun[env, $timeUpdate, EvalTimeUpdate];
Misp.Defun[env, $timeNow, EvalTimeNow];
Misp.Defun[env, $timeFmt, EvalTimeFmt];
Misp.Defun[env, $timeParse, EvalTimeParse];
};
Start: PROC = {
Misp.RegisterPrimitiveDefiner[DefineRopeStuff];
};
Start[];
END.