Skip to content

Commit

Permalink
Fix optimize2 to work for python3
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowone committed Jan 31, 2016
1 parent 14eba49 commit a0de92d
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 4 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ python:
- "3.4"
- "3.5"
- "pypy"
- "pypy3"
- "nightly"
# command to install dependencies
install:
Expand Down
5 changes: 4 additions & 1 deletion aheui/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,9 +610,12 @@ def optimize_order(self):
for op, v in lines:
if op in OP_JUMPS:
labels.append(v)
unused_labels = []
for label in self.label_map.keys():
if label not in labels:
del self.label_map[label]
unused_labels.append(label)
for label in unused_labels:
del self.label_map[label]
self.lines = lines
if self.debug:
new_comments = [self.debug.comments[h] for h in hints]
Expand Down
57 changes: 55 additions & 2 deletions tests/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from aheui import compile


def test_compiler():
def test_targets():
compiler = compile.Compiler()
compiler.compile(u'반맣희')
code1 = compiler.lines[:]
Expand All @@ -14,4 +14,57 @@ def test_compiler():
compiler.read_bytecode(bytecode)
code3 = compiler.lines[:]
assert list(map(lambda t: t[0], code1)) == list(map(lambda t: t[0], code2))
assert list(map(lambda t: t[0], code1)) == list(map(lambda t: t[0], code3))
assert list(map(lambda t: t[0], code1)) == list(map(lambda t: t[0], code3))


def test_optimize():
compiler = compile.Compiler()
compiler.compile(u'''상밢밢밣밦발받밧밥밣밦밦받밦밢밝받밝받밦밧밢받발받밧밣밦밥발받밝밥밧밦밦받밧받붑
붇벌벖벒벖벌벋벖법벍벒벖벋벍벌벍벍벖버벋벌벍벌벗벌벋벌법벓벖벗벋벌벓법벋벖벋벌벓
밦밦발받발받밧밣밦밥발받발밦밧밣발받밦밦발받발받밧밣밦밥발받발밦밧밣발받밦밦발붇
붉벗벋벌벓벓벋벒벋벌벓벗벖벌벋벌법벖벓벗벋벌벋벌벖벖벋벌벓벗벖벌벋벌법벖벓벗벋벌
밧밣밦받밦밣밦밝발받밧받밢발밦받밦밥밧밣발받밧밦받밢발받바밦밝밢밥밦받밧밧발밣불
붒벓벍벋벌벋벍법벖벋벖법벒벍벖벋벌벓벌벋벓벋벖법벒벍벖벋벌벗벍벗벗벋벖법벒벍벖벋
밧밦받밧받밦밢발받밦밧밢받발받밧밝밝받밦받밦밦발밧밦받바밧밝밝받밦받밦받밣밧밦붇
붏법법벋벋벌벋벒벗벖벋벌벓법법벖벋벌벌벍벒벖벋벖벓벓법벖벋벖벓벖벋벗벋벌벒벌법벗
발받발밥밥밣발받밧밥받밥발받밦밝밧받밝받밧밢발밣발받밝밝밥밧밦받밦밥밥밣발받밦붏
불벓벓벗벖벋벌벓벌벗벗벋벌벒벍벗벗벋벖법벋벒벖벋벌벒벍벗벗벋벖벋벗벍벍버벋벌벓벍
받밦밧밧받발받발받밥밣발받밧밝발밦발받밧받밥밣발받밧밣밦밧밝받밧밢받밥밝받밧밦붏
붇벌벓법법벌벋벍벋벗벍벖벋벌벓법벋벗버벋벌벋벍법벖벋벖벋벓벓벗벋벖벗벖벌벖벋벍벗
밧밢밧밦밦받밦받밢밢발받밧발밥밣밦받밦받밥밣발받밦받밥밣발받밦발밥발발받밧받밥붏
붓벋벌벌벗법벗버벋벌벌벗법벗벋벌벓벒벒벋벋벖벓벓법벖벋벌벒법벌벗벋벖벖벗벒벗벋벌
밣밦밥발받밦밦밧밣발받밦밦밧밣발받밝발밧밣발받밝밧발밧밦받발밥받밝발받밦밧밝밥붒
붓벌벍벋벌벓벗벖벖벋벌법벖벓벗벋벌법벖벓벗벋벌벋벌벖벖벋벖벋벖벋벗벋벖벗벌벓벖벋
밣발받밦발밦밧밦받밣밥받밣발받밦받밦발발받바밧밢발밣발받밧밧발밧밝받밦밧밢받발붇
붑벍벒벖벋벌벋벌벖벖벋벖벗벌벗벍벋벌벒벍벗벗벋벌벓벗벖벓벋벌벓벋법벍벋벌법벒벌벗
밦받밣발받밣발받밦밢밝밥밦받밧밥발밧발받밦밢밝밥밦받밧밥받밣발받밦밢밝밥밦받발붑
불벓벓법벗벋벌벌벗법벗벋벌벓벋법벖벋벌벓벌벒벖버벋벌법벍벍벗벋벖벋법벖벋벋벌벍벋
받밧밧밝밢발받받밦밧밣발받밧발밢받밦받밦밝밧받밝받밧밥받밥발받발밦밧밣발받받밦붓
붓벋벌벒벋벖벗벋벖벓벖벋벗벋벖벓벓법벖벋벌벌벒벍벖벋벌벓벗벖벖벋벌벋벒벗벖벋벌벓
밣밣밢발받밦밧밣밣발받바밧밣밧받밦받밧밥밧발발받밢받밝밝발받밦밦발받발받받받밣붏
붉벗벋벌벓벗벌벗벋벍벗벌벗벗벋벍법벋벒벗벋벖벗벓벋벖벋벌벒벒벋벖벋벌벌벗법벗벋벌
발밦발받발발밧밣발받밦밧밧받발받밦밧밣밣발받밧밥받밣발받밧밧밝밢발받밦밢받밥밦붇
붎벋벗벋벖벋벗벌벗벋벖벓법벌벗벋벖벗법벍벖벋벌벖벒벖벌버벋벖벋벌벒벗벋벖벋벗벌벗
발밦받밧밥받밥발받밦받밣받발받밧밥받밣발받밝밝밥밧밦받밦발밥발발받밦발밧밣발받붒
불벓벗벌벗벋벍벋벗벍벖벋벌벓벗벖벌벋벖벌벒벋벗벋벌벒벒벋벖벋벖벓벗벍벗벋벌벓벗벌
받밝밝밧받밦받바밧밦밣밥발받밧밦밣밥발받받받밥밣발받밧밣밦밧밝받발밥받밝발받밝붏
붇벌벒벌법벗벋벍벗벖벓벗벋벌벓법벋벗벋벌법벓벖벗벋벌벒벌법벗벋벌벓법벋벖벋벖벗벖
밧밦밣밥발받밣밥밥밣발받밝받밥밣발받밦밥밝받발받밧밦밣밥발받밝받밥밣발받밧밦밣붑
불벋벌벓벗벌벗벋벌법벖벓벗벋벌법벖벓벗벋벌벌법벌벖버벋벌법벋법벗벋벌벓법벋벓벋벌
발밧밣발받받발밧밣발받받발밧밣발받밝발밧밣발받밧밧발밧밝받밧발밧밣발받밧밣밦밥불
붑벍벖벋벌벓벗벌벌벋벖벋벌벒벋벋벌벓벗법벖벋벖벋벌벒법벋벌벓벗벌벍벋벌벒벋벖벗벋
밧밦받사받싹바싺밝빠따반타밝밙밙받반따따뚜
두벎떠벍떠더벍벖떠뻐터번떠뻐벌섵멓터벉떠떠
숭반투밣쟈뿌차발발뚜삭뱐뎌두쟈수처사맣
싸수쑼뽀뱐분누받루반타푸소뿌또붉다뭏또숰
분뾰빠초추러밤도밡밣두투쏘밡뽀붐또뱔볼
땨슡멓야뱐야냐야뱞야다샅뽀밦뱕뗘도타본
뜌뱖서밝밤따따다쌈샴아멓샅밝밤밤따또
또뷹추뺘져번뚜벌벌처뿌져벓투번
더쎰서토푸터번루벋누분변뽀쑼뽀숭
뵴범삭본투두벓벑도범라추초뻐소써
샤써도뼈섵더여볎여녀여변여
빠바쟈무차붏밣따다밣따다밣따다밣따다맣야희
뫃떠벌번정따도퍼즐릿
'''.replace(' ', ''))
compiler.optimize2()

0 comments on commit a0de92d

Please sign in to comment.