]> thyrsus.com Git - mad.git/commitdiff
We can compile external functions now.
authorEric S. Raymond <esr@thyrsus,com>
Mon, 9 Feb 2004 22:36:30 +0000 (22:36 +0000)
committerEric S. Raymond <esr@thyrsus,com>
Mon, 9 Feb 2004 22:36:30 +0000 (22:36 +0000)
mad

diff --git a/mad b/mad
index 7be96cd079e413badd80b2f810e20bb0d67d7ff5..7f4916adaed139fa6edc43f2263c39ec494f88d8 100755 (executable)
--- a/mad
+++ b/mad
@@ -150,7 +150,7 @@ def p_boollist(t):
 def p_boollist_continue(t):
     'boollist : boollist COMMA NAME'
     t[0] = t[1] + [t[3]]
-    typedict[currentfunc][t[1]] = 'bool'
+    typedict[currentfunc][t[3]] = 'bool'
 
 ## CONTINUE
 def p_statement_continue(t):
@@ -431,6 +431,7 @@ import sys, re
 dimensions = {}
 static = {}
 format = {}
+hasmain = False
 
 # Map MAD intrinsics to C library functions
 madfunc_map = {'elog':'log'}
@@ -448,12 +449,13 @@ def analyze():
             break
     if deck[i][3][0] != 'external_function':
         deck.insert(i, (deck[i][0], i, None, ('entry', 'main.',())))
-        
+        hasmain = True
     else:
         for i in range(len(deck)):
             (file, line, label, statement) = deck[i]
             if statement[0] == 'end_function' and i < len(deck)-1 and deck[i+1][2][0] != 'extern':
                 deck.insert(i, (file, line, None, ('entry', 'main.', ())))
+                hasmain = True
     # Mine the code for compile-time directives
     for (file, line, label, statement) in deck:
         if statement[0] == 'boolean':
@@ -884,8 +886,6 @@ if __name__ == '__main__':
         sys.stderr.write("mad: -o is required with multiple sourcefiles.\n")
         sys.exit(1)
     else:
-        if not target:
-            target = arguments[0][:-4]
         for file in arguments:
             stem = file[:-4]
             out = open(stem + ".c", "w")
@@ -894,7 +894,14 @@ if __name__ == '__main__':
         srclist = " ".join(map(lambda x: x[:-4] + ".c", arguments))
         if binary:
             # Must be gcc, else compilation of internal functions will fail
-            compile = "gcc %s -lm -o %s" % (srclist, target)
+            if hasmain:
+                if not target:
+                    target = arguments[0][:-4]
+                compile = "gcc %s -lm -o %s" % (srclist, target)
+            else:
+                if not target:
+                    target = arguments[0][:-4] + ".o"
+                compile = "gcc -c %s -o %s" % (srclist, target)
             if os.system(compile) == 0:
                 os.system("rm -f " + srclist)