# Map MAD intrinsics to C library functions
madfunc_map = {'elog':'log'}
-def croak(msg):
+errcount = 0
+
+def nonfatal(msg):
+ global errcount
sys.stderr.write('"%s", line %d: %s\n' % (sourcefile, sourceline, msg))
+ errcount += 1
+
+def fatal(msg):
+ nonfatal(msg)
+ sys.exit(1)
# All MAD variables are global, you have to simulate locals using SAVE DATA and
# RETURN DATA. Thus the variable lookup tables about are straight
if statement[0] == 'for':
target = statement[1]
if not target in labels:
- croak("no such label as "+`target`)
- sys.exit(1)
+ nonfatal("no such label as "+`target`)
# On to actual analysis
try:
# Mine the code for compile-time directives
funcline = sourceline
elif statement[0] == 'read':
if statement[1] not in format:
- croak("uninitialized format string" +`statement[1]`)
+ nonfatal("uninitialized format string" +`statement[1]`)
else:
(fmt, types) = fmt_convert(format[statement[1]])
for (vtype, var) in zip(types, statement[2:]):
break
elif prev[0] == 'entry':
(sourcefile,sourceline,label,statement) = deck[i-j-1]
- croak("multiple ENTRY points are not supported")
+ nonfatal("multiple ENTRY points are not supported")
else:
- croak('no EXTERNAL declaration matches this ENTRY')
+ nonfatal('no EXTERNAL declaration matches this ENTRY')
except:
sys.stderr.write("mad: internal error while analyzing code for line %d\n" % line)
(exc_type, exc_value, exc_traceback) = sys.exc_info()
# Perform global analysis
analyze()
+ if errcount:
+ sys.exit(1)
+
# Generate code
if arguments == ['-']:
generate_C_code(sys.stdout)