Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

write_asm의 안쓰이는 파라미터 제거, 'code' -> 'text' #42

Merged
merged 2 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading