Skip to content

Commit

Permalink
Merge pull request #42 from aheui/fix-trivial
Browse files Browse the repository at this point in the history
write_asm의 안쓰이는 파라미터 제거, 'code' -> 'text'
  • Loading branch information
youknowone committed Apr 8, 2024
2 parents c53a597 + ca81c6e commit c7faea7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion aheui/aheui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 8 additions & 3 deletions aheui/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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 = {}
Expand All @@ -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):
Expand Down

0 comments on commit c7faea7

Please sign in to comment.