Commit e8f58ddc authored by Wastl's avatar Wastl

Add unwimp; output size after packing

parent 299e03d6
......@@ -262,7 +262,7 @@ def stack_depth(stack, ob, req=1):
if __name__ == '__main__':
def usage():
print >> sys.stderr, """\
Synopsis: %s [-pdwh] [-e <program> | <file>]
Synopsis: %s [-pdwWh] [-e <program> | <file>]
-p, --pack
......@@ -272,6 +272,10 @@ Options:
-w, --wimp, --wimpy
Replace names of instructions by the correct instructions at
parse time and add the DUP keyword which equals STORE LOAD LOAD
-W, --unwimp
Output a golfed non-wimpy version of a wimpy program. Can also
be used for golfing normal programs if they don't contain
instruction aliases.
-e <program>
Use the given program instead of file/STDIN.
-h, -?, --help
......@@ -279,16 +283,18 @@ Options:
try: opts, args = getopt.getopt(sys.argv[1:], 'dpwe:h?', ['help', 'wimp', 'wimpy', 'pack', 'debug'])
try: opts, args = getopt.getopt(sys.argv[1:], 'dpwWe:h?', ['help', 'wimp', 'wimpy', 'unwimp', 'pack', 'debug'])
except getopt.GetoptError: usage()
code = None
do_pack = False
debug = lambda x: None
wimp = False
unwimp = False
for opt, val in opts:
if opt == '-p' or opt == '--pack': do_pack = True
elif opt == '-d' or opt == '--debug': debug = lambda x: sys.stderr.write(x+'\n')
elif opt == '-w' or opt == '--wimp' or opt == '--wimpy': wimp = True
elif opt == '-W' or opt == '--unwimp': unwimp = True
elif opt == '-e': code = val
elif opt == '-h' or opt == '-?' or opt == '--help': usage()
if code is None:
......@@ -299,7 +305,14 @@ Options:
else: code =
if do_pack:
if is_packed(code): print unpack(code)
else: sys.stdout.write(pack(parse(code, wimp)))
code = pack(parse(code, wimp))
print >> sys.stderr, "Packed: %d bytes" % len(code)
elif unwimp:
code = str(parse(code, True))
print >> sys.stderr, "Size: %d bytes" % len(code)
print code
else: execute(parse(code, wimp), lambda:, lambda x: (sys.stdout.write(x), sys.stdout.flush()), debug)
except ObCodeError as err: print >> sys.stderr, err
except KeyboardInterrupt: print >> sys.stderr, "Interrupted"
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment