micalang 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. micalang-0.1.0/.github/workflows/ci.yml +23 -0
  2. micalang-0.1.0/.github/workflows/release.yml +33 -0
  3. micalang-0.1.0/.gitignore +14 -0
  4. micalang-0.1.0/CHANGELOG.md +23 -0
  5. micalang-0.1.0/CONTRIBUTING.md +33 -0
  6. micalang-0.1.0/LICENSE +202 -0
  7. micalang-0.1.0/NOTICE +4 -0
  8. micalang-0.1.0/PKG-INFO +123 -0
  9. micalang-0.1.0/README.md +97 -0
  10. micalang-0.1.0/README.zh-CN.md +93 -0
  11. micalang-0.1.0/SECURITY.md +23 -0
  12. micalang-0.1.0/demo/.env.example +4 -0
  13. micalang-0.1.0/demo/README.md +32 -0
  14. micalang-0.1.0/demo/main.py +344 -0
  15. micalang-0.1.0/demo/mock_server.py +149 -0
  16. micalang-0.1.0/docs/README.md +16 -0
  17. micalang-0.1.0/docs/architecture.zh-CN.md +96 -0
  18. micalang-0.1.0/docs/behind-the-scenes/README.md +18 -0
  19. micalang-0.1.0/docs/behind-the-scenes/ai-assisted-development.zh-CN.md +60 -0
  20. micalang-0.1.0/docs/behind-the-scenes/conversation.zh-CN.md +1156 -0
  21. micalang-0.1.0/docs/behind-the-scenes/origin.zh-CN.md +60 -0
  22. micalang-0.1.0/docs/design.zh-CN.md +95 -0
  23. micalang-0.1.0/docs/language-reference.zh-CN.md +174 -0
  24. micalang-0.1.0/docs/security.zh-CN.md +60 -0
  25. micalang-0.1.0/docs/stages/01-minimal-vm.zh-CN.md +302 -0
  26. micalang-0.1.0/docs/stages/02-real-engine.zh-CN.md +343 -0
  27. micalang-0.1.0/docs/stages/03-workspace.zh-CN.md +368 -0
  28. micalang-0.1.0/docs/stages/04-dict-and-ffi.zh-CN.md +326 -0
  29. micalang-0.1.0/docs/stages/05-security-and-usability.zh-CN.md +332 -0
  30. micalang-0.1.0/docs/stages/06-demo.zh-CN.md +202 -0
  31. micalang-0.1.0/docs/stages/README.md +64 -0
  32. micalang-0.1.0/examples/debug_sub_vm.mica +15 -0
  33. micalang-0.1.0/examples/dict.mica +20 -0
  34. micalang-0.1.0/examples/ffi.mica +21 -0
  35. micalang-0.1.0/examples/fib.mica +9 -0
  36. micalang-0.1.0/examples/for_finally.mica +27 -0
  37. micalang-0.1.0/examples/nested_vm.mica +11 -0
  38. micalang-0.1.0/examples/root.mica +4 -0
  39. micalang-0.1.0/examples/sub_vm.mica +9 -0
  40. micalang-0.1.0/examples/try_except.mica +27 -0
  41. micalang-0.1.0/examples/vfs.mica +11 -0
  42. micalang-0.1.0/pyproject.toml +42 -0
  43. micalang-0.1.0/src/mica/__init__.py +4 -0
  44. micalang-0.1.0/src/mica/__main__.py +5 -0
  45. micalang-0.1.0/src/mica/cli.py +54 -0
  46. micalang-0.1.0/src/mica/compiler.py +689 -0
  47. micalang-0.1.0/src/mica/engine.py +1497 -0
  48. micalang-0.1.0/src/mica/errors.py +34 -0
  49. micalang-0.1.0/src/mica/io.py +72 -0
  50. micalang-0.1.0/src/mica/isa.py +57 -0
  51. micalang-0.1.0/src/mica/vfs.py +78 -0
  52. micalang-0.1.0/tests/test_cli.py +42 -0
  53. micalang-0.1.0/tests/test_engine.py +182 -0
  54. micalang-0.1.0/tests/test_phase2.py +340 -0
  55. micalang-0.1.0/tests/test_phase3.py +335 -0
  56. micalang-0.1.0/tests/test_phase4.py +370 -0
  57. micalang-0.1.0/tests/test_phase5.py +620 -0
@@ -0,0 +1,23 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ jobs:
9
+ test:
10
+ runs-on: ubuntu-latest
11
+ strategy:
12
+ fail-fast: false
13
+ matrix:
14
+ python-version: ["3.12", "3.13", "3.14"]
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+ - uses: astral-sh/setup-uv@v6
18
+ with:
19
+ python-version: ${{ matrix.python-version }}
20
+ - run: uv sync
21
+ - run: uv run python -m unittest discover -s tests
22
+ - run: uv build
23
+ - run: uvx twine check dist/*
@@ -0,0 +1,33 @@
1
+ name: release
2
+
3
+ on:
4
+ push:
5
+ tags: ["v*"]
6
+
7
+ permissions:
8
+ contents: read
9
+
10
+ jobs:
11
+ build:
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+ - uses: astral-sh/setup-uv@v6
16
+ - run: uv build
17
+ - uses: actions/upload-artifact@v4
18
+ with:
19
+ name: dist
20
+ path: dist/
21
+
22
+ publish:
23
+ needs: build
24
+ runs-on: ubuntu-latest
25
+ environment: pypi
26
+ permissions:
27
+ id-token: write
28
+ steps:
29
+ - uses: actions/download-artifact@v4
30
+ with:
31
+ name: dist
32
+ path: dist/
33
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,14 @@
1
+ .venv/
2
+ .idea/
3
+ uv.lock
4
+ __pycache__/
5
+ *.py[cod]
6
+ .env
7
+ .env.*
8
+ !.env.example
9
+ dist/
10
+ build/
11
+ *.egg-info/
12
+ .pytest_cache/
13
+ .ruff_cache/
14
+ .DS_Store
@@ -0,0 +1,23 @@
1
+ # Changelog
2
+
3
+ 本项目的所有重要变更都会记录在此文件中。
4
+
5
+ 格式基于 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/),
6
+ 版本号遵循 [语义化版本](https://semver.org/lang/zh-CN/)。
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.1.0] - 未发布
11
+
12
+ 首次公开发布。构建过程见构建手记 `docs/stages/`(tag `stage-0`…`stage-6`)。
13
+
14
+ ### Added
15
+
16
+ - Mica-PY 参考实现:源码经白名单校验编译为内部指令流,由统一调度循环执行,不经 `exec`/`eval`。
17
+ - 语言:int/float/str/bool/None/list/dict;`if/while/for`、`break/continue`、`try/except/else/finally`、`raise`、三元表达式;函数、递归、默认参数与关键字实参。
18
+ - 嵌套 VM:任意层可创建子 VM,子 VM 不感知层深;父 VM 可预置文件、喂输入、单步调试、快照、终止。
19
+ - 能力授予(FFI):宿主向 root VM 注入函数,任意层 VM 向下一层授予函数;跨宿主边界双向深拷贝 + 纯数据类型白名单。
20
+ - 资源治理:指令数、输出字节、调用深度、子 VM 数量、嵌套深度、容器大小、字符串字节、整数位宽、近似内存总量、VM 总数、文件数与单文件字节配额;子 VM 消耗计入所有祖先。
21
+ - 每个 VM 自带私有虚拟文件系统(纯内存、纯文本)。
22
+ - 回归测试:198 个用例。
23
+ - demo:HTTP 能力授予 + 多层虚拟化的 LLM 代码执行示例(`demo` extra,含离线桩服务器)。
@@ -0,0 +1,33 @@
1
+ # 贡献指南
2
+
3
+ English readers: this project's development workflow is currently documented in Chinese. An English version is planned.
4
+
5
+ ## 开发环境
6
+
7
+ - Python ≥ 3.12,包管理用 [uv](https://docs.astral.sh/uv/)。
8
+ - 引擎本体零第三方依赖;`demo` 的依赖在 `pyproject.toml` 的 `demo` extra 里。
9
+
10
+ ## 验证
11
+
12
+ 修改引擎、编译器或脚本接口后,必须先运行回归套件:
13
+
14
+ ```bash
15
+ uv sync
16
+ uv run python -m unittest discover -s tests
17
+ ```
18
+
19
+ 仓库采用 `src/` 布局,直接运行 `python -m unittest` 前需要先安装本项目(`uv sync` 会自动处理)。
20
+
21
+ ## 设计纪律
22
+
23
+ - 理念问题以 [`docs/design.zh-CN.md`](docs/design.zh-CN.md) 为准。改理念先改它,不要在别处另造表述。
24
+ - 架构不变量见 [`docs/architecture.zh-CN.md`](docs/architecture.zh-CN.md)。新语法必须先过编译器白名单,禁止引入 `exec`/`eval`。
25
+ - 不给引擎加网络/设备等内建能力;能力的正确形态是 FFI 授予。安全边界见 [`docs/security.zh-CN.md`](docs/security.zh-CN.md)。
26
+
27
+ ## 文档流程
28
+
29
+ 本项目的说明性文档遵循一条规则:**AI 可以起草,入库前必须经作者人工打磨**。如果你提交的 PR 改动文档,请确保文本由人通读并修改过,而不是直接提交模型输出。
30
+
31
+ ## 提交信息
32
+
33
+ 使用中文,一句话说明这次提交做了什么,格式参考已有历史(如 `docs: 文档初始化——设计理念、语言参考与构建手记框架`)。
micalang-0.1.0/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
micalang-0.1.0/NOTICE ADDED
@@ -0,0 +1,4 @@
1
+ MicaLang
2
+ Copyright 2026 LeoLoudWarden
3
+
4
+ Licensed under the Apache License, Version 2.0.
@@ -0,0 +1,123 @@
1
+ Metadata-Version: 2.5
2
+ Name: micalang
3
+ Version: 0.1.0
4
+ Summary: Mica: a scripting language with cheap, arbitrarily nested VM isolation
5
+ Project-URL: Homepage, https://github.com/LeoLoudWarden/micalang
6
+ Project-URL: Repository, https://github.com/LeoLoudWarden/micalang
7
+ Project-URL: Issues, https://github.com/LeoLoudWarden/micalang/issues
8
+ Project-URL: Changelog, https://github.com/LeoLoudWarden/micalang/blob/main/CHANGELOG.md
9
+ Author: LeoLoudWarden
10
+ License-Expression: Apache-2.0
11
+ License-File: LICENSE
12
+ License-File: NOTICE
13
+ Keywords: interpreter,isolation,language,sandbox,scripting-language,virtual-machine
14
+ Classifier: Development Status :: 3 - Alpha
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Topic :: Software Development :: Interpreters
21
+ Requires-Python: >=3.12
22
+ Provides-Extra: demo
23
+ Requires-Dist: python-dotenv; extra == 'demo'
24
+ Requires-Dist: requests; extra == 'demo'
25
+ Description-Content-Type: text/markdown
26
+
27
+ # MicaLang
28
+
29
+ **Mica** is a scripting language and its execution engine, built around a single idea: creating a fully isolated, arbitrarily nestable runtime environment should be a cheap, first-class operation in the language itself.
30
+
31
+ Syntax borrows a subset of Python, but Mica source is compiled into Mica's own instruction stream and executed by the Mica engine — never through `exec`/`eval`. Every VM starts with zero capabilities: its own virtual IO, its own in-memory filesystem, and the ability to create child VMs. Everything else (network, host data, whatever you choose) is granted explicitly, layer by layer, through FFI.
32
+
33
+ [中文文档与项目说明](README.zh-CN.md)
34
+
35
+ ## Status
36
+
37
+ 0.1.0 prototype. The engine is a Python reference implementation (codename **Mica-PY**): zero runtime dependencies, Python ≥ 3.12, 198 regression tests. APIs and semantics may change before 1.0.
38
+
39
+ > **Security note.** Mica is designed for isolation, but the current prototype runs in the host process and has not been formally audited. Do not rely on it as the *only* boundary when executing adversarial code. See the [security model](docs/security.zh-CN.md) (中文) for exactly what is and is not guaranteed.
40
+
41
+ ## Install
42
+
43
+ ```bash
44
+ pip install micalang
45
+ ```
46
+
47
+ The distribution is named `micalang`; the import package is `mica`.
48
+
49
+ ## Quick start
50
+
51
+ As a CLI:
52
+
53
+ ```bash
54
+ printf 'print("hello from mica")\n' > hello.mica
55
+ micalang hello.mica # hello from mica
56
+ ```
57
+
58
+ Embedded in Python:
59
+
60
+ ```python
61
+ from mica import MicaEngine
62
+
63
+ engine = MicaEngine()
64
+ vm = engine.create_root("""
65
+ sub = VM("print('hello from a child VM')")
66
+ print(sub.run())
67
+ """)
68
+ print(vm.run(), end="")
69
+ ```
70
+
71
+ Grant a capability to a VM (FFI):
72
+
73
+ ```python
74
+ def double(x):
75
+ return x * 2
76
+
77
+ vm = engine.create_root("print(double(21))", functions={"double": double})
78
+ print(vm.run(), end="") # 42
79
+ ```
80
+
81
+ ## What a Mica VM is
82
+
83
+ A VM is a cheap, self-contained workspace:
84
+
85
+ - it cannot see its parent's variables, files, or handles, and cannot tell how deep it is nested;
86
+ - it has its own empty in-memory filesystem (text only — structurally unable to touch the real disk);
87
+ - resource quotas (instructions, memory, output, child VMs, nesting depth, …) can only be tightened, never loosened, and a child's consumption is charged to all its ancestors;
88
+ - its parent can preset files, feed input, single-step it statement by statement or instruction by instruction, snapshot its state, or terminate it;
89
+ - it can create its own child VMs — isolation is recursive, because untrusted code is.
90
+
91
+ ## Documentation
92
+
93
+ | Document | Language | Contents |
94
+ |---|---|---|
95
+ | [Design notes](docs/design.zh-CN.md) | 中文 | What Mica is, why it exists, where the boundaries are |
96
+ | [Language reference](docs/language-reference.zh-CN.md) | 中文 | The language subset and semantics, self-contained |
97
+ | [Architecture](docs/architecture.zh-CN.md) | 中文 | Engine structure, invariants, resource quotas |
98
+ | [Security model](docs/security.zh-CN.md) | 中文 | Threat model; what the engine does and does not guarantee |
99
+ | [Build journal](docs/stages/README.md) | 中文 | How Mica 0.1.0 was built, stage by stage, with runnable checkpoints (`git checkout stage-1` … `stage-6`) |
100
+ | [Behind the scenes](docs/behind-the-scenes/README.md) | 中文 | Origin story and how AI-assisted development was used |
101
+
102
+ An English documentation set is planned after 0.1.0.
103
+
104
+ ## How this project was built
105
+
106
+ Mica was developed with AI assistance throughout — design discussion, implementation, testing, adversarial review, and documentation drafting. What the AI did, what the author did, and how outputs were verified are documented in [AI-assisted development](docs/behind-the-scenes/ai-assisted-development.zh-CN.md) (中文), with selected conversation records alongside.
107
+
108
+ ## Roadmap
109
+
110
+ - List/dict/string methods and more ergonomic syntax
111
+ - Performance benchmarks (child-VM creation cost, per-instruction overhead)
112
+ - A normative language spec and a conformance test suite, so a future non-Python engine can be validated against them
113
+ - Evaluation of a native engine (the package name is language-level on purpose: `micalang` survives an engine rewrite)
114
+
115
+ ## The name
116
+
117
+ Mica (云母) is a layered mineral: it cleaves into thin sheets, each sheet complete in itself, and it is an insulator — layers do not conduct into each other. That is the shape of a Mica VM tree.
118
+
119
+ Not related to the Windows "Mica" UI material, the PyPI bioinformatics package MICA, or the (inactive) Rust scripting language named Mica.
120
+
121
+ ## License
122
+
123
+ [Apache-2.0](LICENSE) — see [NOTICE](NOTICE).
@@ -0,0 +1,97 @@
1
+ # MicaLang
2
+
3
+ **Mica** is a scripting language and its execution engine, built around a single idea: creating a fully isolated, arbitrarily nestable runtime environment should be a cheap, first-class operation in the language itself.
4
+
5
+ Syntax borrows a subset of Python, but Mica source is compiled into Mica's own instruction stream and executed by the Mica engine — never through `exec`/`eval`. Every VM starts with zero capabilities: its own virtual IO, its own in-memory filesystem, and the ability to create child VMs. Everything else (network, host data, whatever you choose) is granted explicitly, layer by layer, through FFI.
6
+
7
+ [中文文档与项目说明](README.zh-CN.md)
8
+
9
+ ## Status
10
+
11
+ 0.1.0 prototype. The engine is a Python reference implementation (codename **Mica-PY**): zero runtime dependencies, Python ≥ 3.12, 198 regression tests. APIs and semantics may change before 1.0.
12
+
13
+ > **Security note.** Mica is designed for isolation, but the current prototype runs in the host process and has not been formally audited. Do not rely on it as the *only* boundary when executing adversarial code. See the [security model](docs/security.zh-CN.md) (中文) for exactly what is and is not guaranteed.
14
+
15
+ ## Install
16
+
17
+ ```bash
18
+ pip install micalang
19
+ ```
20
+
21
+ The distribution is named `micalang`; the import package is `mica`.
22
+
23
+ ## Quick start
24
+
25
+ As a CLI:
26
+
27
+ ```bash
28
+ printf 'print("hello from mica")\n' > hello.mica
29
+ micalang hello.mica # hello from mica
30
+ ```
31
+
32
+ Embedded in Python:
33
+
34
+ ```python
35
+ from mica import MicaEngine
36
+
37
+ engine = MicaEngine()
38
+ vm = engine.create_root("""
39
+ sub = VM("print('hello from a child VM')")
40
+ print(sub.run())
41
+ """)
42
+ print(vm.run(), end="")
43
+ ```
44
+
45
+ Grant a capability to a VM (FFI):
46
+
47
+ ```python
48
+ def double(x):
49
+ return x * 2
50
+
51
+ vm = engine.create_root("print(double(21))", functions={"double": double})
52
+ print(vm.run(), end="") # 42
53
+ ```
54
+
55
+ ## What a Mica VM is
56
+
57
+ A VM is a cheap, self-contained workspace:
58
+
59
+ - it cannot see its parent's variables, files, or handles, and cannot tell how deep it is nested;
60
+ - it has its own empty in-memory filesystem (text only — structurally unable to touch the real disk);
61
+ - resource quotas (instructions, memory, output, child VMs, nesting depth, …) can only be tightened, never loosened, and a child's consumption is charged to all its ancestors;
62
+ - its parent can preset files, feed input, single-step it statement by statement or instruction by instruction, snapshot its state, or terminate it;
63
+ - it can create its own child VMs — isolation is recursive, because untrusted code is.
64
+
65
+ ## Documentation
66
+
67
+ | Document | Language | Contents |
68
+ |---|---|---|
69
+ | [Design notes](docs/design.zh-CN.md) | 中文 | What Mica is, why it exists, where the boundaries are |
70
+ | [Language reference](docs/language-reference.zh-CN.md) | 中文 | The language subset and semantics, self-contained |
71
+ | [Architecture](docs/architecture.zh-CN.md) | 中文 | Engine structure, invariants, resource quotas |
72
+ | [Security model](docs/security.zh-CN.md) | 中文 | Threat model; what the engine does and does not guarantee |
73
+ | [Build journal](docs/stages/README.md) | 中文 | How Mica 0.1.0 was built, stage by stage, with runnable checkpoints (`git checkout stage-1` … `stage-6`) |
74
+ | [Behind the scenes](docs/behind-the-scenes/README.md) | 中文 | Origin story and how AI-assisted development was used |
75
+
76
+ An English documentation set is planned after 0.1.0.
77
+
78
+ ## How this project was built
79
+
80
+ Mica was developed with AI assistance throughout — design discussion, implementation, testing, adversarial review, and documentation drafting. What the AI did, what the author did, and how outputs were verified are documented in [AI-assisted development](docs/behind-the-scenes/ai-assisted-development.zh-CN.md) (中文), with selected conversation records alongside.
81
+
82
+ ## Roadmap
83
+
84
+ - List/dict/string methods and more ergonomic syntax
85
+ - Performance benchmarks (child-VM creation cost, per-instruction overhead)
86
+ - A normative language spec and a conformance test suite, so a future non-Python engine can be validated against them
87
+ - Evaluation of a native engine (the package name is language-level on purpose: `micalang` survives an engine rewrite)
88
+
89
+ ## The name
90
+
91
+ Mica (云母) is a layered mineral: it cleaves into thin sheets, each sheet complete in itself, and it is an insulator — layers do not conduct into each other. That is the shape of a Mica VM tree.
92
+
93
+ Not related to the Windows "Mica" UI material, the PyPI bioinformatics package MICA, or the (inactive) Rust scripting language named Mica.
94
+
95
+ ## License
96
+
97
+ [Apache-2.0](LICENSE) — see [NOTICE](NOTICE).
@@ -0,0 +1,93 @@
1
+ # MicaLang
2
+
3
+ **Mica** 是一门脚本语言及其执行引擎,围绕一个想法构建:**创建一个完全隔离、可以任意嵌套的运行环境,应当是语言自身的一种廉价的第一类操作。**
4
+
5
+ 语法借用 Python 的一个子集,但 Mica 源码会被编译为 Mica 自己的指令流,由 Mica 引擎逐条执行——不经过 `exec`/`eval`。每台 VM 初始能力为零:独立的虚拟 IO、独立的内存文件系统、创建子 VM。其余一切能力(网络、宿主数据、任何你选择授予的东西)都通过 FFI 逐层显式授予。
6
+
7
+ ## 状态
8
+
9
+ 0.1.0 原型。引擎是 Python 参考实现(代号 **Mica-PY**):零运行时依赖,Python ≥ 3.12,198 个回归测试用例。1.0 之前 API 与语义可能变化。
10
+
11
+ > **安全提示。** Mica 为隔离而设计,但当前原型与宿主同进程运行,未经正式安全审计。执行对抗性代码时,不要把 Mica 当作**唯一**的隔离边界。引擎保证什么、不保证什么,见[安全模型](docs/security.zh-CN.md)。
12
+
13
+ ## 安装
14
+
15
+ ```bash
16
+ pip install micalang
17
+ ```
18
+
19
+ 发行包名为 `micalang`,导入包名为 `mica`。
20
+
21
+ ## 快速上手
22
+
23
+ 命令行:
24
+
25
+ ```bash
26
+ printf 'print("hello from mica")\n' > hello.mica
27
+ micalang hello.mica # hello from mica
28
+ ```
29
+
30
+ 嵌入 Python:
31
+
32
+ ```python
33
+ from mica import MicaEngine
34
+
35
+ engine = MicaEngine()
36
+ vm = engine.create_root("""
37
+ sub = VM("print('hello from a child VM')")
38
+ print(sub.run())
39
+ """)
40
+ print(vm.run(), end="")
41
+ ```
42
+
43
+ 向 VM 授予能力(FFI):
44
+
45
+ ```python
46
+ def double(x):
47
+ return x * 2
48
+
49
+ vm = engine.create_root("print(double(21))", functions={"double": double})
50
+ print(vm.run(), end="") # 42
51
+ ```
52
+
53
+ ## 一台 Mica VM 是什么
54
+
55
+ 一台廉价、自包含的工作空间:
56
+
57
+ - 看不到父级的变量、文件和句柄,也不知道自己嵌套在第几层;
58
+ - 有独立的空白内存文件系统(纯文本——结构上碰不到真实磁盘);
59
+ - 资源配额(指令、内存、输出、子 VM 数、嵌套深度……)只能收紧不能放宽,子 VM 的消耗计入所有祖先;
60
+ - 父级可以预置文件、喂输入、逐语句或逐指令单步、查看快照、随时终止;
61
+ - 它可以创建自己的子 VM——隔离是递归的,因为不可信的代码是递归的。
62
+
63
+ ## 文档
64
+
65
+ | 文档 | 内容 |
66
+ |---|---|
67
+ | [设计说明](docs/design.zh-CN.md) | Mica 是什么、为什么存在、边界划在哪里 |
68
+ | [语言参考](docs/language-reference.zh-CN.md) | 自完备的语言子集与语义 |
69
+ | [架构说明](docs/architecture.zh-CN.md) | 引擎结构、设计不变量、资源配额 |
70
+ | [安全模型](docs/security.zh-CN.md) | 威胁模型;引擎保证什么、不保证什么 |
71
+ | [构建手记](docs/stages/README.md) | Mica 0.1.0 逐阶段构建过程,含可运行检查点(`git checkout stage-1` … `stage-6`) |
72
+ | [幕后](docs/behind-the-scenes/README.md) | 项目由来与 AI 辅助开发过程 |
73
+
74
+ ## 这个项目是怎么写出来的
75
+
76
+ Mica 全程使用 AI 辅助开发——设计讨论、实现、测试、对抗性审查、文档起草。AI 做了什么、作者做了什么、产出如何被验证,记录在 [AI 辅助开发说明](docs/behind-the-scenes/ai-assisted-development.zh-CN.md),附开发对话选编。
77
+
78
+ ## 路线图
79
+
80
+ - 列表/字典/字符串方法与更多易用性语法
81
+ - 性能基准(子 VM 创建成本、每指令开销)
82
+ - 规范化的语言规范与一致性测试套件,供未来非 Python 引擎对照验证
83
+ - 原生引擎评估(包名刻意取语言级:`micalang` 在引擎重写后依然成立)
84
+
85
+ ## 名字
86
+
87
+ Mica(云母)是一种层状矿物:可以沿解理面剥成薄片,每一片都是完整的一层,且层间绝缘。这正是 Mica VM 树的形状。
88
+
89
+ 本项目与 Windows 的 Mica 界面材质、PyPI 上的生物信息学包 MICA、以及已停更的同名 Rust 脚本语言均无关。
90
+
91
+ ## 许可证
92
+
93
+ [Apache-2.0](LICENSE)——见 [NOTICE](NOTICE)。