From 66b97cdd82458354f1f7f6eb6479cf7d61053648 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Mon, 9 Feb 2004 22:36:30 +0000 Subject: [PATCH] We can compile external functions now. --- mad | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/mad b/mad index 7be96cd..7f4916a 100755 --- 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) -- 2.43.0