[M3devel] strange errors...
Tony Hosking
hosking at cs.purdue.edu
Mon Jul 16 14:42:43 CEST 2007
I'll need to run this in the debugger. Do your previous instructions
for download and build still hold true?
On Jul 15, 2007, at 11:51 PM, Mika Nystrom wrote:
> Tony Hosking writes:
> ...
>>>
>>> Line 113 in Main.m3 is:
>>>
>>> Wr.PutText(wr, subs.apply(Bundle.Get(Form, "tokform.m3")));
>>
>> Where does the variable 'wr' come from? It is this 'wr' that is
>> failing the assert. It should not be gray, assuming that the GC was
>> able to find it. Can I see your Main.m3?
>>
>
> It fails exactly the same way with @M3paranoidgc.
>
> wr comes from FileWr.Open. The programmer has re-used wr for two
> open FileWrs... I marked line 113, where it crashes:
>
> (* Copyright (c) 2000 California Institute of Technology *)
> (* All rights reserved. See the file COPYRIGHT for a full
> description. *)
> (* $Id: Main.m3,v 1.3 2002/12/11 08:54:53 kp Exp $ *)
>
> MODULE Main;
> IMPORT Debug;
> IMPORT tokformBundle, Bundle;
> IMPORT TokParams;
> IMPORT TokSpec;
> IMPORT FileWr, Wr, Thread, OSError;
> IMPORT TextWr;
> IMPORT TextSubs;
> IMPORT TextList;
> IMPORT Pathname;
> IMPORT Fmt;
> IMPORT FmtTable;
> (* IMPORT Term; *)
> <* FATAL Thread.Alerted, Wr.Failure *>
>
> VAR
> Form := tokformBundle.Get();
>
> PROCEDURE FormatTypes(t: TextList.T; tokName, kind: TEXT): TEXT =
> VAR
> wr := TextWr.New();
> cur := t;
> subs: TextSubs.T;
> BEGIN
> WHILE cur # NIL DO
> subs := NEW(TextSubs.T).init();
> subs.add("%type", cur.head);
> subs.add("%tok", tokName);
> Wr.PutText(wr, subs.apply(Bundle.Get(Form, kind)));
> cur := cur.tail;
> END;
> RETURN TextWr.ToText(wr);
> END FormatTypes;
>
> PROCEDURE FormatLegalConst(tok: TokSpec.T): TEXT =
> VAR
> dummy: TEXT;
> fmt := NEW(FmtTable.T).init();
> BEGIN
> FOR i := 1 TO tok.lastConstCode DO
> IF tok.constTokensR.get(i, dummy) THEN
> fmt.putInt(i);
> END;
> END;
> RETURN fmt.toText();
> END FormatLegalConst;
>
> PROCEDURE FormatNamedConst(tok: TokSpec.T): TEXT =
> VAR
> cur := tok.tokens;
> name: TEXT;
> code: INTEGER;
> wr := TextWr.New();
> BEGIN
> WHILE cur # NIL DO
> name := cur.head;
> IF tok.constTokens.get(name, code) THEN
> Wr.PutText(wr, " " & name & " = " & Fmt.Int(code) & ";\n");
> END;
> cur := cur.tail;
> END;
> RETURN TextWr.ToText(wr);
> END FormatNamedConst;
>
> PROCEDURE Subs(tok: TokSpec.T; name: TEXT): TextSubs.T =
> VAR
> subs := NEW(TextSubs.T).init();
> BEGIN
> subs.add("\\\n", "");
> subs.add("%tok", name);
> subs.add("%type", FormatTypes(tok.varTokens, name,
> "tokform.type"));
> subs.add("%case", FormatTypes(tok.varTokens, name,
> "tokform.case"));
> subs.add("%constSet", FormatLegalConst(tok));
> subs.add("%constName", FormatNamedConst(tok));
> subs.add("%lastConst", Fmt.Int(tok.lastConstCode));
> subs.add("%gen", "(* Generated by ktok *)");
> RETURN subs;
> END Subs;
>
>
> VAR
> tp: TokParams.T;
> tok: TokSpec.T;
> subs: TextSubs.T;
> wr: Wr.T;
> BEGIN
> Debug.S("WELCOME!");
> tp := TokParams.Get("tok", ".t", "Tok.i3", FALSE);
> Debug.S("GOT TOKPARAMS!");
> tok := TokParams.ReadTokens(tp);
> Debug.S("GOT TOKENS");
> subs := Subs(tok, tp.outBase);
> Debug.S("GOT SUBS!");
> TRY
> wr := FileWr.Open(tp.out);
> EXCEPT OSError.E =>
> Debug.Error("Cannot open tok interface output file: " & tp.out);
> END;
>
> Wr.PutText(wr, subs.apply(Bundle.Get(Form, "tokform.i3")));
> Wr.Close(wr);
>
> TRY
> wr := FileWr.Open(Pathname.ReplaceExt(tp.out, "m3"));
> EXCEPT OSError.E =>
> Debug.Error("Cannot open tok implementation output file: " &
> Pathname.ReplaceExt(tp.out, "m3"));
> END;
> Wr.PutText(wr, subs.apply(Bundle.Get(Form, "tokform.m3"))); (*
> line 113 *)
> Wr.Close(wr);
> END Main.
>
More information about the M3devel
mailing list