]> thyrsus.com Git - mad.git/commitdiff
This aoppears to compile wordsearch.
authorEric S. Raymond <esr@thyrsus,com>
Fri, 13 Feb 2004 18:06:34 +0000 (18:06 +0000)
committerEric S. Raymond <esr@thyrsus,com>
Fri, 13 Feb 2004 18:06:34 +0000 (18:06 +0000)
mad

diff --git a/mad b/mad
index 662f66340d0ac29cb59ba551a4bee34f1611691d..4acc26ac26a17dbed5a1ee3d29737bc40d78985c 100755 (executable)
--- a/mad
+++ b/mad
@@ -555,10 +555,7 @@ def analyze():
                 (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
@@ -625,7 +622,7 @@ def mode(t):
     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.
@@ -654,7 +651,7 @@ def prinC1(t):
         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]
@@ -705,6 +702,11 @@ def prinC1(t):
             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`
 
@@ -763,7 +765,7 @@ def fmt_convert(str, write=True):
                 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.':
@@ -775,7 +777,7 @@ def fmt_convert(str, write=True):
             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':
@@ -830,10 +832,17 @@ def print_C_statement(statement):
         #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
@@ -878,14 +887,11 @@ def print_C_statement(statement):
     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)
@@ -912,7 +918,9 @@ def print_C_statement(statement):
         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':