JaMRopeImpl.mesa
Last edited by:
Original version John Warnock, January, 1979
Bill Paxton, February 6, 1981 9:31 AM
McGregor, September 10, 1982 11:22 am
Doug Wyatt, August 19, 1983 2:18 pm
DIRECTORY
JaM USING [PopInt, PopRope, PushBool, PushInt, PushRope, ROPE, State],
JaMPrimitives USING [],
Rope USING [Concat, Equal, Fetch, Find, Length, Substr];
JaMRopeImpl: CEDAR PROGRAM
IMPORTS JaM, Rope
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];
};
};
ConvertToString: PUBLIC PROC[self: State] = {
ob: Object ← Pop[self];
string: ROPE ← novalue;
s: STRING ← [50];
WITH ob:ob SELECT FROM
integer => { AppendInteger[s,ob.ivalue]; string ← MakeString[s] };
real => { AppendReal[s,ob.rvalue]; string ← MakeString[s] };
boolean => string ← (IF ob.bvalue THEN true ELSE false);
string => string ← ob;
name => string ← SCopy[NameToString[ob]]; -- make a copy!
ENDCASE;
Push[self,string];
};
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];
};
END.