]> thyrsus.com Git - mad.git/commitdiff
We compile the transpose function now.
authorEric S. Raymond <esr@thyrsus,com>
Sat, 14 Feb 2004 22:37:58 +0000 (22:37 +0000)
committerEric S. Raymond <esr@thyrsus,com>
Sat, 14 Feb 2004 22:37:58 +0000 (22:37 +0000)
mad

diff --git a/mad b/mad
index 2443eff629a1050c70cdcc72457b12b9d2a0d18c..06f753d8f836f2a05f6e933865424e0ea31f7b2b 100755 (executable)
--- a/mad
+++ b/mad
@@ -236,7 +236,7 @@ def p_function_return(t):
     t[0] = ('return', t[3])    
 def p_function_return_void(t):
     "statement : FUNCTION RETURN"
-    t[0] = ('return')    
+    t[0] = ('return',)    
 
 ## INTEGER
 def p_integer(t):
@@ -383,10 +383,13 @@ def p_vector_values(t):
     t[0] = ('values',) + (t[3], t[5])
 
 ## Assignment
-def p_statement_substitution(t):
+def p_statement_substitution1(t):
     'statement : NAME EQUALS expression'
-    newvar = t[1]
-    t[0] = ('substitution', newvar, t[3])
+    t[0] = ('substitution', ('variable', t[1]), t[3])
+
+def p_statement_substitution2(t):
+    'statement : arrayref EQUALS expression'
+    t[0] = ('substitution', tuple(['variable'] + t[1][0]), t[3])
 
 # Expression parsing
 
@@ -612,7 +615,7 @@ def analyze():
                     # Bookkeeping, so we know what function we're in
                     currentfunc = statement[1]
                     funcline = line
-                elif statement[0] == 'return':
+                elif statement[0] == 'return' and len(statement) > 1:
                     # Give the function the type of the last return statement.
                     # We're screwed if two different returns in a function have
                     # different modes.
@@ -627,10 +630,10 @@ def analyze():
                             deductions += 1
                 elif statement[0] == 'substitution':
                     # Propagate type markers through assignment
-                    var = statement[1]
+                    var = statement[1][1]
                     m = mode(statement[2])
                     typedict[var] = m
-                    if m != normalmode and typedict[statement[1]]!=m:
+                    if m != normalmode and typedict[var] != m:
                         deductions += 1
             if deductions == 0:
                 break
@@ -871,7 +874,7 @@ def print_C_statement(statement):
         return "} else {"
     elif statement[0] == 'entry':
         currentfunc = statement[1]
-        rep = "\n" + returntypes.get(currentfunc, normalmode) + " " + currentfunc[:-1] + "("
+        rep = "\n" + returntypes.get(currentfunc, 'void') + " " + currentfunc[:-1] + "("
         defaulted = []
         if len(statement) > 2:
             for (vtype, var) in statement[2]:
@@ -976,7 +979,7 @@ def print_C_statement(statement):
         del dimensions[var]
         return normalmode + " " + prinC1(('variable', var, dim)) + ", *recursor = " + var + ";"
     elif statement[0] == 'substitution':
-        return statement[1] + ' = ' + print_C_expr(statement[2]) + ';'
+        return print_C_expr(statement[1])+' = '+print_C_expr(statement[2])+';'
     elif statement[0] == 'whenever':
         return 'if (' + print_C_expr(statement[1]) + ') {'
     else:
@@ -1108,13 +1111,13 @@ if __name__ == '__main__':
         sys.stderr.write("mad: empty deck\n")
         sys.exit(1)
 
-    # Perform global analysis
-    analyze()
-
     if (dump_tuples):
         for t in deck:
             print t
 
+    # Perform global analysis
+    analyze()
+
     # Generate code
     if arguments == ['-']:
         generate_C_code(sys.stdout)