Skip to main content

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),两个解释器同时编译会互相踩。所以 run / compile 用一把锁串 起来 —— 一次求值不到一毫秒,串行的代价远小于「错得莫名其妙」。

构建(只有我们要)

  • Rust、C 编译器
  • Ruby —— mruby 自己的 rake 要它(brew install ruby)。解析器是 Prism,不要 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-jsonmruby-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

johnnybt_dsl-0.1.1.tar.gz (34.5 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

johnnybt_dsl-0.1.1-cp311-abi3-win_arm64.whl (828.5 kB view details)

Uploaded CPython 3.11+Windows ARM64

johnnybt_dsl-0.1.1-cp311-abi3-win_amd64.whl (911.2 kB view details)

Uploaded CPython 3.11+Windows x86-64

johnnybt_dsl-0.1.1-cp311-abi3-manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.28+ x86-64

johnnybt_dsl-0.1.1-cp311-abi3-manylinux_2_28_aarch64.whl (1.2 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.28+ ARM64

johnnybt_dsl-0.1.1-cp311-abi3-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

johnnybt_dsl-0.1.1-cp311-abi3-macosx_10_12_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.11+macOS 10.12+ x86-64

File details

Details for the file johnnybt_dsl-0.1.1.tar.gz.

File metadata

  • Download URL: johnnybt_dsl-0.1.1.tar.gz
  • Upload date:
  • Size: 34.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for johnnybt_dsl-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9d62baf62c2d4ec87e32b28a71d612bcb098236d4583159c7f25379eac9c5277
MD5 f17416da8bd3e5fd4a6cba60b0a5942f
BLAKE2b-256 f031d711c8eb8f00a55fc29dbaf5867f332134023b8f58302c16453cc6066f68

See more details on using hashes here.

Provenance

The following attestation bundles were made for johnnybt_dsl-0.1.1.tar.gz:

Publisher: release.yml on quant-on-quest/johnnybt-dsl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file johnnybt_dsl-0.1.1-cp311-abi3-win_arm64.whl.

File metadata

  • Download URL: johnnybt_dsl-0.1.1-cp311-abi3-win_arm64.whl
  • Upload date:
  • Size: 828.5 kB
  • Tags: CPython 3.11+, Windows ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for johnnybt_dsl-0.1.1-cp311-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 638cc629feb45ef96e2848d46c173ae8185c19b50effd97225869c45d1d0b683
MD5 23a616f05e706ca95b4787961c7a5a2a
BLAKE2b-256 b5cc41a1f1713718e1a6204eb15deb3797c9588b28d01a2e6d816abe60fab460

See more details on using hashes here.

Provenance

The following attestation bundles were made for johnnybt_dsl-0.1.1-cp311-abi3-win_arm64.whl:

Publisher: release.yml on quant-on-quest/johnnybt-dsl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file johnnybt_dsl-0.1.1-cp311-abi3-win_amd64.whl.

File metadata

  • Download URL: johnnybt_dsl-0.1.1-cp311-abi3-win_amd64.whl
  • Upload date:
  • Size: 911.2 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

Hashes for johnnybt_dsl-0.1.1-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 79c06c54083ba33035838ea3917cae554e0edbe73e3f4e2d1a20c2c20556a30e
MD5 2f14ecebbb960481ea061c61c10f52d9
BLAKE2b-256 7575d459eb68674b1660ca57b52973887d11a0243ce0ebc05f8a04ee5917ed1c

See more details on using hashes here.

Provenance

The following attestation bundles were made for johnnybt_dsl-0.1.1-cp311-abi3-win_amd64.whl:

Publisher: release.yml on quant-on-quest/johnnybt-dsl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file johnnybt_dsl-0.1.1-cp311-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for johnnybt_dsl-0.1.1-cp311-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f993e55e0445469c3d449c7ffcdf303e9eabf59f51825059d77f7b176c943b2e
MD5 d6675b53c34081ee7f04f427652f463f
BLAKE2b-256 8edbbf71a4488f2c3c115c1e38446288f4e7d4e2580cdd791509e3d2b001e7c1

See more details on using hashes here.

Provenance

The following attestation bundles were made for johnnybt_dsl-0.1.1-cp311-abi3-manylinux_2_28_x86_64.whl:

Publisher: release.yml on quant-on-quest/johnnybt-dsl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file johnnybt_dsl-0.1.1-cp311-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for johnnybt_dsl-0.1.1-cp311-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 86df324a65298825cfecd5ddc98569ca8abb4e730fc539d59aab129047102f9b
MD5 127142f442000c6d73e57d629e34eae6
BLAKE2b-256 619b1c8fd2d7bbe7d5b52c3d98ef9e30bff352fa4d8cbb2ac68b3ddb9609f870

See more details on using hashes here.

Provenance

The following attestation bundles were made for johnnybt_dsl-0.1.1-cp311-abi3-manylinux_2_28_aarch64.whl:

Publisher: release.yml on quant-on-quest/johnnybt-dsl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file johnnybt_dsl-0.1.1-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for johnnybt_dsl-0.1.1-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5132658fce36dad74976d2e591c6ad651ad90e828a9785560a57b572d70e206a
MD5 4bea4813567552410d7b9906183c1595
BLAKE2b-256 a3aff01427920cf08a43a7ba8390bfd4e32bac5ca267a9adcbb8e85840341575

See more details on using hashes here.

Provenance

The following attestation bundles were made for johnnybt_dsl-0.1.1-cp311-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on quant-on-quest/johnnybt-dsl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file johnnybt_dsl-0.1.1-cp311-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for johnnybt_dsl-0.1.1-cp311-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 6ba3b717ec98dbe49db85f6a1c5015b09f4f78e8fa6b107ed866d510e0bee3ad
MD5 b0b3331d496da35dd79077c24adadba5
BLAKE2b-256 dadb2dc7262ba3bbb0785caa54f2b2eb2e2dbf89dabc4abef5b022af8303131e

See more details on using hashes here.

Provenance

The following attestation bundles were made for johnnybt_dsl-0.1.1-cp311-abi3-macosx_10_12_x86_64.whl:

Publisher: release.yml on quant-on-quest/johnnybt-dsl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.1.2

7 files

This release

0.1.1 This release

7 files

0.1.0

7 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page