--* From bmt@spadserv.watson.ibm.com  Fri Feb 12 06:13:56 1993
--* Received: from spadserv.watson.ibm.com by radical.watson.ibm.com (AIX 3.2/UCB 5.64/900524)
--*           id AA16025; Fri, 12 Feb 1993 06:13:56 -0500
--* Received: by spadserv.watson.ibm.com (AIX 3.2/UCB 5.64/900524)
--*           id AA17350; Fri, 12 Feb 1993 06:08:00 -0500
--* Date: Fri, 12 Feb 1993 06:08:00 -0500
--* From: bmt@spadserv.watson.ibm.com
--* X-External-Networks: yes
--* Message-Id: <9302121108.AA17350@spadserv.watson.ibm.com>
--* To: axc-bug@radical.watson.ibm.com
--* Subject: compiler dies with program fault (segmentation violation) [junk.as][current (26.2)]

--@ Fixed  by: PAB Wed Oct 06 14:58:35 1993
--@ Tested by: <name of new or existing file in test directory>
--@ Summary:   <One line description of real problem and the fix>


--Copyright The Numerical Algorithms Group Limited 1991.

#include "aslib.as"

macro 
  Boolean == Bit
  B == Bit
  N == Integer
  I == Integer
  min(aa,bb) == if aa < bb then aa else bb
  one? aa == aa = 1


facFlags ==> Enumeration(nil, sqfr, irred, prime)

FFE(S:with Object):with
   Object
   bracket: (facFlags, S, Integer) -> %
   apply: (%, Enumeration(xpnt)) -> Integer
   apply: (%, Enumeration(fctr)) -> S
   apply: (%, Enumeration(flg)) -> facFlags
   set!: (%, Enumeration(xpnt), Integer) -> Integer
 == add
   Rep ==> Record(flg:facFlags, fctr:S, xpnt:Integer)
   import Rep
   apply(f:%, tag:Enumeration(xpnt)):Integer == rep(f).xpnt
   apply(f:%, tag:Enumeration(fctr)):S == rep(f).fctr
   apply(f:%, tag:Enumeration(flg)):facFlags == rep(f).flg
   set!(f:%, tag:Enumeration(xpnt), e:Integer):Integer == set!(rep(f),xpnt,e)
   set!(f:%, tag:Enumeration(fctr), s:S):S == set!(rep(f),fctr,s)
   set!(f:%, tag:Enumeration(flg), flag:facFlags):facFlags == set!(rep(f),flg,flag)
   [flag:facFlags, s:S, e:Integer]:% == per [flag,s,e]
   apply(p: Outport, l: %): Outport ==
         import String
         import S
         import Integer
         p("ffe(fctr: ")(rep(l).fctr)(" xpnt: ")(rep(l).xpnt)(")")

Factored(S: with
           Object
           1:S
        ) : with
   makeFR: (S, List FFE(S)) -> %
   factorList: % -> List FFE(S)
   unit: % -> S
   apply: (Outport, %) -> Outport
 == add
   Rep ==> Record(unit:S, faclist:List FFE(S))
   import Rep
   makeFR(u:S, lffe:List FFE(S)):% == per [u, lffe]
   factorList(x:%):List FFE(S) == apply(rep(x),faclist)
   unit(x:%):S == apply(rep(x),unit)
   apply(p:Outport, f:%): Outport ==
      import String
      import S
      import List FFE(S)
      import FFE(S)
      import Enumeration(xpnt)
      import Enumeration(fctr)
      if unit(f) ~= 1 then p:=p(unit f)
      for fac in factorList f repeat
        p:=p(" ")((fac.fctr)@S)
        if fac.xpnt ~= 1@I then p:=p("^")((fac.xpnt)@I)
      p

import I
import String
l:List FFE(I) := nil
f:Factored I := makeFR(1,l)
if unit(f) ~= 1 then print(unit f)(" ~= 1")()
if unit(f) = 1 then print(unit f)(" = 1")() 
 
