arraydepths = {}
returntypes = {}
normalmode = 'double'
+dummycount = 0
def initfunc(f):
global currentfunc
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':
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:
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 {'
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)