From cc0c44abdad2564fc93bca1e61ab5310cf5e7da0 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Fri, 5 Apr 2024 15:25:59 +0900 Subject: [PATCH 1/7] =?UTF-8?q?rpython=20=EA=B2=BD=EA=B3=A0=20warnings=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aheui/_compat.py | 3 --- aheui/aheui.py | 4 +++- aheui/warning.py | 1 + 3 files changed, 4 insertions(+), 4 deletions(-) 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..b2276c8 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 @@ -493,6 +493,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/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.'), ] From c98fbbb50effd841758579048bbfc2aca4e6ceff Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Fri, 5 Apr 2024 15:26:30 +0900 Subject: [PATCH 2/7] =?UTF-8?q?asm+comment=20target=20=EC=82=B4=EB=A6=AC?= =?UTF-8?q?=EA=B3=A0=20'-'=20output=20=EC=B2=98=EB=A6=AC=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aheui/option.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/aheui/option.py b/aheui/option.py index ed214e5..676dec0 100644 --- a/aheui/option.py +++ b/aheui/option.py @@ -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` @@ -131,10 +131,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 = '-' From 915d5218efe107afeb21e9f64f1322e1e895a9b5 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Fri, 5 Apr 2024 16:37:52 +0900 Subject: [PATCH 3/7] =?UTF-8?q?=EC=95=9F=EC=85=88=EB=B8=94=EB=9F=AC?= =?UTF-8?q?=EB=8F=84=20=ED=95=A8=EA=BB=98=20=EB=B0=B0=ED=8F=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 8 +++++++- ahsembler.py | 2 +- bin/ahsembler | 15 +++++++++++++++ setup.py | 5 +++-- 4 files changed, 26 insertions(+), 4 deletions(-) create mode 100755 bin/ahsembler 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/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..1813f43 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', From 5b77e55213365e0dcb3bcc1bb1641668a3730dad Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Fri, 5 Apr 2024 17:29:42 +0900 Subject: [PATCH 4/7] =?UTF-8?q?push=20=EB=B3=91=ED=95=A9=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_compile.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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'''상밢밢밣밦발받밧밥밣밦밦받밦밢밝받밝받밦밧밢받발받밧밣밦밥발받밝밥밧밦밦받밧받붑 From fcc05ade5db2f107cd3ae9baa0f1d18c79982666 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Fri, 5 Apr 2024 17:53:17 +0900 Subject: [PATCH 5/7] =?UTF-8?q?Python3=20-c=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aheui/aheui.py | 3 ++- aheui/option.py | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/aheui/aheui.py b/aheui/aheui.py index b2276c8..e399dda 100644 --- a/aheui/aheui.py +++ b/aheui/aheui.py @@ -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 diff --git a/aheui/option.py b/aheui/option.py index 676dec0..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 @@ -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' From 288aabfe3e0f76a1b06d6379a43fad3be22e96a4 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Fri, 5 Apr 2024 17:53:29 +0900 Subject: [PATCH 6/7] classifier --- setup.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 1813f43..7c22fc7 100644 --- a/setup.py +++ b/setup.py @@ -54,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', ], ) From a455400c293b20f14be962323764ede70212cb60 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Fri, 5 Apr 2024 17:02:43 +0900 Subject: [PATCH 7/7] Add pypy2 test --- .github/workflows/ci.yaml | 12 +++++++++--- snippets | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) 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/snippets b/snippets index 762e061..64ef571 160000 --- a/snippets +++ b/snippets @@ -1 +1 @@ -Subproject commit 762e06192b2f341df6d9f7fc6750a74bd28aa4b7 +Subproject commit 64ef5719fadea2e5798c989945230339be0b929d