johnnybt_dsl
一台装好的 mruby 虚拟机。跑几段 Ruby,取回它产出的那个字符串 —— 就这些。
from johnnybt_dsl import compile, run
words = compile(open("dsl.rb").read(), "dsl.rb") # 一个进程编一次
ir = run([(words, "dsl.rb"), (source, "策略.rb")], answer="MyDSL.result")
词是你自己的。 这个包不知道什么是策略、什么是因子,也不规定 IR 长什么样: 那都是拿它写 DSL 的项目说了算。写死一套词就成了只服务一个项目的库。
装上就能用:wheel 里 mruby 已经编好了,用的人不需要 GCC,也不需要 Ruby。 那两样只有我们构建 wheel 时才要。
安装
pip install johnnybt-dsl
预编译轮子,一个平台一个,abi3 绑 Python 3.11、覆盖 3.11–3.14:
| x86_64 | arm64 | |
|---|---|---|
| Linux | manylinux_2_28(glibc 2.28 及以上) | manylinux_2_28(glibc 2.28 及以上) |
| macOS | 10.12 及以上 | 11.0 及以上 |
| Windows | 有 | 有 |
linux 的门槛比同系的两个 polars 插件(2.17)高一档,是因为这个包要编 C:
mruby 的构建会跑它刚编出来的 mrbc,所以每一格都得在自己的架构上原生构建,
而 pypa 提供原生镜像的最老的一档是 glibc 2.28。
API
compile(source, name) -> bytes |
编成字节码。字节码和解释器无关,编一次到处 load |
run(chunks, answer, context) -> str |
按顺序跑几段(源码或字节码),再跑 answer,返回它的字符串。context 进全局变量 $johnny_context(惯例是 JSON,基类懒解析成 JohnnyBtDSL.context) |
run_file(path, before, answer) |
同上,最后一段读自文件 |
一次 run 一个解释器:一份文件定义的东西不会漏进下一份。几段之间共用一个
编译上下文,所以局部变量跨得过去 —— 它们像一段程序,不像几份互不相干的文件。
里面有什么
| 件 | 做什么 |
|---|---|
build.rs |
取 mruby(钉住某个 commit)、按 build_config.rb 编、链接 libmruby.a |
src/sys.rs |
mruby 的 C API,手写的 extern 声明。十来个函数,不用生成器 |
src/shim.c |
mruby 里是宏的那几个(mrb_test / mrb->exc)和编译入口的跳板 |
src/engine.rs |
解释器的生命周期,以及「跑几段、取一个字符串」 |
mrbgems/mruby-json/ |
我们自己的 gem:JSON.generate / #to_json / JSON.parse,双向都在 C 里(解析错误带字节位) |
mrbgems/mruby-dsl/ |
我们自己的 gem:JohnnyBtDSL::Base —— DSL 的基类(注册、declare、逐语句 trouble、manifest/ir 信封、JohnnyBtDSL.context)。词不在这里,词归定义语言的项目 |
一处 mruby 的实情
mruby 开发线上的 Prism 编译器带全局状态(mrc_init_presym 写一个文件级的
offset),两个解释器同时编译会互相踩。我们钉的是稳定版,它的解析器状态都在
mrb_parser_state 里、没有这个全局 —— 但 run / compile 那把锁留着:一次求值
不到一毫秒,串行的代价是零,而下次挪版本时谁都不用再想起这件事。
构建(只有我们要)
- Rust、C 编译器
- Ruby —— mruby 自己的 rake 要它(
brew install ruby)。解析器由parse.y生成,但生成好的y.tab.c随发布版一起来,不要 bison
构建走真 rake -m(并行):mruby 自带的 minirake 完全串行,316 个目标文件
一个一个编,32 核机器上要几分钟;rake -m 同一棵树 4 秒。没有 rake 时退回
minirake。vendor/mruby 不进 git,第一次 cargo build 自己取。
测试:vendor/mruby/build/host/bin/mruby mrbgems/run_tests.rb(gem 那侧)与
cargo test(引擎那侧)。
许可
本包 MIT(见 LICENSE)。wheel 里静态链接了 mruby(MIT,见 LICENSE-mruby,
版权归 mruby developers);两个 mrbgem(mruby-json、mruby-dsl)是本仓库自己写的,
同样 MIT。
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file johnnybt_dsl-0.1.2.tar.gz.
File metadata
- Download URL: johnnybt_dsl-0.1.2.tar.gz
- Upload date:
- Size: 35.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee117a7b359d0eff1f338dcfe34d84271998551fd5bd90146f669288379230e2
|
|
| MD5 |
8cc56e3ffb347d1bb9f01315ecacf9e2
|
|
| BLAKE2b-256 |
586abfd6e648212b8c9ca097a8bfc35ac9d7d7058635028ed448e5d384fe2f70
|
Provenance
The following attestation bundles were made for johnnybt_dsl-0.1.2.tar.gz:
Publisher:
release.yml on quant-on-quest/johnnybt-dsl
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
johnnybt_dsl-0.1.2.tar.gz -
Subject digest:
ee117a7b359d0eff1f338dcfe34d84271998551fd5bd90146f669288379230e2 - Sigstore transparency entry: 2788732620
- Sigstore integration time:
-
Permalink:
quant-on-quest/johnnybt-dsl@4e72d3d63311555fe80b2abc77615bba64e8c2f0 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/quant-on-quest
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4e72d3d63311555fe80b2abc77615bba64e8c2f0 -
Trigger Event:
push
-
Statement type:
File details
Details for the file johnnybt_dsl-0.1.2-cp311-abi3-win_arm64.whl.
File metadata
- Download URL: johnnybt_dsl-0.1.2-cp311-abi3-win_arm64.whl
- Upload date:
- Size: 578.1 kB
- Tags: CPython 3.11+, Windows ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
70d02f3099ab30c34bece2f39da70e497e9aa4def67414944c2c929922ac9bc4
|
|
| MD5 |
8669fef4d1a2946282c2841aff347276
|
|
| BLAKE2b-256 |
d5d138b5833f206b6d5ebdab7177a75e2e31825ab5f1182fc9e5592ef95e5606
|
Provenance
The following attestation bundles were made for johnnybt_dsl-0.1.2-cp311-abi3-win_arm64.whl:
Publisher:
release.yml on quant-on-quest/johnnybt-dsl
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
johnnybt_dsl-0.1.2-cp311-abi3-win_arm64.whl -
Subject digest:
70d02f3099ab30c34bece2f39da70e497e9aa4def67414944c2c929922ac9bc4 - Sigstore transparency entry: 2788732923
- Sigstore integration time:
-
Permalink:
quant-on-quest/johnnybt-dsl@4e72d3d63311555fe80b2abc77615bba64e8c2f0 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/quant-on-quest
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4e72d3d63311555fe80b2abc77615bba64e8c2f0 -
Trigger Event:
push
-
Statement type:
File details
Details for the file johnnybt_dsl-0.1.2-cp311-abi3-win_amd64.whl.
File metadata
- Download URL: johnnybt_dsl-0.1.2-cp311-abi3-win_amd64.whl
- Upload date:
- Size: 638.8 kB
- Tags: CPython 3.11+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
12a3208fee0e3b12a0a68283c5e160d457533177d27b450a2e95c6c6ddce517d
|
|
| MD5 |
ec6604ad1eddc60d0b346511dbe68686
|
|
| BLAKE2b-256 |
527b277a155d754c634f6be1be9078c5f5bdcc8e98d3ef58f7c66e56a264e2ae
|
Provenance
The following attestation bundles were made for johnnybt_dsl-0.1.2-cp311-abi3-win_amd64.whl:
Publisher:
release.yml on quant-on-quest/johnnybt-dsl
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
johnnybt_dsl-0.1.2-cp311-abi3-win_amd64.whl -
Subject digest:
12a3208fee0e3b12a0a68283c5e160d457533177d27b450a2e95c6c6ddce517d - Sigstore transparency entry: 2788732822
- Sigstore integration time:
-
Permalink:
quant-on-quest/johnnybt-dsl@4e72d3d63311555fe80b2abc77615bba64e8c2f0 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/quant-on-quest
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4e72d3d63311555fe80b2abc77615bba64e8c2f0 -
Trigger Event:
push
-
Statement type:
File details
Details for the file johnnybt_dsl-0.1.2-cp311-abi3-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: johnnybt_dsl-0.1.2-cp311-abi3-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 838.7 kB
- Tags: CPython 3.11+, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
75695bec5f10c2cbcbc1cd3a402f7454556a4ad04ba29bee2396e9513ac03839
|
|
| MD5 |
cdbbcd854bd55106c3b879a93d0fa53e
|
|
| BLAKE2b-256 |
8a7c210272dc1fce224ccf2c06d9e42a553294edf342f6d8daf4002c10560ac0
|
Provenance
The following attestation bundles were made for johnnybt_dsl-0.1.2-cp311-abi3-manylinux_2_28_x86_64.whl:
Publisher:
release.yml on quant-on-quest/johnnybt-dsl
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
johnnybt_dsl-0.1.2-cp311-abi3-manylinux_2_28_x86_64.whl -
Subject digest:
75695bec5f10c2cbcbc1cd3a402f7454556a4ad04ba29bee2396e9513ac03839 - Sigstore transparency entry: 2788732756
- Sigstore integration time:
-
Permalink:
quant-on-quest/johnnybt-dsl@4e72d3d63311555fe80b2abc77615bba64e8c2f0 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/quant-on-quest
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4e72d3d63311555fe80b2abc77615bba64e8c2f0 -
Trigger Event:
push
-
Statement type:
File details
Details for the file johnnybt_dsl-0.1.2-cp311-abi3-manylinux_2_28_aarch64.whl.
File metadata
- Download URL: johnnybt_dsl-0.1.2-cp311-abi3-manylinux_2_28_aarch64.whl
- Upload date:
- Size: 841.4 kB
- Tags: CPython 3.11+, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a017481793231781d6a0f4ddd6c4bfa8fafdfc53abf9b3af352544f64a574f8a
|
|
| MD5 |
4c9fc382266b6335570aed4f66e30828
|
|
| BLAKE2b-256 |
417d600e3b662c3191534aa83c681aa90f04373074c27555a4b7b88aac3fbd02
|
Provenance
The following attestation bundles were made for johnnybt_dsl-0.1.2-cp311-abi3-manylinux_2_28_aarch64.whl:
Publisher:
release.yml on quant-on-quest/johnnybt-dsl
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
johnnybt_dsl-0.1.2-cp311-abi3-manylinux_2_28_aarch64.whl -
Subject digest:
a017481793231781d6a0f4ddd6c4bfa8fafdfc53abf9b3af352544f64a574f8a - Sigstore transparency entry: 2788732694
- Sigstore integration time:
-
Permalink:
quant-on-quest/johnnybt-dsl@4e72d3d63311555fe80b2abc77615bba64e8c2f0 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/quant-on-quest
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4e72d3d63311555fe80b2abc77615bba64e8c2f0 -
Trigger Event:
push
-
Statement type:
File details
Details for the file johnnybt_dsl-0.1.2-cp311-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: johnnybt_dsl-0.1.2-cp311-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 807.4 kB
- Tags: CPython 3.11+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5bd8d8e137203c03187b01afcaa91af687bd9a05b18749bea37f41b092c07ec7
|
|
| MD5 |
f5cf55556f7f96f6d155736a8634a8d8
|
|
| BLAKE2b-256 |
0c7266c59b5fce8c58d1a39e2ff38577cbcc7de6bc9e42ae31cfb8bc4fa56360
|
Provenance
The following attestation bundles were made for johnnybt_dsl-0.1.2-cp311-abi3-macosx_11_0_arm64.whl:
Publisher:
release.yml on quant-on-quest/johnnybt-dsl
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
johnnybt_dsl-0.1.2-cp311-abi3-macosx_11_0_arm64.whl -
Subject digest:
5bd8d8e137203c03187b01afcaa91af687bd9a05b18749bea37f41b092c07ec7 - Sigstore transparency entry: 2788732862
- Sigstore integration time:
-
Permalink:
quant-on-quest/johnnybt-dsl@4e72d3d63311555fe80b2abc77615bba64e8c2f0 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/quant-on-quest
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4e72d3d63311555fe80b2abc77615bba64e8c2f0 -
Trigger Event:
push
-
Statement type:
File details
Details for the file johnnybt_dsl-0.1.2-cp311-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: johnnybt_dsl-0.1.2-cp311-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 780.3 kB
- Tags: CPython 3.11+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8b5b5b9bd0d4090ea578ff0ec8371ccfb2534fd32fb375a8639d8f3bc2124899
|
|
| MD5 |
5d75d2ca9cfbea4a9a185476438c4ace
|
|
| BLAKE2b-256 |
009b9a55dbd043c2519f60223f50daff604e17ff34fdb62264688b974b4e1e53
|
Provenance
The following attestation bundles were made for johnnybt_dsl-0.1.2-cp311-abi3-macosx_10_12_x86_64.whl:
Publisher:
release.yml on quant-on-quest/johnnybt-dsl
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
johnnybt_dsl-0.1.2-cp311-abi3-macosx_10_12_x86_64.whl -
Subject digest:
8b5b5b9bd0d4090ea578ff0ec8371ccfb2534fd32fb375a8639d8f3bc2124899 - Sigstore transparency entry: 2788732962
- Sigstore integration time:
-
Permalink:
quant-on-quest/johnnybt-dsl@4e72d3d63311555fe80b2abc77615bba64e8c2f0 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/quant-on-quest
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4e72d3d63311555fe80b2abc77615bba64e8c2f0 -
Trigger Event:
push
-
Statement type: