DIRECTORY JaM USING [PopInt, PopRope, PushBool, PushInt, PushRope, ROPE, State, Error, Pop, Any], JaMPrimitives USING [], IO USING [STREAM, ROS, RopeFromROS, Put1, int, real], Rope USING [Concat, Equal, Fetch, Find, Length, Substr]; JaMRopeImpl: CEDAR PROGRAM IMPORTS JaM, Rope, IO EXPORTS JaMPrimitives = BEGIN OPEN JaM; ApplyConcat: PUBLIC PROC[self: State] = { b: ROPE = PopRope[self]; a: ROPE = PopRope[self]; PushRope[self, Rope.Concat[a, b]]; }; ApplySubstr: PUBLIC PROC[self: State] = { len: INT = PopInt[self]; start: INT = PopInt[self]; rope: ROPE = PopRope[self]; PushRope[self, rope.Substr[start, len]]; }; ApplySGet: PUBLIC PROC[self: State] = { i: INT = PopInt[self]; rope: ROPE = PopRope[self]; c: CHAR = rope.Fetch[i]; PushInt[self, LOOPHOLE[c, [0..256)]]; }; ApplySearch: PUBLIC PROC[self: State] = { s: ROPE = PopRope[self]; t: ROPE = PopRope[self]; slen: INT = s.Length[]; i: INT = t.Find[s]; IF i>=0 THEN { PushRope[self, t.Substr[i+slen]]; -- part of t following match PushRope[self, s]; -- part of t matching s PushRope[self, t.Substr[0, i]]; -- part of t preceding match PushBool[self, TRUE]; } ELSE { PushRope[self, t]; -- no match, just push t PushBool[self, FALSE]; }; }; ApplyASearch: PUBLIC PROC[self: State] = { s: ROPE = PopRope[self]; t: ROPE = PopRope[self]; slen: INT = s.Length[]; IF s.Equal[t.Substr[0, slen]] THEN { PushRope[self, t.Substr[slen]]; -- part of t following match PushRope[self, s]; -- part of t matching s PushBool[self, TRUE]; } ELSE { PushRope[self, t]; -- no match, just push t PushBool[self, FALSE]; }; }; ApplyConvertToString: PUBLIC PROC[self: State] = { x: JaM.Any = JaM.Pop[self]; stream: IO.STREAM ¬ IO.ROS[]; rope: ROPE; WITH x SELECT FROM x: REF INT => stream.Put1[IO.int[x­]]; x: REF REAL => stream.Put1[IO.real[x­]]; ENDCASE => JaM.Error[InvalidArgs]; rope ¬ IO.RopeFromROS[stream, TRUE]; JaM.PushRope[self,rope]; }; END. Π JaMRopeImpl.mesa Copyright Σ 1985, 1992 by Xerox Corporation. All rights reserved. Original version John Warnock, January, 1979 Bill Paxton, February 6, 1981 9:31 AM McGregor, September 10, 1982 11:22 am Stone, February 14, 1985 6:48:04 pm PST Doug Wyatt, March 18, 1985 3:29:34 pm PST Bier, September 15, 1992 4:26 pm PDT ConvertToRadixString: PUBLIC PROC[self: State] = { rdx: INT _ PopInt[self]; ob: Object _ Pop[self]; string: ROPE _ novalue; s: STRING _ [50]; IF rdx NOT IN[2..36] THEN ERROR Error[rangechk]; WITH ob:ob SELECT FROM integer => { AppendInteger[s,ob.ivalue,rdx]; string _ MakeString[s] }; real => { AppendInteger[s,LOOPHOLE[ob.rvalue],rdx]; string _ MakeString[s] }; ENDCASE; Push[self,string]; }; ConvertOctalString: PUBLIC PROC[self: State] = { string: ROPE _ PopRope[self]; s: STRING _ [50]; i: LONG INTEGER; IF string.length>s.maxlength THEN ERROR Error[rangechk]; VM.GetText[string,s]; i _ S.StringToLongNumber[s,8]; PushInteger[self,i]; }; Κ–"cedarcode" style•NewlineDelimiter ™codešœ™Kšœ Οeœ6™BKšœ,™,Kšœ&™&Kšœ%™%K™'Kšœ)™)K™$—K˜šΟk ˜ Kšœžœ0žœ˜WKšœžœ˜Kšžœžœžœžœ ˜5Kšœžœ.˜8—K˜KšΠbl œžœž˜Kšžœ ž˜Kšžœ˜Kšœžœžœ˜K˜šΟn œžœžœ˜)Kšœžœ˜Kšœžœ˜K˜"K˜K˜—š  œžœžœ˜)Kšœžœ˜Kšœžœ˜Kšœžœ˜K˜(K˜K˜—š  œžœžœ˜'Kšœžœ˜Kšœžœ˜Kšœžœ˜Kšœžœ˜%K˜K˜—š  œžœžœ˜)Kšœžœ˜Kšœžœ˜Kšœžœ˜Kšœžœ ˜šžœžœ˜Kšœ"Οc˜>Kšœ‘˜*Kšœ ‘˜