diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a1ef5dc..1ddf9d3 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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 \ No newline at end of file + AHEUI="$GITHUB_WORKSPACE/rpaheui-bigint-c" ./test.sh diff --git a/Makefile b/Makefile index 14140da..46fa1e9 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 diff --git a/aheui/_compat.py b/aheui/_compat.py index cf7c0fd..b2d94ad 100644 --- a/aheui/_compat.py +++ b/aheui/_compat.py @@ -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) diff --git a/aheui/aheui.py b/aheui/aheui.py index dfd5d03..e399dda 100644 --- a/aheui/aheui.py +++ b/aheui/aheui.py @@ -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 @@ -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 @@ -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']: diff --git a/aheui/option.py b/aheui/option.py index ed214e5..aff6e5f 100644 --- a/aheui/option.py +++ b/aheui/option.py @@ -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 @@ -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` @@ -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 = '-' @@ -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' @@ -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 = '-' diff --git a/aheui/warning.py b/aheui/warning.py index cfe044c..e8f7265 100644 --- a/aheui/warning.py +++ b/aheui/warning.py @@ -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.'), ] diff --git a/ahsembler.py b/ahsembler.py index 8e1ea3c..6af4dc7 100755 --- a/ahsembler.py +++ b/ahsembler.py @@ -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): diff --git a/bin/ahsembler b/bin/ahsembler new file mode 100755 index 0000000..6af4dc7 --- /dev/null +++ b/bin/ahsembler @@ -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) diff --git a/setup.py b/setup.py index cea1792..7c22fc7 100644 --- a/setup.py +++ b/setup.py @@ -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'] }, @@ -45,6 +45,7 @@ def get_readme(): scripts=[ 'bin/aheui-py', 'bin/aheui', + 'bin/ahsembler', ], classifiers=[ 'Intended Audience :: Developers', @@ -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', ], ) diff --git a/snippets b/snippets index 762e061..64ef571 160000 --- a/snippets +++ b/snippets @@ -1 +1 @@ -Subproject commit 762e06192b2f341df6d9f7fc6750a74bd28aa4b7 +Subproject commit 64ef5719fadea2e5798c989945230339be0b929d diff --git a/tests/test_compile.py b/tests/test_compile.py index 8cc4465..2504a7c 100644 --- a/tests/test_compile.py +++ b/tests/test_compile.py @@ -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'''상밢밢밣밦발받밧밥밣밦밦받밦밢밝받밝받밦밧밢받발받밧밣밦밥발받밝밥밧밦밦받밧받붑