]> thyrsus.com Git - mad.git/commitdiff
Floats get mapped to doubles internally.
authorEric S. Raymond <esr@thyrsus,com>
Fri, 30 Jan 2004 22:57:12 +0000 (22:57 +0000)
committerEric S. Raymond <esr@thyrsus,com>
Fri, 30 Jan 2004 22:57:12 +0000 (22:57 +0000)
mad

diff --git a/mad b/mad
index 5739de69bd1fd3897e3f83c4ea1e89c532c526c4..6b44f905c66c24ed1b6745a4dc30f0a3e829b326 100755 (executable)
--- a/mad
+++ b/mad
@@ -361,7 +361,7 @@ def p_expression_name(t):
     var = t[1]
     t[0] = ('variable', var)
     refcount[var] = refcount.get(var, 0) + 1 
-    if var not in integers + bools + floats + untyped:
+    if var not in integers + bools + doubles + untyped:
         untyped.append(var)
 
 # Error handling
@@ -375,7 +375,7 @@ yacc.yacc()
 import sys, re
 
 integers = []
-floats = []
+doubles = []
 bools = []
 dimensions = {}
 static = {}
@@ -395,7 +395,7 @@ def croak(t, msg):
 
 def analyze():
     "Gather variable types and determine function boundaries."
-    global integers, floats, bools, deck
+    global integers, doubles, bools, deck
     # We may need to generate a pseudo-function call
     if deck[0][3][0] != 'external_function':
         deck = [(deck[0][0], 0, None, ('entry', ('apply', 'main.',())))] + deck
@@ -414,7 +414,7 @@ def analyze():
                 declare(var, integers)
         elif statement[0] == 'substitution':
             var = statement[1]
-            if var not in integers + bools + floats + untyped:
+            if var not in integers + bools + doubles + untyped:
                 untyped.append(var)
         elif statement[0] in ('read', 'print'):
             pass
@@ -539,7 +539,7 @@ def fmt_convert(fmt, write=True):
             i = 1
             while str[i] in '0123456789.':
                 i += 1
-            res += ('%' + str[1:i] + 'f') * count
+            res += ('%' + str[1:i] + 'g') * count
             str = str[i:]
         elif str[0] == 'H':
             if write:
@@ -625,15 +625,15 @@ def generate(out):
     if bools:
         out.write('int ' + ', '.join(bools) + ';\t/* boolean */\n')
     if untyped:
-        out.write('float ' + ', '.join(untyped) + ';\t/* untyped */\n')
-    if floats:
-        out.write('float ' + ', '.join(floats) + ';\n')
+        out.write('double ' + ', '.join(untyped) + ';\t/* untyped */\n')
+    if doubles:
+        out.write('double ' + ', '.join(doubles) + ';\n')
     for (id, value) in static.items():
         out.write('static const char *%s\t= "%s";\n' % (id,fmt_convert(value)))
     for (file, line, label, statement) in deck:
         if statement[0] == 'internal':
             # FIXME: someday, deduce when return is of integral type
-            out.write('float %s {return %s;}\n' % \
+            out.write('double %s {return %s;}\n' % \
                       (print_expr(('apply', statement[1], statement[2])), print_expr(statement[3])))
 
     indent = 0