Skip to content

Commit

Permalink
Merge pull request #39 from aheui/x
Browse files Browse the repository at this point in the history
asm+comment 타겟 수정, 앟셈블러 배포, 실행시에만 rlib 경고
  • Loading branch information
youknowone authored Apr 5, 2024
2 parents 10c67b7 + a455400 commit d11187e
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 24 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,19 @@ jobs:
repository: pypy/pypy
ref: release-pypy2.7-v7.3.15
path: pypy
- name: Build
- name: Install Python package dependencies
run: |
pypy -m pip install -e .
- name: Python Test with snippets
run: |
cd snippets && PYTHONPATH=$GITHUB_WORKSPACE/pypy AHEUI='pypy ../rpaheui.py' ./test.sh --disable logo
- name: Build binary
run: |
export RPYTHON="pypy $GITHUB_WORKSPACE/pypy/rpython/bin/rpython"
cd $GITHUB_WORKSPACE
make -j 3
- name: Test with snippets
- name: Binary Test with snippets
run: |
cd "$GITHUB_WORKSPACE/snippets"
AHEUI="$GITHUB_WORKSPACE/rpaheui-c" ./test.sh --disable integer
AHEUI="$GITHUB_WORKSPACE/rpaheui-bigint-c" ./test.sh
AHEUI="$GITHUB_WORKSPACE/rpaheui-bigint-c" ./test.sh
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ RPYTHONFLAGS?=--opt=jit --translation-jit_opencoder_model=big
.PHONY: all rpaheui-c rpaheui-bigint-c test-bigint test-smallint test-py clean install


all: aheui-bigint-c aheui-c aheui-py
all: aheui-bigint-c aheui-c aheui-py ahsembler-py

version:
echo "VERSION = '`git describe --tags`'" > aheui/version.py
Expand All @@ -15,12 +15,18 @@ aheui-py: version
cp rpaheui.py bin/aheui-py
cp rpaheui.py bin/aheui

ahsembler-py:
cp ahsembler.py bin/ahsembler

rpaheui-bigint-c:
RPAHEUI_BIGINT=1 $(RPYTHON) $(RPYTHONFLAGS) --output rpaheui-bigint-c rpaheui.py

rpaheui-c:
$(RPYTHON) $(RPYTHONFLAGS) rpaheui.py

ahsembler-c:
$(RPYTHON) ahsembler.py # No JIT

aheui-bigint-c: rpaheui-bigint-c
cp rpaheui-bigint-c bin/aheui-bigint-c

Expand Down
3 changes: 0 additions & 3 deletions aheui/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ def __init__(self, list):
def sort(self):
self.list.sort()

import os
os.write(2, b"[Warning] It is running without rlib/jit.\n")


try:
unichr(0)
Expand Down
7 changes: 5 additions & 2 deletions aheui/aheui.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import os

from aheui import const as c
from aheui._compat import jit, unichr, ord, _unicode, bigint
from aheui._compat import jit, unichr, ord, _unicode, bigint, PYR
from aheui import compile
from aheui.option import process_options
from aheui.warning import WarningPool
Expand Down Expand Up @@ -454,7 +454,8 @@ def prepare_compiler(contents, opt_level=2, source='code', aheuic_output=None, a
elif source == 'asm':
compiler.read_asm(contents.decode('utf-8'))
else:
compiler.compile(contents.decode('utf-8'), add_debug_info=add_debug_info)
contents = contents.decode('utf-8')
compiler.compile(contents, add_debug_info=add_debug_info)

if opt_level == 0:
pass
Expand Down Expand Up @@ -493,6 +494,8 @@ def entry_point(argv):
compiler = prepare_compiler(contents, int(str_opt_level), source, aheuic_output, add_debug_info)
outfp = 1 if output == '-' else open_w(output)
if target == 'run':
if not PYR:
warnings.warn(b'no-rpython')
program = Program(compiler.lines, compiler.label_map)
exitcode = mainloop(program, compiler.debug)
elif target in ['asm', 'asm+comment']:
Expand Down
19 changes: 11 additions & 8 deletions aheui/option.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import os
from aheui._argparse import ArgumentParser
from aheui._compat import bigint
from aheui._compat import bigint, PY3
from aheui.version import VERSION
from aheui import compile

Expand All @@ -14,13 +14,13 @@
\t1: Quickly resolve deadcode by rough stacksize emulation and merge constant operations.
\t2: Perfectly resolve deadcode by stacksize emulation, reserialize code chunks and merge constant operations.
""")
parser.add_argument('--source', '-S', default='auto', choices='auto,bytecode,asm,asm+comment,text', description='Set source filetype.', full_description="""\t- `auto`: Guess the source type. `bytecode` if `.aheuic` or `End of bytecode` pattern in source. `asm` is `.aheuis`. `text` if `.aheui`. `text` is default.
parser.add_argument('--source', '-S', default='auto', choices='auto,bytecode,asm,text', description='Set source filetype.', full_description="""\t- `auto`: Guess the source type. `bytecode` if `.aheuic` or `End of bytecode` pattern in source. `asm` is `.aheuis`. `text` if `.aheui`. `text` is default.
\t- `bytecode`: Aheui bytecode. (Bytecode representation of `ahsembly`.
\t- `asm`: See `ahsembly`.
\t- `asm+comment`: Same as `asm` with comments.
\t- usage: `--source=asm`, `-Sbytecode` or `-S text`
""")
parser.add_argument('--target', '-T', default='run', choices='run,bytecode,asm', description='Set target filetype.', full_description="""\t- `run`: Run given code.
parser.add_argument('--target', '-T', default='run', choices='run,bytecode,asm,asm+comment', description='Set target filetype.', full_description="""\t- `run`: Run given code.
\t- `bytecode`: Aheui bytecode. (Bytecode representation of `ahsembly`.
\t- `asm`: See `ahsembly`.
\t- usage: `--target=asm`, `-Tbytecode` or `-T run`
Expand Down Expand Up @@ -89,6 +89,8 @@ def open_r(filename):
if len(args) != 1:
os.write(2, b'aheui: error: --cmd,-c but input file found\n')
raise SystemExit()
if PY3:
cmd = cmd.encode('utf-8')
contents = cmd
filename = '-'

Expand All @@ -100,7 +102,7 @@ def open_r(filename):
source = 'bytecode'
elif filename.endswith('.aheuis'):
source = 'asm'
elif '\xff\xff\xff\xff' in contents:
elif b'\xff\xff\xff\xff' in contents:
source = 'bytecode'
else:
source = 'text'
Expand Down Expand Up @@ -131,10 +133,11 @@ def open_r(filename):
output += '.aheuic'
elif target in ['asm', 'asm+comment']:
output = filename
if output.endswith('.aheui'):
output += 's'
else:
output += '.aheuis'
if output != '-':
if output.endswith('.aheui'):
output += 's'
else:
output += '.aheuis'
comment_aheuis = target == 'asm+comment'
elif target == 'run':
output = '-'
Expand Down
1 change: 1 addition & 0 deletions aheui/warning.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def format(self, *args):


WARNING_LIST = [
Warning(b'no-rpython', b"[Warning:VirtualMachine] Running without rlib/jit.\n"),
Warning(b'write-utf8-range', b'[Warning:UndefinedBehavior:write-utf8-range] value %x is out of unicode codepoint range.'),
]

Expand Down
2 changes: 1 addition & 1 deletion ahsembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

def entry_point(argv):
from aheui.aheui import entry_point
return entry_point(argv + ['--target=asm', '--output=-'])
return entry_point(argv + ['--target=asm+comment'])


def target(*args):
Expand Down
15 changes: 15 additions & 0 deletions bin/ahsembler
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env python


def entry_point(argv):
from aheui.aheui import entry_point
return entry_point(argv + ['--target=asm+comment'])


def target(*args):
return entry_point, None


if __name__ == '__main__':
import sys
entry_point(sys.argv)
9 changes: 4 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ def get_readme():
author='Jeong YunWon',
author_email='aheui@youknowone.org',
url='https://github.com/aheui/rpaheui',
packages=(
packages=[
'aheui',
'aheui/int',
),
],
package_data={
'aheui': ['version.py']
},
Expand All @@ -45,6 +45,7 @@ def get_readme():
scripts=[
'bin/aheui-py',
'bin/aheui',
'bin/ahsembler',
],
classifiers=[
'Intended Audience :: Developers',
Expand All @@ -53,8 +54,6 @@ def get_readme():
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.12',
],
)
2 changes: 1 addition & 1 deletion snippets
Submodule snippets updated 1 files
+2 −2 test.sh
14 changes: 14 additions & 0 deletions tests/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ def test_targets():
assert list(map(lambda t: t[0], code1)) == list(map(lambda t: t[0], code3))


def test_optimize_push():
c1 = compile.Compiler()
c1.compile(u'밤희')
c1.optimize1()
asm1 = c1.write_asm()

c2 = compile.Compiler()
c2.compile(u'반반따희')
c2.optimize1()
asm2 = c2.write_asm()

assert asm1 == asm2


def test_optimize():
compiler = compile.Compiler()
compiler.compile(u'''상밢밢밣밦발받밧밥밣밦밦받밦밢밝받밝받밦밧밢받발받밧밣밦밥발받밝밥밧밦밦받밧받붑
Expand Down

0 comments on commit d11187e

Please sign in to comment.