Skip to content

Commit

Permalink
Remove object file on error
Browse files Browse the repository at this point in the history
The object code will be corrupt anyway and `make` does not think something
usable was produced.
  • Loading branch information
matze committed Apr 11, 2012
1 parent f039022 commit ed4ade7
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions asm.py
Expand Up @@ -6,6 +6,7 @@
import re
import sys
import argparse
import os


def disjunction(*lst):
Expand Down Expand Up @@ -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)

0 comments on commit ed4ade7

Please sign in to comment.