kyn-lang 1.0.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.
- kyn_lang-1.0.0/LICENSE +21 -0
- kyn_lang-1.0.0/PKG-INFO +132 -0
- kyn_lang-1.0.0/README.md +89 -0
- kyn_lang-1.0.0/kyn/__init__.py +653 -0
- kyn_lang-1.0.0/kyn/__main__.py +21 -0
- kyn_lang-1.0.0/kyn/_version.py +22 -0
- kyn_lang-1.0.0/kyn/ai.py +595 -0
- kyn_lang-1.0.0/kyn/bench.py +454 -0
- kyn_lang-1.0.0/kyn/cache.py +686 -0
- kyn_lang-1.0.0/kyn/cli.py +1165 -0
- kyn_lang-1.0.0/kyn/crypto.py +740 -0
- kyn_lang-1.0.0/kyn/crypto_aead.py +209 -0
- kyn_lang-1.0.0/kyn/dataframe.py +662 -0
- kyn_lang-1.0.0/kyn/db_vn.py +113 -0
- kyn_lang-1.0.0/kyn/diagnostics.py +295 -0
- kyn_lang-1.0.0/kyn/doctor.py +344 -0
- kyn_lang-1.0.0/kyn/fixes.py +1429 -0
- kyn_lang-1.0.0/kyn/formatter.py +451 -0
- kyn_lang-1.0.0/kyn/graph_vn.py +124 -0
- kyn_lang-1.0.0/kyn/gui.py +452 -0
- kyn_lang-1.0.0/kyn/html_exporter.py +542 -0
- kyn_lang-1.0.0/kyn/importer.py +301 -0
- kyn_lang-1.0.0/kyn/lexicon.py +843 -0
- kyn_lang-1.0.0/kyn/lexicon_data.json +1456 -0
- kyn_lang-1.0.0/kyn/lexicon_data.toml +1331 -0
- kyn_lang-1.0.0/kyn/lexicon_files/algorithms.json +169 -0
- kyn_lang-1.0.0/kyn/lexicon_files/asyncio.json +148 -0
- kyn_lang-1.0.0/kyn/lexicon_files/collections.json +705 -0
- kyn_lang-1.0.0/kyn/lexicon_files/core.json +3131 -0
- kyn_lang-1.0.0/kyn/lexicon_files/database.json +229 -0
- kyn_lang-1.0.0/kyn/lexicon_files/en.json +78 -0
- kyn_lang-1.0.0/kyn/lexicon_files/exceptions.json +1078 -0
- kyn_lang-1.0.0/kyn/lexicon_files/extra.json +1612 -0
- kyn_lang-1.0.0/kyn/lexicon_files/grammar.json +5977 -0
- kyn_lang-1.0.0/kyn/lexicon_files/logging.json +187 -0
- kyn_lang-1.0.0/kyn/lexicon_files/math.json +940 -0
- kyn_lang-1.0.0/kyn/lexicon_files/network.json +198 -0
- kyn_lang-1.0.0/kyn/lexicon_files/operators.json +475 -0
- kyn_lang-1.0.0/kyn/lexicon_files/pathlib.json +355 -0
- kyn_lang-1.0.0/kyn/lexicon_files/stdlib.json +6461 -0
- kyn_lang-1.0.0/kyn/lexicon_files/str.json +727 -0
- kyn_lang-1.0.0/kyn/lexicon_files/system.json +210 -0
- kyn_lang-1.0.0/kyn/lexicon_files/threading.json +147 -0
- kyn_lang-1.0.0/kyn/lexicon_files/typing.json +197 -0
- kyn_lang-1.0.0/kyn/lexicon_files/utilities.json +222 -0
- kyn_lang-1.0.0/kyn/linter.py +661 -0
- kyn_lang-1.0.0/kyn/lsp.py +646 -0
- kyn_lang-1.0.0/kyn/ml/__init__.py +366 -0
- kyn_lang-1.0.0/kyn/ml/activations.py +160 -0
- kyn_lang-1.0.0/kyn/ml/advanced.py +722 -0
- kyn_lang-1.0.0/kyn/ml/backend.py +480 -0
- kyn_lang-1.0.0/kyn/ml/classical.py +1318 -0
- kyn_lang-1.0.0/kyn/ml/data.py +744 -0
- kyn_lang-1.0.0/kyn/ml/gradcheck.py +152 -0
- kyn_lang-1.0.0/kyn/ml/llm.py +289 -0
- kyn_lang-1.0.0/kyn/ml/losses.py +467 -0
- kyn_lang-1.0.0/kyn/ml/metrics.py +277 -0
- kyn_lang-1.0.0/kyn/ml/metrics_extra.py +57 -0
- kyn_lang-1.0.0/kyn/ml/nn.py +1710 -0
- kyn_lang-1.0.0/kyn/ml/optim.py +788 -0
- kyn_lang-1.0.0/kyn/ml/random.py +95 -0
- kyn_lang-1.0.0/kyn/ml/serialization.py +554 -0
- kyn_lang-1.0.0/kyn/ml/tensor.py +2170 -0
- kyn_lang-1.0.0/kyn/ml/trainer.py +572 -0
- kyn_lang-1.0.0/kyn/optimizer.py +324 -0
- kyn_lang-1.0.0/kyn/profiler.py +606 -0
- kyn_lang-1.0.0/kyn/py.typed +1 -0
- kyn_lang-1.0.0/kyn/regex_vn.py +62 -0
- kyn_lang-1.0.0/kyn/repl.py +250 -0
- kyn_lang-1.0.0/kyn/rules.py +1170 -0
- kyn_lang-1.0.0/kyn/runtime.py +691 -0
- kyn_lang-1.0.0/kyn/sandbox.py +348 -0
- kyn_lang-1.0.0/kyn/scaffold.py +106 -0
- kyn_lang-1.0.0/kyn/scope.py +190 -0
- kyn_lang-1.0.0/kyn/shield.py +413 -0
- kyn_lang-1.0.0/kyn/super_ast.py +380 -0
- kyn_lang-1.0.0/kyn/super_runtime.py +1185 -0
- kyn_lang-1.0.0/kyn/super_syntax.py +684 -0
- kyn_lang-1.0.0/kyn/tensor.py +621 -0
- kyn_lang-1.0.0/kyn/terminal.py +150 -0
- kyn_lang-1.0.0/kyn/transpiler.py +2041 -0
- kyn_lang-1.0.0/kyn/trie.py +270 -0
- kyn_lang-1.0.0/kyn/web_framework.py +399 -0
- kyn_lang-1.0.0/kyn/web_server.py +542 -0
- kyn_lang-1.0.0/kyn_lang.egg-info/PKG-INFO +132 -0
- kyn_lang-1.0.0/kyn_lang.egg-info/SOURCES.txt +133 -0
- kyn_lang-1.0.0/kyn_lang.egg-info/dependency_links.txt +1 -0
- kyn_lang-1.0.0/kyn_lang.egg-info/entry_points.txt +2 -0
- kyn_lang-1.0.0/kyn_lang.egg-info/requires.txt +14 -0
- kyn_lang-1.0.0/kyn_lang.egg-info/top_level.txt +1 -0
- kyn_lang-1.0.0/pyproject.toml +75 -0
- kyn_lang-1.0.0/setup.cfg +4 -0
- kyn_lang-1.0.0/tests/test_cache_hmac.py +194 -0
- kyn_lang-1.0.0/tests/test_cache_strict.py +93 -0
- kyn_lang-1.0.0/tests/test_cli_characterization.py +289 -0
- kyn_lang-1.0.0/tests/test_cross_translate.py +83 -0
- kyn_lang-1.0.0/tests/test_crypto.py +61 -0
- kyn_lang-1.0.0/tests/test_dataframe_and_cache.py +169 -0
- kyn_lang-1.0.0/tests/test_deep_audit_regressions.py +157 -0
- kyn_lang-1.0.0/tests/test_deep_edge_cases.py +130 -0
- kyn_lang-1.0.0/tests/test_engine_cli_regressions.py +312 -0
- kyn_lang-1.0.0/tests/test_extended_syntax.py +444 -0
- kyn_lang-1.0.0/tests/test_extended_syntax_edge_cases.py +238 -0
- kyn_lang-1.0.0/tests/test_fixes_mutable_global.py +100 -0
- kyn_lang-1.0.0/tests/test_golden.py +69 -0
- kyn_lang-1.0.0/tests/test_gui_and_export.py +173 -0
- kyn_lang-1.0.0/tests/test_legacy_contract.py +380 -0
- kyn_lang-1.0.0/tests/test_lexicon_and_trie.py +65 -0
- kyn_lang-1.0.0/tests/test_lexicon_vocabulary.py +289 -0
- kyn_lang-1.0.0/tests/test_linter_and_membership.py +435 -0
- kyn_lang-1.0.0/tests/test_linter_edge_cases.py +139 -0
- kyn_lang-1.0.0/tests/test_llm_contract.py +189 -0
- kyn_lang-1.0.0/tests/test_llm_live.py +43 -0
- kyn_lang-1.0.0/tests/test_lsp.py +238 -0
- kyn_lang-1.0.0/tests/test_ml_backend_numpy.py +160 -0
- kyn_lang-1.0.0/tests/test_ml_data_classical.py +234 -0
- kyn_lang-1.0.0/tests/test_ml_nn_training.py +283 -0
- kyn_lang-1.0.0/tests/test_ml_regressions.py +337 -0
- kyn_lang-1.0.0/tests/test_ml_serialization_advanced_llm.py +362 -0
- kyn_lang-1.0.0/tests/test_ml_tensor_autograd.py +221 -0
- kyn_lang-1.0.0/tests/test_real_world_algorithms_and_apps.py +185 -0
- kyn_lang-1.0.0/tests/test_release_and_modules.py +616 -0
- kyn_lang-1.0.0/tests/test_release_safety.py +417 -0
- kyn_lang-1.0.0/tests/test_runtime_and_tooling.py +175 -0
- kyn_lang-1.0.0/tests/test_shield_and_diagnostics.py +65 -0
- kyn_lang-1.0.0/tests/test_single_ml_packaging.py +85 -0
- kyn_lang-1.0.0/tests/test_stdlib_integration.py +311 -0
- kyn_lang-1.0.0/tests/test_transpiler_and_scope.py +71 -0
- kyn_lang-1.0.0/tests/test_transpiler_regressions.py +227 -0
- kyn_lang-1.0.0/tests/test_transpiler_stress.py +160 -0
- kyn_lang-1.0.0/tests/test_vietnamese_stdlib_aliases.py +246 -0
- kyn_lang-1.0.0/tests/test_vietnamese_syntax.py +263 -0
- kyn_lang-1.0.0/tests/test_vm_limits.py +179 -0
- kyn_lang-1.0.0/tests/test_vn_stdlib_modules.py +75 -0
- kyn_lang-1.0.0/tests/test_web_ide_security.py +173 -0
kyn_lang-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Khang
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
kyn_lang-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: kyn-lang
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Ngôn ngữ lập trình tiếng Việt hoàn chỉnh (Lexer, Parser, Bytecode Compiler, Stack VM độc lập & LSP) kèm Bridge song ngữ sang Python 3.10+
|
|
5
|
+
Author-email: Khang <tranhuykhang31032013@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/tranhuykhang31032013-koocbiet/Kyn
|
|
8
|
+
Project-URL: Repository, https://github.com/tranhuykhang31032013-koocbiet/Kyn
|
|
9
|
+
Project-URL: Documentation, https://github.com/tranhuykhang31032013-koocbiet/Kyn/blob/main/README.md
|
|
10
|
+
Project-URL: Changelog, https://github.com/tranhuykhang31032013-koocbiet/Kyn/blob/main/CHANGELOG.md
|
|
11
|
+
Project-URL: Bug Tracker, https://github.com/tranhuykhang31032013-koocbiet/Kyn/issues
|
|
12
|
+
Keywords: vietnamese,transpiler,python,compiler,interpreter,ml,lsp
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Education
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Natural Language :: Vietnamese
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
25
|
+
Classifier: Topic :: Software Development :: Compilers
|
|
26
|
+
Classifier: Topic :: Software Development :: Interpreters
|
|
27
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
28
|
+
Requires-Python: >=3.10
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
Provides-Extra: numpy
|
|
32
|
+
Requires-Dist: numpy>=1.26; extra == "numpy"
|
|
33
|
+
Provides-Extra: dev
|
|
34
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
35
|
+
Requires-Dist: hypothesis>=6.0; extra == "dev"
|
|
36
|
+
Requires-Dist: ruff>=0.4; extra == "dev"
|
|
37
|
+
Requires-Dist: mypy>=1.10; extra == "dev"
|
|
38
|
+
Provides-Extra: test
|
|
39
|
+
Requires-Dist: pytest>=8.0; extra == "test"
|
|
40
|
+
Requires-Dist: hypothesis>=6.0; extra == "test"
|
|
41
|
+
Requires-Dist: numpy>=1.26; extra == "test"
|
|
42
|
+
Dynamic: license-file
|
|
43
|
+
|
|
44
|
+
# Kyn v2.0.0
|
|
45
|
+
|
|
46
|
+
> **A sandboxed, polyglot, Python-ergonomic language that runs natively on Node.js, Browsers, and WebAssembly — featuring built-in step/memory budgets, Rust-style diagnostics, bidirectional human-language translation, and zero-install browser execution.**
|
|
47
|
+
|
|
48
|
+
[](https://github.com/tranhuykhang31032013-koocbiet/Kyn/actions/workflows/ci.yml)
|
|
49
|
+
[](https://github.com/tranhuykhang31032013-koocbiet/Kyn/actions/workflows/pages.yml)
|
|
50
|
+
[](https://www.npmjs.com/package/kyn-engine)
|
|
51
|
+
[](https://pypi.org/project/kyn-lang/)
|
|
52
|
+
[](./LICENSE)
|
|
53
|
+
|
|
54
|
+
**Live Playground (Zero-Install ESM + WASM):** [https://tranhuykhang31032013-koocbiet.github.io/Kyn/playground/](https://tranhuykhang31032013-koocbiet.github.io/Kyn/playground/)
|
|
55
|
+
**Docs:** [Language Spec](./docs/SPEC.md) · [Embedding Guide](./docs/EMBEDDING.md) · [Show HN & Deep-Dive](./docs/LAUNCH_SHOW_HN.md) · [Tiếng Việt](./README.vi.md)
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## Why Kyn?
|
|
60
|
+
|
|
61
|
+
Most embeddable scripting languages force a trade-off between ergonomics, safety, and portability. Kyn is built from scratch in pure ESM JavaScript with:
|
|
62
|
+
|
|
63
|
+
1. **Hardened Sandboxed VM (`--sandbox`, `--max-steps`, `--max-frames`, `--max-memory`):** Deterministic execution budgets prevent infinite loops, stack overflows, and OOM payloads (`E_MEMORY_LIMIT`) before crashing the host process.
|
|
64
|
+
2. **Zero-Dependency WebAssembly Compiler (`kyn wasm` / `--target wasm`):** Compiles numeric (`i32`/`f64`), loop (`for range` with step, `while`), recursive, array-buffer, logical (`and`/`or`), ternary, and `print` workloads directly to `.wasm` binaries without LLVM or Emscripten.
|
|
65
|
+
3. **Rust/Elm-Style Multi-Line Diagnostics & Optimizer:** Multi-line context code frames with caret spans, Levenshtein "did you mean" hints, automatic error-code tips, constant/comparison folding, null-coalescing folding, and peephole optimization (`--opt`).
|
|
66
|
+
4. **Polyglot Syntax & Bidirectional Translation (`vi` ↔ `en`):** Write Python-ergonomic code in English or Vietnamese (Unicode NFC/NFD-safe) and translate source files cleanly while preserving comments, strings, and dot-attributes.
|
|
67
|
+
5. **Runs Everywhere with Zero Python Dependency:** Execute on Node.js (`npx kyn-engine`), browsers, or `.wasm`. Need ML/Data Science? Install the optional `kyn-lang` Python & AI Bridge (`pip install kyn-lang`).
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## 30-Second Quickstart
|
|
72
|
+
|
|
73
|
+
### 1. Standalone Engine (`kyn-engine` on Node.js >= 18, no Python required)
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
# Run directly via npx or global install
|
|
77
|
+
npm install -g kyn-engine
|
|
78
|
+
kyn init my-app
|
|
79
|
+
kyn my-app/main.kyn
|
|
80
|
+
|
|
81
|
+
# Or run from source
|
|
82
|
+
node engine/cli.mjs init my-app
|
|
83
|
+
node engine/cli.mjs my-app/main.kyn
|
|
84
|
+
|
|
85
|
+
# Compile to WebAssembly (.wasm)
|
|
86
|
+
node engine/cli.mjs wasm demo_samples/demo_independent_engine.kyn -o app.wasm
|
|
87
|
+
|
|
88
|
+
# Run untrusted code safely with resource budgets
|
|
89
|
+
node engine/cli.mjs --sandbox --max-memory 67108864 --max-steps 5000000 my-app/main.kyn
|
|
90
|
+
|
|
91
|
+
# Lint, format, test, and switch diagnostic locale (en default, or vi)
|
|
92
|
+
node engine/cli.mjs lint my-app/main.kyn
|
|
93
|
+
node engine/cli.mjs --lang vi --help
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### 2. Optional Python & AI Bridge (`kyn-lang`)
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
pip install kyn-lang
|
|
100
|
+
kyn demo_samples/demo_ai_neural_net.kyn
|
|
101
|
+
kyn translate demo_samples/demo_modern_syntax.kyn --from vi --to en
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### 3. VS Code Extension
|
|
105
|
+
|
|
106
|
+
Open `editors/vscode/` in VS Code for bilingual TextMate syntax highlighting (`source.kyn`) and live JSON-RPC LSP integration (`diagnostics`, `completion`, `hover`, `definition`, `references`, `semanticTokens`).
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## Benchmarks
|
|
111
|
+
|
|
112
|
+
Measured with `node scripts/bench/run_bench.mjs --json` on **Node.js v18.20.4 (`linux x64`, `Intel(R) Xeon(R) Platinum 8481C`)** and **Python 3.11.2**, median of 7 runs after 3 warmups:
|
|
113
|
+
|
|
114
|
+
| Workload | Kyn WASM (`kyn wasm`) | Node.js V8 (JS) | Python 3.11 | Kyn Stack VM (step-metered) | Peak RSS / Heap |
|
|
115
|
+
|---|---:|---:|---:|---:|---:|
|
|
116
|
+
| `fib(25)` recursive | **`0.536 ms`** | `0.732 ms` | `8.07 ms` | `325.09 ms` (`5,462,673` steps) | `98.9 MB` / `16.6 MB` |
|
|
117
|
+
| `sum(range(900_000))` loop | **`0.299 ms`** | `0.612 ms` | `20.56 ms` | `477.80 ms` (`9,000,017` steps) | `95.7 MB` / `9.3 MB` |
|
|
118
|
+
|
|
119
|
+
Inline micro-benchmark (`node engine/cli.mjs bench --json`, `sum(i*i for i in range(10000))` BigInt): **`7.34 ms` median**.
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## Testing & Verification
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
npm test
|
|
127
|
+
python -m pytest -q
|
|
128
|
+
ruff check .
|
|
129
|
+
python scripts/build_single.py --check
|
|
130
|
+
python scripts/build_single_ml.py --check
|
|
131
|
+
node scripts/bench/run_bench.mjs --json
|
|
132
|
+
```
|
kyn_lang-1.0.0/README.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# Kyn v2.0.0
|
|
2
|
+
|
|
3
|
+
> **A sandboxed, polyglot, Python-ergonomic language that runs natively on Node.js, Browsers, and WebAssembly — featuring built-in step/memory budgets, Rust-style diagnostics, bidirectional human-language translation, and zero-install browser execution.**
|
|
4
|
+
|
|
5
|
+
[](https://github.com/tranhuykhang31032013-koocbiet/Kyn/actions/workflows/ci.yml)
|
|
6
|
+
[](https://github.com/tranhuykhang31032013-koocbiet/Kyn/actions/workflows/pages.yml)
|
|
7
|
+
[](https://www.npmjs.com/package/kyn-engine)
|
|
8
|
+
[](https://pypi.org/project/kyn-lang/)
|
|
9
|
+
[](./LICENSE)
|
|
10
|
+
|
|
11
|
+
**Live Playground (Zero-Install ESM + WASM):** [https://tranhuykhang31032013-koocbiet.github.io/Kyn/playground/](https://tranhuykhang31032013-koocbiet.github.io/Kyn/playground/)
|
|
12
|
+
**Docs:** [Language Spec](./docs/SPEC.md) · [Embedding Guide](./docs/EMBEDDING.md) · [Show HN & Deep-Dive](./docs/LAUNCH_SHOW_HN.md) · [Tiếng Việt](./README.vi.md)
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Why Kyn?
|
|
17
|
+
|
|
18
|
+
Most embeddable scripting languages force a trade-off between ergonomics, safety, and portability. Kyn is built from scratch in pure ESM JavaScript with:
|
|
19
|
+
|
|
20
|
+
1. **Hardened Sandboxed VM (`--sandbox`, `--max-steps`, `--max-frames`, `--max-memory`):** Deterministic execution budgets prevent infinite loops, stack overflows, and OOM payloads (`E_MEMORY_LIMIT`) before crashing the host process.
|
|
21
|
+
2. **Zero-Dependency WebAssembly Compiler (`kyn wasm` / `--target wasm`):** Compiles numeric (`i32`/`f64`), loop (`for range` with step, `while`), recursive, array-buffer, logical (`and`/`or`), ternary, and `print` workloads directly to `.wasm` binaries without LLVM or Emscripten.
|
|
22
|
+
3. **Rust/Elm-Style Multi-Line Diagnostics & Optimizer:** Multi-line context code frames with caret spans, Levenshtein "did you mean" hints, automatic error-code tips, constant/comparison folding, null-coalescing folding, and peephole optimization (`--opt`).
|
|
23
|
+
4. **Polyglot Syntax & Bidirectional Translation (`vi` ↔ `en`):** Write Python-ergonomic code in English or Vietnamese (Unicode NFC/NFD-safe) and translate source files cleanly while preserving comments, strings, and dot-attributes.
|
|
24
|
+
5. **Runs Everywhere with Zero Python Dependency:** Execute on Node.js (`npx kyn-engine`), browsers, or `.wasm`. Need ML/Data Science? Install the optional `kyn-lang` Python & AI Bridge (`pip install kyn-lang`).
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## 30-Second Quickstart
|
|
29
|
+
|
|
30
|
+
### 1. Standalone Engine (`kyn-engine` on Node.js >= 18, no Python required)
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
# Run directly via npx or global install
|
|
34
|
+
npm install -g kyn-engine
|
|
35
|
+
kyn init my-app
|
|
36
|
+
kyn my-app/main.kyn
|
|
37
|
+
|
|
38
|
+
# Or run from source
|
|
39
|
+
node engine/cli.mjs init my-app
|
|
40
|
+
node engine/cli.mjs my-app/main.kyn
|
|
41
|
+
|
|
42
|
+
# Compile to WebAssembly (.wasm)
|
|
43
|
+
node engine/cli.mjs wasm demo_samples/demo_independent_engine.kyn -o app.wasm
|
|
44
|
+
|
|
45
|
+
# Run untrusted code safely with resource budgets
|
|
46
|
+
node engine/cli.mjs --sandbox --max-memory 67108864 --max-steps 5000000 my-app/main.kyn
|
|
47
|
+
|
|
48
|
+
# Lint, format, test, and switch diagnostic locale (en default, or vi)
|
|
49
|
+
node engine/cli.mjs lint my-app/main.kyn
|
|
50
|
+
node engine/cli.mjs --lang vi --help
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### 2. Optional Python & AI Bridge (`kyn-lang`)
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
pip install kyn-lang
|
|
57
|
+
kyn demo_samples/demo_ai_neural_net.kyn
|
|
58
|
+
kyn translate demo_samples/demo_modern_syntax.kyn --from vi --to en
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### 3. VS Code Extension
|
|
62
|
+
|
|
63
|
+
Open `editors/vscode/` in VS Code for bilingual TextMate syntax highlighting (`source.kyn`) and live JSON-RPC LSP integration (`diagnostics`, `completion`, `hover`, `definition`, `references`, `semanticTokens`).
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## Benchmarks
|
|
68
|
+
|
|
69
|
+
Measured with `node scripts/bench/run_bench.mjs --json` on **Node.js v18.20.4 (`linux x64`, `Intel(R) Xeon(R) Platinum 8481C`)** and **Python 3.11.2**, median of 7 runs after 3 warmups:
|
|
70
|
+
|
|
71
|
+
| Workload | Kyn WASM (`kyn wasm`) | Node.js V8 (JS) | Python 3.11 | Kyn Stack VM (step-metered) | Peak RSS / Heap |
|
|
72
|
+
|---|---:|---:|---:|---:|---:|
|
|
73
|
+
| `fib(25)` recursive | **`0.536 ms`** | `0.732 ms` | `8.07 ms` | `325.09 ms` (`5,462,673` steps) | `98.9 MB` / `16.6 MB` |
|
|
74
|
+
| `sum(range(900_000))` loop | **`0.299 ms`** | `0.612 ms` | `20.56 ms` | `477.80 ms` (`9,000,017` steps) | `95.7 MB` / `9.3 MB` |
|
|
75
|
+
|
|
76
|
+
Inline micro-benchmark (`node engine/cli.mjs bench --json`, `sum(i*i for i in range(10000))` BigInt): **`7.34 ms` median**.
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## Testing & Verification
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
npm test
|
|
84
|
+
python -m pytest -q
|
|
85
|
+
ruff check .
|
|
86
|
+
python scripts/build_single.py --check
|
|
87
|
+
python scripts/build_single_ml.py --check
|
|
88
|
+
node scripts/bench/run_bench.mjs --json
|
|
89
|
+
```
|