Skip to content

Commit

Permalink
bigint/smallint 다중 빌드
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowone committed Apr 4, 2024
1 parent d7decf4 commit e71b05d
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 25 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ jobs:
run: |
export RPYTHON="pypy $GITHUB_WORKSPACE/pypy/rpython/bin/rpython"
cd $GITHUB_WORKSPACE
make
make -j 3
- name: Test with snippets
run: |
cd "$GITHUB_WORKSPACE/snippets"
AHEUI="$GITHUB_WORKSPACE/rpaheui-c" ./test.sh --disable logo integer
AHEUI="$GITHUB_WORKSPACE/rpaheui-c" ./test.sh --disable integer
AHEUI="$GITHUB_WORKSPACE/rpaheui-bigint-c" ./test.sh
27 changes: 16 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,35 @@ RPYTHON?=../pypy/rpython/bin/rpython
RPYTHONFLAGS?=--opt=jit


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

version:
echo "VERSION = '`git describe --tags`'" > aheui/version.py

aheui-py:
aheui-py: version
cp rpaheui.py bin/aheui-py
cp rpaheui.py bin/aheui

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

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

clean:
rm rpaheui-c
rm rpaheui-smallint rpaheui-bigint

install: aheui-c
cp rpaheui-c /usr/local/bin/rpaheui
cp rpaheui-bigint /usr/local/bin/rpaheui-bigint
cp rpaheui-smallint /usr/local/bin/rpaheui
ln -s /usr/local/bin/rpaheui /usr/local/bin/aheui

test:
if [ -e snippets ]; then cd snippets && git pull; else git clone https://github.com/aheui/snippets; fi
cd snippets && AHEUI="../rpaheui-c" bash test.sh
test-bigint:
cd snippets && AHEUI="../rpaheui-bigint-c" bash test.sh

test-smallint:
cd snippets && AHEUI="../rpaheui-c" bash test.sh --disable integer

testpy:
test-py:
pytest
if [ -e snippets ]; then cd snippets && git pull; else git clone https://github.com/aheui/snippets; fi
cd snippets && AHEUI=../rpaheui.py bash test.sh
cd snippets && AHEUI=../bin/aheui bash test.sh --disable logo
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
```
git clone https://github.com/aheui/rpaheui
make # RPYTHON 환경변수 설정 필요. rpython은 pypy 소스코드를 내려받으면 포함되어 있습니다. 버전은 github actions 설정을 참고해 주세요.
./aheui-c <your-aheui-code>
./aheui-c <아희 코드 파일>
./aheui-bigint-c <큰 정수가 필요한 아희 코드 파일>
```

JIT로 속도 올리기
Expand Down
40 changes: 37 additions & 3 deletions aheui/_compat.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@

# coding: utf-8
from __future__ import absolute_import
import os


try:
from rpython.rlib import jit
from rpython.rlib.listsort import TimSort
TRACE_LIMIT = jit.PARAMETERS['trace_limit']

PYR = True
PY2 = False
PY3 = False
PY = -1

try:
USE_BIGINT = os.environ["RPAHEUI_BIGINT"]
except (KeyError, ValueError):
USE_BIGINT = ''

except ImportError:
"""Python compatibility."""
# Python compatibility

import sys

PY = sys.version_info.major
PYR = False
PY2 = PY == 2
PY3 = PY == 3

USE_BIGINT = False

def omnipotent(*args, **kw):
return args and args[0]

Expand Down Expand Up @@ -61,3 +83,15 @@ def _unicode(i):
def _unicode(i):
return u'%d' % i
_unicode(0)


try:
USE_BIGINT = os.environ["RPAHEUI_BIGINT"]
except (KeyError, ValueError):
USE_BIGINT = ''


if USE_BIGINT:
from aheui.int import bigint # Enable bigint in rpython build
else:
from aheui.int import smallint as bigint # noqa; smallint or python support
6 changes: 2 additions & 4 deletions aheui/aheui.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
import os

from aheui import const as c
from aheui._compat import jit, unichr, ord, _unicode
from aheui._compat import jit, unichr, ord, _unicode, bigint
from aheui import compile
from aheui.int import smallint as bigint # import `bigint` to enable bigint
from aheui.option import process_options
from aheui.warning import WarningPool

Expand Down Expand Up @@ -441,7 +440,6 @@ def mainloop(program, debug):
return 0



def open_w(filename):
return os.open(filename, os.O_WRONLY | os.O_CREAT, 0o644)

Expand Down Expand Up @@ -483,7 +481,7 @@ def entry_point(argv):
cmd, source, contents, str_opt_level, target, aheuic_output, comment_aheuis, output, warning_limit, trace_limit = process_options(argv, os.environ)
except SystemExit:
return 1

warnings.limit = warning_limit
if trace_limit >= 0:
jit.set_param(driver, 'trace_limit', trace_limit)
Expand Down
3 changes: 3 additions & 0 deletions aheui/int/bigint.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
from rpython.rlib.rbigint import rbigint


NAME = 'bigint'


Int = rbigint


Expand Down
20 changes: 19 additions & 1 deletion aheui/int/smallint.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,75 @@
except ImportError: # python2
builtins = __builtins__

from aheui._compat import jit


NAME = 'smallint'


Int = int


@jit.elidable
def fromstr(s):
return int(s)


@jit.elidable
def fromint(v):
return v


@jit.elidable
def fromlong(v):
return v


@jit.elidable
def toint(v):
return v


@jit.elidable
def tolonglong(v):
return v


@jit.elidable
def add(r1, r2):
return r1 + r2


@jit.elidable
def sub(r1, r2):
return r1 - r2


@jit.elidable
def mul(r1, r2):
return r1 * r2


@jit.elidable
def div(r1, r2):
return r1 // r2


@jit.elidable
def mod(r1, r2):
return r1 % r2


@jit.elidable
def ge(r1, r2):
return r1 >= r2


@jit.elidable
def str(r):
return builtins.str(r).encode('utf-8')
return builtins.str(r)


@jit.elidable
def eq_int(r, i):
return r == i
4 changes: 2 additions & 2 deletions aheui/option.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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

Expand Down Expand Up @@ -32,11 +33,10 @@
parser.add_argument('--no-c', '--no-c', narg='0', default='no', description='Do not generate `.aheuic` file automatically.', full_description='\tWhat is .aheuic? https://github.com/aheui/snippets/commit/cbb5a12e7cd2db771538ab28dfbc9ad1ada86f35\n')
parser.add_argument('--warning-limit', '--warning-limit', default='', description='Set repetitive warning limit. '' fallbacks to environment variable `RPAHEUI_WARNING_LIMIT`. 0 means no warning. -1 means no limit. Default is 3.')
parser.add_argument('--trace-limit', '--trace-limit', default='', description='Set JIT trace limit. '' fallbacks to environment variable `RPAHEUI_TRACE_LIMIT`.')
parser.add_argument('--version', '-v', narg='-1', default='no', description='Show program version', message=VERSION)
parser.add_argument('--version', '-v', narg='-1', default='no', description='Show program version', message=b'%s %s' % (VERSION, bigint.NAME))
parser.add_argument('--help', '-h', narg='-1', default='no', description='Show this help text')



def kwarg_or_environ(kwargs, environ, arg_key, env_key):
if arg_key in kwargs and kwargs[arg_key] != '':
return (1, kwargs[arg_key])
Expand Down
2 changes: 1 addition & 1 deletion aheui/warning.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def __init__(self, name, message):

def format(self, *args):
return self.message % args


WARNING_LIST = [
Warning(b'write-utf8-range', b'[Warning:UndefinedBehavior:write-utf8-range] value %x is out of unicode codepoint range.'),
Expand Down

0 comments on commit e71b05d

Please sign in to comment.