[M3devel] small set comparisons understood, now just to understand the front end code..
Jay
jayk123 at hotmail.com
Mon Apr 14 16:51:37 CEST 2008
currently set <,>,<=,>= are implemented merely as
integer <,>,<=,>=
This is wrong.
I believe it should be:
a < b => (a & b) == a
a <= b => (a & b) == a (same as <=)
a > b => (a & b) == b
a >= b => (a & b) == b (same as >)
The bug is in the frontend.
m3-sys\m3front\src\misc\CG.m3.
The code should be /something/ like:
PROCEDURE Set_compare (s: Size; op: Cmp) =
VAR tmp: Val;
swap := FALSE;
BEGIN
(* a op b => BOOLEAN *)
IF Force_pair (commute := TRUE) THEN
op := M3CG.SwappedCompare [op];
END;
IF (s <= Target.Integer.size) THEN
IF (op = Cmp.EQ) OR (op = Cmp.NE) THEN
cg.compare (Target.Word.cg_type, Target.Integer.cg_type, op);
ELSE
(* set a is less than or equal to set b, if all of set a's members are in set b. *)
IF (op = Cmp.LT) OR (op = Cmp.LE) THEN
swap := TRUE;
Swap ();
END;
tmp := Pop ();
Push (tmp);
IF swap THEN
Swap ();
END;
cg.and (Target.Integer.cg_type);
Push (tmp);
SimpleIndirectLoad (tmp^, Target.Word.cg_type);
EVAL Force_pair (commute := TRUE);
cg.compare (Target.Word.cg_type, Target.Integer.cg_type, Cmp.EQ);
SPop (1, "Set_compare");
Free (tmp);
END;
ELSE
cg.set_compare (AsBytes (s), op, Target.Integer.cg_type);
END;
SPop (2, "Set_compare");
SPush (Type.Int32);
END Set_compare;
though this doesn't quite drive all the machinery correctly, since it yields assertion failures in the compiler due to an unbalanced software stack.
upgrade works, but the test case (p155) fails assertions in the integrated backend.
I'd love to figure this out but have to do other stuff for now.
Anyone (if there is anyone) familiar with what all is being pushed and popped around here should be able to figure it out easily from this mail.
Otherwise I'll stare at more later.
ps: "small" sets should probably be anything up to the number of bits in longint, rather than int or pointer, since that is probably efficient enough at the next level down. This is tangential.
- Jay
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20080414/3d4e8296/attachment-0001.html>
More information about the M3devel
mailing list