Skip to content

Commit

Permalink
Merge pull request #23 from aheui/ci-actions
Browse files Browse the repository at this point in the history
CI actions
  • Loading branch information
youknowone committed Mar 31, 2024
2 parents 280251c + 044078d commit 0fb41f3
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 25 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python package

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.12"]

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 2
submodules: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install -e '.[tests]'
- name: Lint with Ruff
run: |
ruff check .
- name: Test with snippets
run: |
pytest
- name: Test with pytest
run: |
cd snippets && AHEUI=../rpaheui.py ./test.sh --disable logo
- name: Codecov
run: bash <(curl -s https://codecov.io/bash)
3 changes: 2 additions & 1 deletion aheui/_argparse.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# flake8: noqa: E501

from __future__ import absolute_import

Expand Down Expand Up @@ -113,7 +114,7 @@ def parse_args(self, args):
import os
try:
return self._parse_args(args)
except HelpException as e:
except HelpException:
os.write(2, 'usage: %s [option] ... file\n\n' % self.kwargs.get('prog', args[0]))
for names, opt in self.arguments:
name = names[0] if names[0] == names[1] else ('%s,%s' % names[0:2])
Expand Down
2 changes: 1 addition & 1 deletion aheui/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def unichr(n): # not rpython but python3
ord3 = ord

def ord(n):
if type(n) == int:
if type(n) == int: # noqa: E721
return n
return ord3(n)

Expand Down
19 changes: 11 additions & 8 deletions aheui/aheui.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def get_location(pc, stackok, is_queue, program):
"""
op = program.get_op(pc)
val = ('_%d' % program.get_operand(pc)) if compile.OP_USEVAL[op] else ''
return "#%d(s%dq%d)_%s%s" % (pc, stackok, is_queue, compile.OP_NAMES[op].encode('utf-8'), val)
op_name = compile.OP_NAMES[op].encode('utf-8')
return "#%d(s%dq%d)_%s%s" % (pc, stackok, is_queue, op_name, val)


driver = jit.JitDriver(
Expand Down Expand Up @@ -241,8 +242,9 @@ def read_utf8(input_buffer=input_buffer):
buf = input_buffer.take(length)
if len(buf) == length:
try:
v = ord((buf).decode('utf-8')[0])
except:
decoded = buf.decode('utf-8')
v = ord(decoded[0])
except UnicodeDecodeError:
v = -1
else:
v = -1
Expand Down Expand Up @@ -286,7 +288,8 @@ def write_number(value):
@jit.dont_look_inside
def write_utf8(value):
if not (0 <= value < 0x110000):
os.write(errfp, b'[Warning] Undefined behavior: unicode %x out of range\n' % value)
msg = b'[Warning] Undefined behavior: unicode %x out of range\n' % value
os.write(errfp, msg)
value = 0xfffd
os.write(outfp, unichr(value).encode('utf-8'))

Expand All @@ -295,8 +298,8 @@ class Program(object):
_immutable_fields_ = ['labels[**]', 'opcodes[*]', 'values[*]', 'size']

def __init__(self, lines, label_map):
self.opcodes = [l[0] for l in lines]
self.values = [l[1] for l in lines]
self.opcodes = [line[0] for line in lines]
self.values = [line[1] for line in lines]
self.size = len(lines)
self.labels = label_map

Expand Down Expand Up @@ -507,7 +510,7 @@ def open_r(filename):
elif target == 'run':
output = '-'
else:
os.write(2, b'aheui: error: --target,-t must be one of "bytecode", "asm", "asm+comment", "run"\n')
os.write(2, b'aheui: error: --target,-t must be one of "bytecode", "asm", "asm+comment", "run"\n') # noqa: E501
raise SystemExit()

return cmd, source, contents, opt_level, target, aheuic_output, comment_aheuis, output
Expand Down Expand Up @@ -544,7 +547,7 @@ def prepare_compiler(contents, opt_level=2, source='code', aheuic_output=None, a
os.write(bfp, '\n\n')
os.write(bfp, asm)
os.close(bfp)
except:
except Exception:
pass
return compiler

Expand Down
22 changes: 15 additions & 7 deletions aheui/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
DIR_LEFT = -2


def padding(s, l, left=True):
spaces = u' ' * max(0, l - len(s))
padded = (s + spaces) if left else (spaces + s)
def padding(content, max_length, left=True):
spaces = u' ' * max(0, max_length - len(content))
padded = (content + spaces) if left else (spaces + content)
return padded


Expand Down Expand Up @@ -592,7 +592,9 @@ def optimize_order(self):
b3 = lines[ix + 1:f]
b4 = lines[f + 1:]
lines = b1 + b3 + b2 + b4
hints = hints[:i] + hints[ix + 1:f] + hints[i:ix + 1] + hints[f + 1:]
hints = (
hints[:i] + hints[ix + 1:f] + hints[i:ix + 1] + hints[f + 1:]
)
else:
"""
... | JMP->i(f) | ... JMP(i-1) | XXX(i) ... JMP(ix) | ...
Expand All @@ -612,7 +614,9 @@ def optimize_order(self):
b3 = lines[i:ix + 1]
b4 = lines[ix + 1:]
lines = b1 + b3 + b2 + b4
hints = hints[:f] + hints[i:ix + 1] + hints[f + 1:i] + hints[ix + 1:]
hints = (
hints[:f] + hints[i:ix + 1] + hints[f + 1:i] + hints[ix + 1:]
)
break
else:
break
Expand Down Expand Up @@ -798,7 +802,10 @@ def write_bytecode(self):
if op in c.OP_JUMPS:
val = self.label_map[val]
if val >= 0:
p_val = chr(val & 0xff) + chr((val & 0xff00) >> 8) + chr((val & 0xff0000) >> 16)
char1 = chr(val & 0xff)
char2 = chr((val & 0xff00) >> 8)
char3 = chr((val & 0xff0000) >> 16)
p_val = char1 + char2 + char3
else:
p_val = '\0\0\0'
if op < 0:
Expand Down Expand Up @@ -908,7 +915,8 @@ def read_asm(self, text):
lines.append((opcode, -1))
comments.append([comment])
except Exception:
os.write(2, b'parsing error: ln%d %s\n' % (len(lines), main.encode('utf-8')))
msg = b'parsing error: ln%d %s\n' % (len(lines), main.encode('utf-8'))
os.write(2, msg)
raise
self.lines = lines
self.label_map = {}
Expand Down
10 changes: 5 additions & 5 deletions aheui/const.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

# coding: utf-8
# flake8: noqa: E501

OP_REQSIZE = [0, 0, 2, 2, 2, 2, 1, 0, 1, 0, 1, 0, 2, 0, 1, 0, 2, 2, 0, 1, 1, 0, 0, 2, 1, 0]
OP_STACKDEL = [0, 0, 2, 2, 2, 2, 1, 0, 1, 0, 1, 0, 2, 0, 1, 0, 2, 2, 0, 1, 1, 0, 0, 0, 0, 0]
Expand All @@ -16,18 +16,18 @@
OP_MUL = 4 # ㄸ
OP_MOD = 5 # ㄹ
OP_POP = 6 # ㅁ
OP_PUSH= 7 # ㅂ
OP_PUSH = 7 # ㅂ
OP_DUP = 8 # ㅃ
OP_SEL = 9 # ㅅ
OP_MOV = 10 # ㅆ
OP_NONE= 11 # ㅇ
OP_NONE = 11 # ㅇ
OP_CMP = 12 # ㅈ
# ㅉ
OP_BRZ = 14
# ㅋ
OP_SUB = 16 # ㅌ
OP_SWAP= 17 # ㅍ
OP_HALT= 18 # ㅎ
OP_SWAP = 17 # ㅍ
OP_HALT = 18 # ㅎ

# end of primitive
OP_POPNUM = 19
Expand Down
2 changes: 1 addition & 1 deletion aheui/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = '1.2.2-20-gee8ab38'
VERSION = '1.2.3'
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def get_readme():


tests_require = [
'flake8', 'tox', 'pytest>=3.0.1',
'ruff', 'tox', 'pytest>=3.0.1',
]

setup(
Expand Down
2 changes: 1 addition & 1 deletion snippets

0 comments on commit 0fb41f3

Please sign in to comment.