From: Eric S. Raymond Date: Fri, 30 Jan 2004 22:57:12 +0000 (+0000) Subject: Floats get mapped to doubles internally. X-Git-Tag: 1.0~156 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=d4eb050ab2f8df4be59608ae5718ff7925bf5567;p=mad.git Floats get mapped to doubles internally. --- diff --git a/mad b/mad index 5739de6..6b44f90 100755 --- 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