[M3devel] narrow still failing..

mika at async.caltech.edu mika at async.caltech.edu
Sun Jan 19 22:36:49 CET 2014


A smaller test:

     1  MODULE Main;
     2  IMPORT BDD, IO;
     3
     4  PROCEDURE P() : REFANY =
     5    BEGIN
     6      VAR x : REFANY;
     7      BEGIN
     8        x := BDD.New("a");
     9        Z(x);
    10        RETURN x
    11      END
    12    END P;
    13
    14  PROCEDURE Q() =
    15    BEGIN
    16      IO.Put(P() & "\n")
    17    END Q;
    18
    19  PROCEDURE Z(VAR x : REFANY) =
    20    BEGIN
    21      x := BDD.Format(x)
    22    END Z;
    23
    24  BEGIN
    25    Q()
    26  END Main.

(191)rover:~/refany/src>../FreeBSD4/refany

***
*** runtime error:
***    NARROW failed
***    file "/big/home/mika/refany/src/Main.m3", line 21
***

What's going on here???

Here are the relevant declarations:

(* simple BDD package *)

INTERFACE BDD;
IMPORT Word;

TYPE 
  T <: REFANY;

(* the boolean constants top and bottom *)
PROCEDURE True() : T;
PROCEDURE False() : T;

(* a new variable *)
PROCEDURE New(name : TEXT := NIL) : T;

(* unary ops *)
PROCEDURE Not(a : T) : T;

(* binary ops *)
PROCEDURE And(a, b : T) : T;
PROCEDURE Xor(a , b : T) : T;
PROCEDURE Equivalent(a, b : T) : T;
PROCEDURE Or( a, b : T) : T;
PROCEDURE Implies  (a , b : T) : T;

(* maketrue/makefalse *)

PROCEDURE MakeFalse(b, v : T) : T; (* make v false in b *)
PROCEDURE MakeTrue(b, v : T) : T; (* make v true in b *)


(* print with ids *)
PROCEDURE Format(a : T; symtab : REFANY (* BDDTextTbl.T *) := NIL) : TEXT;

(* the following procedures allow this interface to be used in generics *)
PROCEDURE Equal(a, b : T) : BOOLEAN;
PROCEDURE Hash(a : T) : Word.T;

PROCEDURE Size(a : T) : CARDINAL;
  (* number of nodes in structure *)

CONST
  Brand = "BDD 0.1";

PROCEDURE GetId(a : T) : INTEGER; (* for debugging *)

END BDD.
....

REVEAL
  T = BRANDED Brand OBJECT
    l , r : T;
    root : Root;
    tag : CARDINAL; (* for hashing *)
    name : TEXT;
  METHODS
    init() : T := Init;
  END;

PROCEDURE New(name : TEXT) : T =
  VAR res : Root := NEW(Root).init(); BEGIN
    res.name := name;
    res.root := res;
    res.l := true; res.r := false;
    res.id := nextId;
    res.tab := NEW(BDDTripleHash.Default).init(128);
    FOR i := FIRST(res.cache) TO LAST(res.cache) DO
      res.cache[i] := NEW(BDDTripleHash.Default).init(64)
    END; 
    EVAL BDDTripleHash.Put(res.tab, Pair { res.l, res.r }, (res));
    INC(nextId);
    RETURN res
  END New;

PROCEDURE Format(x : T; symtab : REFANY := NIL) : TEXT =
  VAR nm : TEXT;
  BEGIN
    IF symtab # NIL AND NARROW(symtab, BDDTextTbl.T).get(x, nm) THEN
      RETURN nm
    END;
    IF x = true THEN RETURN "TRUE"
    ELSIF x = false THEN RETURN "FALSE"
    END;
       
    IF x.name # NIL THEN RETURN x.name END;

    RETURN Fmt.Int(x.root.id) & " && (" & Format(x.l) & ") || (" & Format(x.r) &
           ") && ~" & Fmt.Int(x.root.id)
  END Format;

  use option @M3stackdump to get a stack trace
Abort


I'm happy to share the whole package if anyone with a better clue than me would like a look.

In fact:

http://rover.gcapltd.com/~mika/bdd.tgz

It should build without anything outside of standard cm3. 

     Mika



More information about the M3devel mailing list