[M3devel] Strange behavior in recent CM3-compiled code...

Mika Nystrom mika at async.caltech.edu
Tue Jun 16 09:59:10 CEST 2009


This small example exhibits it!

MODULE Main;
IMPORT IO, Fmt;

PROCEDURE PutLn(what : TEXT) =
  BEGIN IO.Put(what & "\n") END PutLn;


TYPE 
  Pair = BRANDED "Pair" REF RECORD
    first, rest : REFANY;
  END;

PROCEDURE Rest(p : Pair) : REFANY = 
  BEGIN
    IF p = NIL THEN RETURN NIL ELSE RETURN p.rest END
  END Rest;

VAR 
  t := NEW(Pair, first := "first", 
                 rest  := NEW(Pair, first := "second", 
                                    rest := NIL));

BEGIN
  PutLn("t.rest # NIL? " & Fmt.Bool(t.rest#NIL));
  PutLn("ISTYPE(t.rest,Pair)? " & Fmt.Bool(ISTYPE(t.rest,Pair)));
  PutLn("Rest(t.rest) = NIL? " & Fmt.Bool(Rest(t.rest)=NIL));
  PutLn("conjunction? " & Fmt.Bool(
     (t.rest # NIL) AND (ISTYPE(t.rest,Pair)) AND (Rest(t.rest) = NIL) ));
  IF (t.rest # NIL) AND (ISTYPE(t.rest,Pair)) AND (Rest(t.rest) = NIL) THEN
    PutLn("in IF clause...")
  ELSE
    PutLn("in ELSE clause...")
  END
END Main.

Output:

(133)rover:~/testcm3/src>m3build -O
--- building in ../FreeBSD4 ---
m3build: missing ../src/m3overrides
new source -> compiling ../src/Main.m3
 -> linking prog
(134)rover:~/testcm3/src>../FreeBSD4/prog
t.rest # NIL? TRUE
ISTYPE(t.rest,Pair)? TRUE
Rest(t.rest) = NIL? TRUE
conjunction? TRUE
in IF clause...
(135)rover:~/testcm3/src>cm3 -clean
--- cleaning ../FreeBSD4 ---

(136)rover:~/testcm3/src>cm3
--- building in ../FreeBSD4 ---

new source -> compiling Main.m3
 -> linking prog
(137)rover:~/testcm3/src>../FreeBSD4/prog 
t.rest # NIL? TRUE
ISTYPE(t.rest,Pair)? TRUE
Rest(t.rest) = NIL? TRUE
conjunction? FALSE
in ELSE clause...
(138)rover:~/testcm3/src>

Jay writes:
>--_55f6c801-7d57-4602-a131-dda139b64dfd_
>Content-Type: text/plain; charset="iso-8859-1"
>Content-Transfer-Encoding: quoted-printable
>
>
>Kneejerk generic response:
>
>=20
>
>I don't know the operator precedence. Can you put in parens?
>
>Have you looked at the code?
>
>Can you mail us a small self contained repro?
>
>Can you test it on birch?
>
>  (That way -- all your files are there and easily gotten/investigated by o=
>thers.)
>
>Optimization enabled? Works without? I know=2C I shouldn't even ask this so=
>rt of thing without evidence.
>
>=20
>
> - Jay
>=20
>> To: m3devel at elegosoft.com
>> Date: Tue=2C 16 Jun 2009 00:01:18 -0700
>> From: mika at async.caltech.edu
>> CC: mika at camembert.async.caltech.edu
>> Subject: [M3devel] Strange behavior in recent CM3-compiled code...
>>=20
>>=20
>> Hello everyone=2C
>>=20
>> I'm trying to update to the latest CM3 again=2C so that I can get my
>> Mac working=2C and push my project of migrating a largish codebase
>> from PM3 to CM3 a little further.
>>=20
>> I updated CM3 today from CVS=2C on both my Mac and on a FreeBSD system=2C
>> and ... my Scheme interpreter broke. Here's what the code looks like=2C
>> with annotations:
>>=20
>> 49 Debug.Out("t.rest =3D NIL? " & Fmt.Bool(t.rest=3DNIL))=3B
>> 50 Debug.Out("ISTYPE(t.rest=2CT)? " & Fmt.Bool(ISTYPE(t.rest=2CT)))=3B
>> 51 Debug.Out("Rest(t.rest) =3D NIL? " & Fmt.Bool(Rest(t.rest)=3DNIL))=3B
>> 52
>> 53 IF t.rest # NIL AND ISTYPE(t.rest=2CT) AND Rest(t.rest) =3D NIL THEN
>> 54 Debug.Out("in IF clause...")=3B
>> 55
>> 56 IF SymEq(t.first=2C "quote") THEN special :=3D "'"
>> 57 ELSIF SymEq(t.first=2C "quasiquote") THEN special :=3D "`"
>> 58 ELSIF SymEq(t.first=2C "unquote") THEN special :=3D "=2C"
>> 59 ELSIF SymEq(t.first=2C "unquote-splicing") THEN special :=3D "=2C@"
>> 60 END
>> 61 ELSE
>> 62 Debug.Out("in ELSE clause...")
>> 63 END=3B
>>=20
>> all you need to know is that Debug.Out prints out debugging information
>> to the terminal. What I see is...
>>=20
>> t.rest =3D NIL? FALSE
>> ISTYPE(t.rest=2CT)? TRUE
>> Rest(t.rest) =3D NIL? TRUE
>> in ELSE clause...
>>=20
>> What gives!?
>>=20
>> Note this behavior occurs on both the Mac and on FreeBSD4 with a
> compiler and runtime bootstrapped today from some previous CM3.
>> My old CM3 compiler was timestamped... April 30=2C I believe=2C and the
>> code behaved properly under that one.
>>=20
>> I believe I have also tried it both with and without compiler
>> optimizations.
>>=20
>> I find it baffling that so much stuff (mentor!) can work if "AND" isn't
>> working right. This is the only if statement in many=2C many source files
>> that seems to be working wrong.
>>=20
>> Is it possible I'm missing something?? No I don't think so... here's a mo=
>re
>> explicit version:
>>=20
>> Debug.Out("t.rest # NIL? " & Fmt.Bool(t.rest#NIL))=3B
>> Debug.Out("ISTYPE(t.rest=2CT)? " & Fmt.Bool(ISTYPE(t.rest=2CT)))=3B
>> Debug.Out("Rest(t.rest) =3D NIL? " & Fmt.Bool(Rest(t.rest)=3DNIL))=3B
>> Debug.Out("conjunction? " & Fmt.Bool(
>> t.rest # NIL AND ISTYPE(t.rest=2CT) AND Rest(t.rest) =3D NIL ))=3B
>> IF t.rest # NIL AND ISTYPE(t.rest=2CT) AND Rest(t.rest) =3D NIL THEN
>> ...
>>=20
>> output is:
>>=20
>> t.rest # NIL? TRUE
>> ISTYPE(t.rest=2CT)? TRUE
>> Rest(t.rest) =3D NIL? TRUE
>> conjunction? FALSE
>> in ELSE clause...
>>=20
>> TRUE AND TRUE AND TRUE is FALSE??
>>=20
>> Note that:=20
>>=20
>> VAR q=2C w=2C e :=3D TRUE=3B
>>=20
>> Debug.Out("conjunction? " & Fmt.Bool(
>> q AND w AND e))=3B
>>=20
>> results in TRUE (as it should).
>>=20
>>=20
>> Mika
>>=20
>
>--_55f6c801-7d57-4602-a131-dda139b64dfd_
>Content-Type: text/html; charset="iso-8859-1"
>Content-Transfer-Encoding: quoted-printable
>
><html>
><head>
><style>
>.hmmessage P
>{
>margin:0px=3B
>padding:0px
>}
>body.hmmessage
>{
>font-size: 10pt=3B
>font-family:Verdana
>}
></style>
></head>
><body class=3D'hmmessage'>
>Kneejerk generic response:<BR>
>&nbsp=3B<BR>
>I don't know the operator precedence. Can you put in parens?<BR>
>Have you looked at the code?<BR>
>Can you mail us a small self contained repro?<BR>
>Can you test it on birch?<BR>
>&nbsp=3B (That way -- all your files are there and easily gotten/investigat=
>ed by others.)<BR>
>Optimization enabled? Works without? I know=2C I shouldn't even ask this so=
>rt of thing without evidence.<BR>
>&nbsp=3B<BR>
>&nbsp=3B- Jay<BR>&nbsp=3B<BR>&gt=3B To: m3devel at elegosoft.com<BR>&gt=3B Dat=
>e: Tue=2C 16 Jun 2009 00:01:18 -0700<BR>&gt=3B From: mika at async.caltech.edu=
><BR>&gt=3B CC: mika at camembert.async.caltech.edu<BR>&gt=3B Subject: [M3devel=
>] Strange behavior in recent CM3-compiled code...<BR>&gt=3B <BR>&gt=3B <BR>=
>&gt=3B Hello everyone=2C<BR>&gt=3B <BR>&gt=3B I'm trying to update to the l=
>atest CM3 again=2C so that I can get my<BR>&gt=3B Mac working=2C and push m=
>y project of migrating a largish codebase<BR>&gt=3B from PM3 to CM3 a littl=
>e further.<BR>&gt=3B <BR>&gt=3B I updated CM3 today from CVS=2C on both my =
>Mac and on a FreeBSD system=2C<BR>&gt=3B and ... my Scheme interpreter brok=
>e. Here's what the code looks like=2C<BR>&gt=3B with annotations:<BR>&gt=3B=
> <BR>&gt=3B 49 Debug.Out("t.rest =3D NIL? " &amp=3B Fmt.Bool(t.rest=3DNIL))=
>=3B<BR>&gt=3B 50 Debug.Out("ISTYPE(t.rest=2CT)? " &amp=3B Fmt.Bool(ISTYPE(t=
>.rest=2CT)))=3B<BR>&gt=3B 51 Debug.Out("Rest(t.rest) =3D NIL? " &amp=3B Fmt=
>.Bool(Rest(t.rest)=3DNIL))=3B<BR>&gt=3B 52<BR>&gt=3B 53 IF t.rest # NIL AND=
> ISTYPE(t.rest=2CT) AND Rest(t.rest) =3D NIL THEN<BR>&gt=3B 54 Debug.Out("i=
>n IF clause...")=3B<BR>&gt=3B 55<BR>&gt=3B 56 IF SymEq(t.first=2C "quote") =
>THEN special :=3D "'"<BR>&gt=3B 57 ELSIF SymEq(t.first=2C "quasiquote") THE=
>N special :=3D "`"<BR>&gt=3B 58 ELSIF SymEq(t.first=2C "unquote") THEN spec=
>ial :=3D "=2C"<BR>&gt=3B 59 ELSIF SymEq(t.first=2C "unquote-splicing") THEN=
> special :=3D "=2C@"<BR>&gt=3B 60 END<BR>&gt=3B 61 ELSE<BR>&gt=3B 62 Debug.=
>Out("in ELSE clause...")<BR>&gt=3B 63 END=3B<BR>&gt=3B <BR>&gt=3B all you n=
>eed to know is that Debug.Out prints out debugging information<BR>&gt=3B to=
> the terminal. What I see is...<BR>&gt=3B <BR>&gt=3B t.rest =3D NIL? FALSE<=
>BR>&gt=3B ISTYPE(t.rest=2CT)? TRUE<BR>&gt=3B Rest(t.rest) =3D NIL? TRUE<BR>=
>&gt=3B in ELSE clause...<BR>&gt=3B <BR>&gt=3B What gives!?<BR>&gt=3B <BR>&g=
>t=3B Note this behavior occurs on both the Mac and on FreeBSD4 with a<BR>&g=
>t=3B compiler and runtime bootstrapped today from some previous CM3.<BR>&gt=
>=3B My old CM3 compiler was timestamped... April 30=2C I believe=2C and the=
><BR>&gt=3B code behaved properly under that one.<BR>&gt=3B <BR>&gt=3B I bel=
>ieve I have also tried it both with and without compiler<BR>&gt=3B optimiza=
>tions.<BR>&gt=3B <BR>&gt=3B I find it baffling that so much stuff (mentor!)=
> can work if "AND" isn't<BR>&gt=3B working right. This is the only if state=
>ment in many=2C many source files<BR>&gt=3B that seems to be working wrong.=
><BR>&gt=3B <BR>&gt=3B Is it possible I'm missing something?? No I don't thi=
>nk so... here's a more<BR>&gt=3B explicit version:<BR>&gt=3B <BR>&gt=3B Deb=
>ug.Out("t.rest # NIL? " &amp=3B Fmt.Bool(t.rest#NIL))=3B<BR>&gt=3B Debug.Ou=
>t("ISTYPE(t.rest=2CT)? " &amp=3B Fmt.Bool(ISTYPE(t.rest=2CT)))=3B<BR>&gt=3B=
> Debug.Out("Rest(t.rest) =3D NIL? " &amp=3B Fmt.Bool(Rest(t.rest)=3DNIL))=
>=3B<BR>&gt=3B Debug.Out("conjunction? " &amp=3B Fmt.Bool(<BR>&gt=3B t.rest =
># NIL AND ISTYPE(t.rest=2CT) AND Rest(t.rest) =3D NIL ))=3B<BR>&gt=3B IF t.=
>rest # NIL AND ISTYPE(t.rest=2CT) AND Rest(t.rest) =3D NIL THEN<BR>&gt=3B .=
>..<BR>&gt=3B <BR>&gt=3B output is:<BR>&gt=3B <BR>&gt=3B t.rest # NIL? TRUE<=
>BR>&gt=3B ISTYPE(t.rest=2CT)? TRUE<BR>&gt=3B Rest(t.rest) =3D NIL? TRUE<BR>=
>&gt=3B conjunction? FALSE<BR>&gt=3B in ELSE clause...<BR>&gt=3B <BR>&gt=3B =
>TRUE AND TRUE AND TRUE is FALSE??<BR>&gt=3B <BR>&gt=3B Note that: <BR>&gt=
>=3B <BR>&gt=3B VAR q=2C w=2C e :=3D TRUE=3B<BR>&gt=3B <BR>&gt=3B Debug.Out(=
>"conjunction? " &amp=3B Fmt.Bool(<BR>&gt=3B q AND w AND e))=3B<BR>&gt=3B <B=
>R>&gt=3B results in TRUE (as it should).<BR>&gt=3B <BR>&gt=3B <BR>&gt=3B Mi=
>ka<BR>&gt=3B <BR></body>
></html>=
>
>--_55f6c801-7d57-4602-a131-dda139b64dfd_--



More information about the M3devel mailing list