BEGIN
inputStream: IO.STREAM;
errorCount: INT ← 0;
warningCount: INT ← 0;
parseTree: RussellInterp.ICExp;
initialEnvironment: RussellInterp.RTTuple;
resultOfExecution: RussellInterp.RTValue;
errMsgProc: RussellInterp.ErrMsgProc
[errPos: INT, errMsg: Rope.ROPE, severe: BOOL ← TRUE]
=
BEGIN
severityChar: CHAR;
ProcessExtras.CheckForAbort[];
IF severe
THEN { severityChar ← 'E; errorCount ← errorCount + 1 }
ELSE { severityChar ← 'W; warningCount ← warningCount + 1 };
cmd.out.PutF[ "%g %g: %g\n", IO.char[severityChar], IO.int[errPos], IO.rope[msg]];
END ; -- errMsgProc
IF (argv.argc > 2)
THEN
{ msg ← usageMsg; GOTO FailCmd } ;
cmd.out.PutF[ "Compiling %g:\n", IO.rope[argv[1]] ];
ProcessExtras.CheckForAbort[];
IF argv.argc = 1
THEN inputStream ← cmd.in
ELSE inputStream ←
FS.StreamOpen[ fileName~argv[1]
! FS.Error => { msg ← "Cannot open source file.\n"; GOTO FailCmd }];
parseTree ← RussellInterp.RussellParse[ source~inputStream, errMsgProc~errMsgProc];
cmd.out.PutF[ "%g errors, %g warnings.\n", IO.int[errorCount], IO.int[warningCount] ];
IF errorCount > 0
THEN
{ msg ← "ERRORS in source.\n"; GOTO ExitCmd };
cmd.out.PutF[ "Beginning execution:\n"];
ProcessExtras.CheckForAbort[];
initialEnvironment ← RussellInterp.RussellMkInitEnv[ in~cmd.in, out~cmd.out];
ProcessExtras.CheckForAbort[];
resultOfExecution ← RussellInterp.RussellEval[ env~initialEnvironment, ip~parseTree];
TRUSTED
BEGIN
resultTV: AMTypes.
TV ←
AMBridge.TVForReferent[ ref~resultOfExecution];
cmd.out.PutF[ "\nResult of execution:\n"];
PrintTV.Print[ tv~resultTV, put~cmd.out, depth~10, verbose~TRUE ];
cmd.out.PutF[ "\n\n"];
END ;
{ msg ← "Execution done.\n"; GOTO ExitCmd }
END ;