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.0.tar.gz (34.0 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.0-cp311-abi3-win_arm64.whl (828.3 kB view details)

Uploaded CPython 3.11+Windows ARM64

johnnybt_dsl-0.1.0-cp311-abi3-win_amd64.whl (911.1 kB view details)

Uploaded CPython 3.11+Windows x86-64

johnnybt_dsl-0.1.0-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.0-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.0-cp311-abi3-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

johnnybt_dsl-0.1.0-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.0.tar.gz.

File metadata

  • Download URL: johnnybt_dsl-0.1.0.tar.gz
  • Upload date:
  • Size: 34.0 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.0.tar.gz
Algorithm Hash digest
SHA256 b53b1c4b8189f64292d793916d9589337950ccf9d477be2a94d49a0fe635eebc
MD5 aea9156f17bd80ab1efc3b38ad7796f5
BLAKE2b-256 646abc05147b0480290827dadbfb7f1ae5f64a06f69d7f9268f6e626c25c3ee4

See more details on using hashes here.

Provenance

The following attestation bundles were made for johnnybt_dsl-0.1.0.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.0-cp311-abi3-win_arm64.whl.

File metadata

  • Download URL: johnnybt_dsl-0.1.0-cp311-abi3-win_arm64.whl
  • Upload date:
  • Size: 828.3 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.0-cp311-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 15a3aad394970964e2d4f7dc0058ec075b0cd7cbb755bc89f21fbcfee429e5dd
MD5 14ffc80b962f08c1539351f6fe533e1d
BLAKE2b-256 e89c52afde5f8851fd8283666f1fc01b64741e2da42a2896b5cc77f757cbeeaa

See more details on using hashes here.

Provenance

The following attestation bundles were made for johnnybt_dsl-0.1.0-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.0-cp311-abi3-win_amd64.whl.

File metadata

  • Download URL: johnnybt_dsl-0.1.0-cp311-abi3-win_amd64.whl
  • Upload date:
  • Size: 911.1 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.0-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 05e3b55fb4957f43d45bf299be682d872ad0589b3dcb277d85312062e6a26d81
MD5 0f26ea4738d79e5191e705bf510ed94c
BLAKE2b-256 eceb3aae49dc52dd7819c38d45d8aad913f1d90ebc61f19b6cf3d4af362f7b1b

See more details on using hashes here.

Provenance

The following attestation bundles were made for johnnybt_dsl-0.1.0-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.0-cp311-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for johnnybt_dsl-0.1.0-cp311-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0dd6307bff1783927ccf22a3239c0879a2ffe61cd9ff2c93e1c47f3ad5120b2c
MD5 0c932e9e6d6638f85116dcfc091fd395
BLAKE2b-256 11a6ba3d3b9eac2a14b96e92a4be952c6ea473f63c41051b9fe73aa334db8fc8

See more details on using hashes here.

Provenance

The following attestation bundles were made for johnnybt_dsl-0.1.0-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.0-cp311-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for johnnybt_dsl-0.1.0-cp311-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 5f63e41c5b7d7f493dd9bfa65ffe1bf1d9f34012f8808a7a639354e1af5ac6a2
MD5 95e9b7bdbc2ad8d119bb273e348758d5
BLAKE2b-256 a0334f9bfc93cddbe5976966d3529ce64041c3f074fe5f3d4a8e593f944ba0dd

See more details on using hashes here.

Provenance

The following attestation bundles were made for johnnybt_dsl-0.1.0-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.0-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for johnnybt_dsl-0.1.0-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 af93e3b91fef49668fa48822d32b153a11aa0d0d1ad2570113dd65d13dad0086
MD5 038571899a8287d805e422d485da3018
BLAKE2b-256 8a456ec3922e5316db61c534fb37c076e0def6739abfcd0fa6999a98f09fb9e8

See more details on using hashes here.

Provenance

The following attestation bundles were made for johnnybt_dsl-0.1.0-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.0-cp311-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for johnnybt_dsl-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 a53351d585d7ae6caae67b2bf4c73d2aedc2a8d797876682fa9eef71929f938b
MD5 54ffee8ab90ba15aedea54bcdc653f94
BLAKE2b-256 b91037337efecf022c8fe528800309e19459fd40f47b4ea16264d3b4164f549a

See more details on using hashes here.

Provenance

The following attestation bundles were made for johnnybt_dsl-0.1.0-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

0.1.1

7 files

This release

0.1.0 This release

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