<> <> <> <> <> <> <> DIRECTORY JaM USING [PopInt, PopRope, PushBool, PushInt, PushRope, ROPE, State, Error, Pop, Any], JaMPrimitives USING [], IO USING [STREAM, ROS, RopeFromROS, Put, 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.Put[IO.int[x^]]; x: REF REAL => stream.Put[IO.real[x^]]; ENDCASE => JaM.Error[InvalidArgs]; rope _ IO.RopeFromROS[stream, TRUE]; JaM.PushRope[self,rope]; }; <> <> <> <> <> <> <> < { AppendInteger[s,ob.ivalue,rdx]; string _ MakeString[s] };>> < { AppendInteger[s,LOOPHOLE[ob.rvalue],rdx]; string _ MakeString[s] };>> <> <> <<};>> <<>> <> <> <> <> <s.maxlength THEN ERROR Error[rangechk];>> <> <> <<};>> <<>> END.