rearranged Python part
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
# Build and distribution artifacts
|
||||
build/
|
||||
dist/
|
||||
*.egg-info/
|
||||
__pycache__/
|
||||
*.pyc
|
||||
|
||||
# Dynamically copied files at build time
|
||||
README.md
|
||||
clyx/*.clx
|
||||
@@ -0,0 +1 @@
|
||||
from .clyx import Clyx, repl, main
|
||||
@@ -10,6 +10,12 @@ try: import socket
|
||||
except: from deck.net import init_socket; from deck.input import input; socket = init_socket()
|
||||
|
||||
scriptdir = __file__.replace('\\', '/').rsplit('/', 1)[0] if ('/' in __file__ or '\\' in __file__) else '.'
|
||||
def _fpath(p1, p2):
|
||||
try: open(p1).close(); return p1
|
||||
except: return p2
|
||||
libpath = _fpath(f'{scriptdir}/lib.clx', f'{scriptdir}/../../lib.clx')
|
||||
replpath = _fpath(f'{scriptdir}/clyx_repl.clx', f'{scriptdir}/../../clyx_repl.clx')
|
||||
|
||||
|
||||
class Sock:
|
||||
def __init__(self, s): self.s = s
|
||||
@@ -61,7 +67,7 @@ class Clyx:
|
||||
'exp': lambda: self._stack.append(math.exp(float(self._stack.pop()))), 'log': lambda: self._stack.append(math.log(float(self._stack.pop())))
|
||||
}
|
||||
self.run('"::" [ next defw ] defw :: readf [ "r" fopen dup read swap close ] :: src [ readf i ]')
|
||||
self.run(f'"{scriptdir}/lib.clx" src' if libfname is None else (libfname + ' src'))
|
||||
self.run(f'"{libpath}" src' if libfname is None else (libfname + ' src'))
|
||||
|
||||
def _cmd_qset(self): i, v, x = self._stack.pop(), self._stack.pop(), self._stack.pop(); (v.pop(int(i)), v.insert(int(i), x)) if isinstance(v, list) else None; self._stack.append(v if isinstance(v, list) else None)
|
||||
def _exec_loop(self, c, b):
|
||||
@@ -117,6 +123,7 @@ def clyx(f):
|
||||
try: Clyx().run(open(f).read())
|
||||
except Exception as e: (sys.stderr.write(f'Error executing {f}: {e}\n'), sys.exit(1))
|
||||
|
||||
repl = lambda: clyx(f'{scriptdir}/clyx_repl.clx')
|
||||
repl = lambda: clyx(replpath)
|
||||
def main(): clyx(sys.argv[1] if len(sys.argv) > 1 else replpath)
|
||||
|
||||
if __name__ == '__main__': clyx(sys.argv[1] if len(sys.argv) > 1 else f'{scriptdir}/clyx_repl.clx')
|
||||
if __name__ == '__main__': main()
|
||||
@@ -0,0 +1,25 @@
|
||||
[build-system]
|
||||
requires = ["setuptools>=61.0.0"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "clyx"
|
||||
version = "0.1.0"
|
||||
description = "Clyx programming language interpreter"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.7"
|
||||
license = { text = "Public Domain" }
|
||||
classifiers = [
|
||||
"Programming Language :: Python :: 3",
|
||||
"License :: Public Domain",
|
||||
"Operating System :: OS Independent",
|
||||
]
|
||||
|
||||
[project.scripts]
|
||||
clyx = "clyx:main"
|
||||
|
||||
[tool.setuptools]
|
||||
packages = ["clyx"]
|
||||
|
||||
[tool.setuptools.package-data]
|
||||
clyx = ["*.clx"]
|
||||
@@ -0,0 +1,19 @@
|
||||
import os
|
||||
import shutil
|
||||
from setuptools import setup
|
||||
|
||||
pkg_dir = os.path.join(os.path.dirname(__file__), "clyx")
|
||||
parent_dir = os.path.join(os.path.dirname(__file__), "..")
|
||||
|
||||
for fname in ["lib.clx", "clyx_repl.clx"]:
|
||||
src = os.path.join(parent_dir, fname)
|
||||
dst = os.path.join(pkg_dir, fname)
|
||||
if os.path.exists(src):
|
||||
shutil.copy(src, dst)
|
||||
|
||||
readme_src = os.path.join(parent_dir, "README.md")
|
||||
readme_dst = os.path.join(os.path.dirname(__file__), "README.md")
|
||||
if os.path.exists(readme_src):
|
||||
shutil.copy(readme_src, readme_dst)
|
||||
|
||||
setup()
|
||||
+1
-1
@@ -5,5 +5,5 @@
|
||||
TARGET="$1"
|
||||
[ -z $TARGET ] && TARGET='dist/clyx_py/clyx'
|
||||
mkdir -p $TARGET
|
||||
cp clyx.py lib.clx clyx_repl.clx test.clx $TARGET/
|
||||
cp clyx-python/clyx/clyx.py lib.clx clyx_repl.clx test.clx $TARGET/
|
||||
echo "Distribution created at $TARGET"
|
||||
|
||||
Reference in New Issue
Block a user