]> thyrsus.com Git - mad.git/commitdiff
We compile truthtable.mad now -- FOR VALUES is handled.
authorEric S. Raymond <esr@thyrsus,com>
Tue, 10 Feb 2004 04:17:59 +0000 (04:17 +0000)
committerEric S. Raymond <esr@thyrsus,com>
Tue, 10 Feb 2004 04:17:59 +0000 (04:17 +0000)
mad

diff --git a/mad b/mad
index ac44b357ff83efa4e684642cb54c6bc923194463..342dc3b15fa12d615beb05be32ca416459a89acd 100755 (executable)
--- a/mad
+++ b/mad
@@ -116,6 +116,7 @@ typedict = {}
 arraydepths = {}
 returntypes = {}
 normalmode = 'double'
+dummycount = 0
 
 def initfunc(f):
     global currentfunc
@@ -444,7 +445,7 @@ def croak(t, msg):
 
 def analyze():
     "Gather variable types and determine function boundaries."
-    global deck, currentfunc
+    global deck, currentfunc, hasmain
     # We may need to generate a pseudo-function call
     for i in range(len(deck)):
         if deck[i][3][0] != 'remark':
@@ -476,6 +477,9 @@ def analyze():
         elif statement[0] == 'normal':
             global normalmode
             normalmode = statement[1]
+        elif statement[0] in ("print", "read"):
+            if "stdio" not in headers:
+                headers.append("stdio")
         elif statement[0] == 'values':
             var = statement[1]
             if var in refcount:
@@ -782,10 +786,13 @@ def print_statement(statement):
         return '%s %s {return %s;}' % \
                       (returntypes.get(statement[1], normalmode), print_expr(('apply', statement[1], statement[2])), print_expr(statement[3]))
     elif statement[0] == 'map':
+        global dummycount
         scopes.append(statement[1])
         count = len(statement[3])
-        rep='for (i = 0; i < %d; i++) { %s = '%(count ,statement[2])
-        rep += "((%s [%d]){%s})[i];" % (statement[3][0][0][:-3], count, ", ".join(map(lambda x: `x[1]`, statement[3])))
+        dummy = "d_%d" % dummycount
+        dummycount += 1
+        rep='for (int %s = 0; %s < %d; %s++) {%s = '%(dummy, dummy, count, dummy, statement[2])
+        rep += "((%s [%d]){%s})[%s];" % (statement[3][0][0][:-3], count, ", ".join(map(lambda x: `x[1]`, statement[3])), dummy)
         return rep
     elif statement[0] == 'otherwise':
         return 'else {'
@@ -923,11 +930,11 @@ if __name__ == '__main__':
             if hasmain:
                 if not target:
                     target = arguments[0][:-4]
-                compile = "gcc %s -lm -o %s" % (srclist, target)
+                compile = "gcc -std=c99 %s -lm -o %s" % (srclist, target)
             else:
                 if not target:
                     target = arguments[0][:-4] + ".o"
-                compile = "gcc -c %s -o %s" % (srclist, target)
+                compile = "gcc -std=c99 -c %s -o %s" % (srclist, target)
             if os.system(compile) == 0:
                 os.system("rm -f " + srclist)