-- JaMStart.mesa
-- Written by John Warnock, Feb., 1979.
-- Last changed by Doug Wyatt, January 9, 1981 3:36 PM

DIRECTORY
JaMStartDefs,
JaMMasterDefs USING [Frame, Object],
JaMControlDefs USING [GetCurrentFrame, NotifyStringObject],
JaMExecDefs USING [Execute],
JaMInterruptDefs USING [InitJaMBreak],
JaMIODefs USING [MakeIntoEditedStream],
JaMStackDefs USING [Push],
AltoFileDefs USING [CFA],
ImageDefs USING [CleanupReason, CleanupItem, CleanupMask,
AddCleanupProcedure],
MiscDefs USING [CommandLineCFA],
SegmentDefs USING [FindFile],
StreamDefs USING [StreamHandle, CreateByteStream, NewByteStream,
Read, GetDefaultKey, JumpToFA];

JaMStart: PROGRAM
IMPORTS JaMControlDefs,JaMExecDefs,JaMInterruptDefs,JaMIODefs,
JaMStackDefs,ImageDefs,MiscDefs,SegmentDefs,StreamDefs
EXPORTS JaMStartDefs =
BEGIN 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] =
BEGIN RETURN[jamstreamhandle] END;

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];
};
JaMStackDefs.Push[[nolit,StreamType[s]],frame.execstk];
JaMExecDefs.Execute[];
};

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

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

-- do command line
DoCommandLine[];

-- The Main Loop
DO
JaMStackDefs.Push[stream,frame.execstk];
JaMStackDefs.Push[prmpt,frame.execstk];
JaMExecDefs.Execute[];
ENDLOOP;
END;

StartStart: PROCEDURE =
BEGIN OPEN JaMControlDefs;
NotifyStringObject[@prmpt, ".prompt"L];
NotifyStringObject[@strt, ".start"L];
END;

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

-- Initialization
ImageDefs.AddCleanupProcedure[@item];
jamstreamhandle←JaMIODefs.MakeIntoEditedStream[StreamDefs.GetDefaultKey[]];
stream←[nolit,StreamType[jamstreamhandle]];
JaMInterruptDefs.InitJaMBreak[];
StartStart;

END.

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