(fmt, types) = fmt_convert(format[statement[1]])
for (vtype, var) in zip(types, statement[2:]):
if type(var) == type(()) and var[0] == 'range':
- if type == 'string':
- typedict[currentfunc][var[1]] = 'char'
- else:
- typedict[currentfunc][var[1]] = vtype
+ typedict[currentfunc][var[1]] = vtype
else:
typedict[currentfunc][var] = vtype
# Type inference loop. We initialized for this by deducing types
elif t[0] == 'boolnum':
#print "<-mode of boolean constant", t[1]
return 'bool'
- elif t[0] == 'string':
+ elif t[0] == 'char':
# Yes, MAD considers strings to have int type, see section
# 2.10. In the original 709 implementation they were 6-byte
# constants that fit in a 36-bit machine word.
res = t[1]
if len(t) > 2:
for dim in t[2]:
- res += '[' + dim[1] + ']'
+ res += '[' + print_C_expr(('-', dim[1], ('intnum', '1'))) + ']'
return res
elif t[0] == 'apply':
madfunc = t[1][:-1]
return 'abs(%s)' % prinC1(t[1]) # int or bool
elif t[0] in ('intnum', 'doublenum'):
return t[1]
+ elif type(t) == type(()) and t[0] == 'range':
+ if t[2] == ('intnum', '1'):
+ return print_C_expr(('variable', t[1]))
+ else:
+ return print_C_expr(('+',('variable', t[1]),('-',t[2],('intnum', '1'))))
else:
return '***'+`t`
i += 1
res += "%" + `count * int(str[1:i])` + "s"
str = str[i:]
- types += ['string']
+ types += ['char']
elif str[0] == 'F':
i = 1
while str[i] in '0123456789.':
if write:
res += str[1:count+1]
str = str[count+1:]
- types += ['string']
+ types += ['char']
elif str[0] == 'I':
i = 1
while str[i] in '0123456789':
#if defaulted:
# sys.stderr.write("warning: defaulted base type for %s\n" % ", ".join(defaulted))
declarations = ""
- for vtype in ('double', 'int', 'bool'):
+ for vtype in ('double', 'int', 'bool', 'char'):
vars = filter(lambda x: types[x] == vtype, types.keys())
if vars:
- declarations += vtype + " " + ", ".join(vars) + "; "
+ declarations += vtype
+ for var in vars:
+ declarations += " " + var
+ if var in dimensions:
+ for dim in dimensions[var]:
+ declarations += "[" + print_C_expr(dim) + "]"
+ declarations += ","
+ declarations = declarations[:-1] + "; "
if declarations:
rep += " " + declarations[:-1] + "\n"
return rep
elif statement[0] == 'read':
(fmt, types) = fmt_convert(format[statement[1]], write=False)
inlist = []
- for (inspec, intype) in zip(statement[2:], types):
- if type(inspec) == type(""):
- inlist.append("&" + inspec)
- elif type(inspec) == type(()) and inspec[0] == 'range' and intype == 'string':
- if inspec[2] == ('intnum', '1'):
- inlist.append(print_C_expr(('variable', inspec[1])))
- else:
- inlist.append(print_C_expr(('+',('variable', inspec[1]),('-',inspec[2],('intnum', '1')))))
+ for (ispec, itype) in zip(statement[2:], types):
+ if type(ispec) == type(""):
+ inlist.append("&" + ispec)
+ elif type(ispec)==type(()) and ispec[0]=='range' and itype=='char':
+ inlist.append(print_C_expr(ispec))
else:
sys.stderr.write("unsupported type in READ FORMAT\n")
sys.exit(1)
return rep
elif statement[0] == 'set_list_to':
var = statement[1]
- return normalmode + " " + prinC1(('variable', var, dimensions[var])) + ", *recursor = " + var + ";"
+ dim = dimensions[var]
+ del dimensions[var]
+ return normalmode + " " + prinC1(('variable', var, dim)) + ", *recursor = " + var + ";"
elif statement[0] == 'substitution':
return statement[1] + ' = ' + print_C_expr(statement[2]) + ';'
elif statement[0] == 'whenever':