-- JaMStart.mesa
-- Written by John Warnock, Feb., 1979.
-- Last changed by Doug Wyatt, April 9, 1981 10:52 AM
-- Last changed by Doug Brotz, June 5, 1981 2:19 PM

DIRECTORY
JaMStartDefs,
JaMMasterDefs USING [Frame, Object],
JaMControlDefs USING [GetCurrentFrame, QuitError],
JaMExecDefs USING [Execute],
JaMInterruptDefs USING [InitJaMBreak],
JaMIODefs USING [MakeIntoEditedStream],
JaMLiteralDefs USING [MakeStringObject],
JaMStackDefs USING [Push],
AltoFileDefs USING [CFA],
FrameDefs USING [IsBound],
ImageDefs USING [CleanupReason, CleanupItem, CleanupMask,
AddCleanupProcedure],
IODefs USING [GetInputStream],
LaurelExecDefs USING [GetUserCredentials],
MiscDefs USING [CommandLineCFA],
SegmentDefs USING [FindFile],
StreamDefs USING [StreamHandle, CreateByteStream, NewByteStream,
Read, JumpToFA];

JaMStart: PROGRAM
IMPORTS JaMControlDefs, JaMExecDefs, JaMInterruptDefs, JaMIODefs,
JaMLiteralDefs, JaMStackDefs,
FrameDefs, ImageDefs, IODefs, LaurelExecDefs, MiscDefs, SegmentDefs, StreamDefs
EXPORTS JaMStartDefs = {
OPEN JaMMasterDefs;

-- This is the main control program for JaM.
-- It creates an edited stream, and then transfers execution control.

jamstreamhandle: StreamDefs.StreamHandle;

stream: StreamType Object;
prmpt: StringType Object;
strt: StringType Object;

GetJaMStream: PUBLIC PROCEDURE RETURNS[StreamDefs.StreamHandle] =
{ RETURN[jamstreamhandle] };

restarted: BOOLEAN ← FALSE;

DoCommandLine: PROCEDURE = { OPEN StreamDefs;
frame: Frame ← JaMControlDefs.GetCurrentFrame[];
s: StreamHandle ← NIL;
IF restarted THEN {
s ← NewByteStream[name: "Com.cm"L, access: Read];
-- skip first token in command line
UNTIL s.endof[s] DO IF s.get[s]=’ THEN EXIT ENDLOOP;
}
ELSE {
cfa: POINTER TO AltoFileDefs.CFA ← MiscDefs.CommandLineCFA[];
s ← CreateByteStream[file: SegmentDefs.FindFile[@cfa.fp], access: Read];
JumpToFA[s, @cfa.fa];
};
IF NOT s.endof[s] THEN {
JaMStackDefs.Push[[nolit,StreamType[s]],frame.execstk];
JaMExecDefs.Execute[];
};
};

RunJaM: PUBLIC PROCEDURE = {
frame: Frame ← JaMControlDefs.GetCurrentFrame[];

-- do start macro
JaMStackDefs.Push[strt,frame.execstk];
JaMExecDefs.Execute[];

-- do command line
IF ~FrameDefs.IsBound[LaurelExecDefs.GetUserCredentials] THEN
DoCommandLine[];

-- The Main Loop
DO
JaMStackDefs.Push[stream,frame.execstk];
JaMStackDefs.Push[prmpt,frame.execstk];
JaMExecDefs.Execute[ ! JaMControlDefs.QuitError =>
{stream.SHandle.destroy[stream.SHandle]; EXIT}];
stream.SHandle.reset[stream.SHandle];
ENDLOOP;
};

NoteRestart: PROCEDURE[why: ImageDefs.CleanupReason] = { restarted ← TRUE };
item: ImageDefs.CleanupItem ← [link: NIL, proc: NoteRestart,
mask: ImageDefs.CleanupMask[Restore] + ImageDefs.CleanupMask[Restart]];

-- Initialization
IF ~FrameDefs.IsBound[LaurelExecDefs.GetUserCredentials] THEN
ImageDefs.AddCleanupProcedure[@item];
jamstreamhandle←JaMIODefs.MakeIntoEditedStream[IODefs.GetInputStream[]];
stream←[nolit,StreamType[jamstreamhandle]];
JaMInterruptDefs.InitJaMBreak[];

STOP;

{ OPEN JaMLiteralDefs;
prmpt ← MakeStringObject[".prompt"L];
strt ← MakeStringObject[".start"L];
};

}.

MN March 10, 1980 5:32 PM
added start macro, command-line input

DKW March 25, 1980 1:57 PM
no longer calls RealDefs.InitFloat

DKW March 29, 1980 11:51 AM
Initialization substantially changed. Most START code has been moved to
JaMControl, which is now JaM’s control module. Added StartStart, RunJaM.

DKW July 25, 1980 3:12 PM
changed DoCommandLine to use MiscDefs.CommandLineCFA

DKW January 9, 1981 3:23 PM
DoCommandLine doesn’t use CommandLineCFA if JaM is an image file

DKW February 10, 1981 6:42 PM
initializes after STOP

DKW April 9, 1981 10:48 AM
stream.reset at bottom of main loop
DoCommandLine tests for end of stream

DKB June 5, 1981 2:20 PM
Laurelized.