From ed4ade75fba7e2561a023af6edffe7ba26040982 Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Wed, 11 Apr 2012 20:40:01 +0200 Subject: [PATCH] Remove object file on error The object code will be corrupt anyway and `make` does not think something usable was produced. --- asm.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/asm.py b/asm.py index 75bbdc1..950b387 100755 --- a/asm.py +++ b/asm.py @@ -6,6 +6,7 @@ import re import sys import argparse +import os def disjunction(*lst): @@ -148,8 +149,11 @@ def report_error(filename, lineno, error): if y is not None: program.append(y) - with open(args.o, "wb") as f: - for word in program: - if isinstance(word, str): - word = labels[word] - f.write(struct.pack(">H", word)) + try: + with open(args.o, "wb") as f: + for word in program: + if isinstance(word, str): + word = labels[word] + f.write(struct.pack(">H", word)) + except KeyError: + os.remove(args.o)