ConvertAsciiJaM.mesa
-- Written by Michael Plass on October 14, 1982 2:28 pm
-- Last edit by Michael Plass on October 14, 1982 2:28 pm
-- Maureen Stone May 15, 1984 3:42:57 pm PDT
DIRECTORY
FitJaM USING [InitProc, RegisterInit],
JaM USING [State, PopRope, PushRope, PushInt, PopInt, Register],
Rope;
ConvertAsciiJaM: CEDAR PROGRAM
IMPORTS JaM, Rope, FitJaM
= BEGIN
ROPE: TYPE = Rope.ROPE;
State: TYPE = JaM.State;
PopRope: PROCEDURE [f: State] RETURNS [rope: ROPE] = {RETURN[JaM.PopRope[f]]};
PushRope: PROCEDURE [f: State, rope: ROPE] = {JaM.PushRope[f,rope]};
ConvertAcsiiCharToInteger: PROCEDURE [f: State] = {
char: CHAR ← PopRope[f].Fetch[0];
byte: [0..256) ← char - 000C;
JaM.PushInt[f, byte];
};
ConvertIntegerToAcsiiChar: PROCEDURE [f: State] = {
byte: [0..256) ← JaM.PopInt[f];
PushRope[f, Rope.FromChar[000C + byte]];
};
ConvertIntegerToAcsiiString: PROCEDURE [f: State] = {
byte: [0..256) ← JaM.PopInt[f];
b0: CHAR ← '0 + byte MOD 8;
b1: CHAR ← '0 + byte/8 MOD 8;
b2: CHAR ← '0 + byte/64 MOD 8;
IF 000C + byte IN (' ..'}] AND 000C + byte # '\" AND 000C + byte # '\\ THEN PushRope[f, Rope.FromChar[000C + byte]]
ELSE PushRope[f, Rope.Cat["\\", Rope.FromChar[b2], Rope.FromChar[b1], Rope.FromChar[b0]]];
};
ConvertAsciiJaMInit: FitJaM.InitProc = {
JaM.Register[state, ".cvaci", ConvertAcsiiCharToInteger];
JaM.Register[state, ".cviac", ConvertIntegerToAcsiiChar];
JaM.Register[state, ".cvias", ConvertIntegerToAcsiiString];
};
FitJaM.RegisterInit[$ConvertAsciiJaM, ConvertAsciiJaMInit];
END.