diff --git a/aheui/aheui.py b/aheui/aheui.py index b9214f8..67695a1 100644 --- a/aheui/aheui.py +++ b/aheui/aheui.py @@ -447,7 +447,7 @@ def open_w(filename): return os.open(filename, os.O_WRONLY | os.O_CREAT, 0o644) -def prepare_compiler(contents, opt_level=2, source='code', aheuic_output=None, add_debug_info=False): +def prepare_compiler(contents, opt_level=2, source='text', aheuic_output=None, add_debug_info=False): compiler = compile.Compiler() if source == 'bytecode': compiler.read_bytecode(contents) diff --git a/aheui/compile.py b/aheui/compile.py index ed32b39..aa261e1 100644 --- a/aheui/compile.py +++ b/aheui/compile.py @@ -5,7 +5,7 @@ import os import aheui.const as c -from aheui._compat import unichr, _unicode +from aheui._compat import unichr, _unicode, PY3 OP_NAMES = [None, None, u'DIV', u'ADD', u'MUL', u'MOD', u'POP', u'PUSH', u'DUP', u'SEL', u'MOV', None, u'CMP', None, u'BRZ', None, u'SUB', u'SWAP', u'HALT', u'POPNUM', u'POPCHAR', u'PUSHNUM', u'PUSHCHAR', u'BRPOP2', u'BRPOP1', u'JMP'] @@ -815,10 +815,15 @@ def write_bytecode(self): assert len(p) == 4 codes.append(p) codes.append('\xff\xff\xff\xff') - return ''.join(codes) + code = ''.join(codes) + if PY3: + code = code.encode('utf-8') + return code def read_bytecode(self, text): """Read bytecodes from data text.""" + if PY3: + text = text.decode('utf-8') self.debug = None self.lines = [] self.label_map = {} @@ -838,7 +843,7 @@ def read_bytecode(self, text): if op in c.OP_JUMPS: self.label_map[val] = val - def write_asm(self, fp=1, commented=True): + def write_asm(self, commented=True): """Write assembly representation with comments.""" codes = [] for i, (op, val) in enumerate(self.lines):