--* From SMWATT%WATSON.vnet.ibm.com@yktvmh.watson.ibm.com  Thu Jan 27 23:39:25 1994
--* Received: from yktvmh.watson.ibm.com by leonardo.watson.ibm.com (AIX 3.2/UCB 5.64/4.03)
--*           id AA07514; Thu, 27 Jan 1994 23:39:25 -0500
--* Received: from watson.vnet.ibm.com by yktvmh.watson.ibm.com (IBM VM SMTP V2R3)
--*    with BSMTP id 5842; Thu, 27 Jan 94 23:45:18 EST
--* Received: from YKTVMH by watson.vnet.ibm.com with "VAGENT.V1.0"
--*           id <A.SMWATT.NOTE.VAGENT2.2368.Jan.27.23:45:17.-0500>
--*           for asbugs@watson; Thu, 27 Jan 94 23:45:18 -0500
--* Received: from YKTVMH by watson.vnet.ibm.com with "VAGENT.V1.0"
--*           id 2366; Thu, 27 Jan 1994 23:45:17 EST
--* Received: from cyst.watson.ibm.com by yktvmh.watson.ibm.com (IBM VM SMTP V2R3)
--*    with TCP; Thu, 27 Jan 94 23:45:15 EST
--* Received: from spadserv.watson.ibm.com by cyst.watson.ibm.com (AIX 3.2/UCB 5.64/900528)
--*   id AA78425; Thu, 27 Jan 1994 23:45:31 -0500
--* Received: by spadserv.watson.ibm.com (AIX 3.2/UCB 5.64/900524)
--*           id AA15650; Thu, 27 Jan 1994 23:42:59 -0500
--* Date: Thu, 27 Jan 1994 23:42:59 -0500
--* From: smwatt@spadserv.watson.ibm.com (Stephen Watt)
--* X-External-Networks: yes
--* Message-Id: <9401280442.AA15650@spadserv.watson.ibm.com>
--* To: asbugs@watson.ibm.com
--* Subject: [5] for free n ... generates bad code without -O [forfree.as][33.7x]

--@ Fixed  by:  SSD   Thu May 11 10:43:42 EDT 1995 
--@ Tested by:  none 
--@ Summary:    File now compiles, runs, and prints text mandel pattern correctly. 


-- The statement below "for free n in ..." generates bad C when not optimized.
#include "aslib.as"

macro
    SI       == SingleInteger
    F        == DoubleFloat
    CF       == Complex F
    Infinity == 0

import from CF
inline from CF


maxIters: SI == 100

drawMand(minR:F, maxR:F, numR:SI, minI:F, maxI:F, numI:SI): () ==
  mandel(c: CF): SI ==
    z: CF := 0
    n: SI := 0
    for free n in 1..maxIters while norm z < 4.0 repeat
        z  := z*z + c
    if n = maxIters then n := Infinity
    n

  for i in step(numI)(minI, maxI) for ic in 1..numI repeat
    for r in step(numR)(minR, maxR) for rc in 1..numR repeat
      drawPoint(rc, ic, mandel complex(r,i))
    endRow()


drawPoint(x: SI, y: SI, n: SI): () ==
  n = Infinity => print "   "
  print(if n < 10 then "  " else " ")(n)

endRow(): () == print()

import from F
drawMand(-2.0, -1.0, 25, -0.5, 0.5, 25)
 
