DIRECTORY BasicTime USING [GMT, Period], FS USING [Error, ExpandName, FileInfo, StreamOpen], IO USING [bool, char, Close, GetBool, GetInt, GetLineRope, GetReal, int, Put, PutF, PutRope, real, rope, STREAM], RobotDefs USING [Robot, RobotRec], RobotIO, RobotTParser USING [AssembleRobot], Rope USING [Cat, Concat, ROPE, Substr]; RobotIOImpl: CEDAR PROGRAM IMPORTS BasicTime, FS, IO, RobotTParser, Rope EXPORTS RobotIO ~ { OPEN RobotIO; WriteRobot: PUBLIC PROC [r: Rope.ROPE, robot: RobotDefs.Robot] ~ { OPEN IO; s: IO.STREAM _ FS.StreamOpen[Rope.Concat[r,".RobotC"], create]; IO.PutF[s, "%g\n", IO.rope[robot.creator]]; --Creator's name IO.Put[s,real[robot.version], char['\n]]; --Assembler Version FOR loc: CARDINAL IN [0..256) DO --Code IO.Put[s,int[robot.code[loc]], char[' ]]; ENDLOOP; FOR row: CARDINAL IN [0..16) DO --Picture FOR col: CARDINAL IN [0..16) DO IO.Put[s,bool[robot.pic[row][col]], char[' ]]; ENDLOOP; ENDLOOP; IO.Close[s]; }; ReadRobot: PUBLIC PROC [r: ROPE, wDir: ROPE _ NIL] RETURNS [robot: RobotDefs.Robot] ~ { OPEN IO; s: STREAM _ FS.StreamOpen[fileName: Rope.Concat[r,".RobotC"], accessOptions: read, wDir: wDir]; robot _ NEW[RobotDefs.RobotRec]; robot.creator _ GetLineRope[s]; --Creator's name robot.version _ GetReal[s]; --Assembler Version FOR loc: CARDINAL IN [0..256) DO --Code robot.code[loc] _ GetInt[s]; ENDLOOP; FOR row: CARDINAL IN [0..16) DO --Picture FOR col: CARDINAL IN [0..16) DO robot.pic[row][col] _ GetBool[s]; ENDLOOP; ENDLOOP; Close[s]; }; AssembleRobot: PUBLIC PROC [r: ROPE, log: IO.STREAM, onlyIfNew: BOOL _ TRUE, wDir: ROPE _ NIL] RETURNS [success: BOOLEAN] ~ { name: ROPE; createTime: BasicTime.GMT; robot: RobotDefs.Robot; [fullFName: name, created: createTime] _ FS.FileInfo[name: Rope.Cat[r, ".robot"], wDir: wDir ! FS.Error => {GOTO Fail}]; IF onlyIfNew AND BasicTime.Period[to: FS.FileInfo[name: Rope.Cat[r, ".robotc"], wDir: wDir ! FS.Error => CONTINUE].created, from: createTime] > 0 THEN RETURN [TRUE]; --I.e. we don't need to assemble IO.PutRope[log, Rope.Cat["Assembling ", name, ".\n"]]; [robot, success, ] _ RobotTParser.AssembleRobot[name, log]; IF success THEN { WriteRobot[Rope.Substr[base: name, len: FS.ExpandName[name].cp.ext.start-1], robot]; } ELSE { IO.PutRope[log, " Assembly failed.\n"]; }; EXITS Fail => { success _ TRUE; [] _ FS.FileInfo[name: Rope.Cat[r, ".robotc"], wDir: wDir ! FS.Error => { IO.PutRope[log, Rope.Cat[r, " not found.\n"]]; success _ FALSE; CONTINUE }]; }; }; }. ΖRobotIOImpl.mesa Created Saturday, June 9, 1984 4:24 pm PDT Last edited by Eric Nickell, July 6, 1985 1:29:56 pm PDT This interface provide the tools to read and write compiled robot images to and from the disk. IO.Put[s,time[robot.timeOfSource], char['\n]]; --Time the source version was last edited robot.timeOfSource _ GetTime[s]; --Time the source version was last edited Here, we need to attempt assembly Complain if no .robotC file either Κ ˜šœ™Jšœ*™*J™8J™^J™—šΟk ˜ Icodešœ œœ ˜Jšœœ+˜3Jšœœaœ˜qJšœ œ˜"J˜Kšœ œ˜#Jšœœœ ˜'J˜—šœ œ˜Jšœ œœ˜-Jšœ˜J˜Jšœ ˜ J˜šΟn œœœ œ˜BKšœœ˜Jšœœœœ.˜?KšœœΟc˜[s1: ROPE, pos1: INT _ 0, s2: ROPE, case: BOOL _ TRUE]šœ(œ*˜TKšœ˜—šœ˜Kšœ'˜)Kšœ˜—š˜šœ ˜ K™"Kšœ œ˜šœœ5œ ˜IKšœ,˜.Kšœ œ˜Kš˜Kšœ˜—Kšœ˜——K˜J˜—J˜——…— ¦Œ