@tishlang/tish-format 1.0.12 → 1.0.13
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.
- package/Cargo.toml +49 -0
- package/LICENSE +13 -0
- package/README.md +138 -0
- package/bin/tish-format +0 -0
- package/crates/js_to_tish/Cargo.toml +11 -0
- package/crates/js_to_tish/README.md +18 -0
- package/crates/js_to_tish/src/error.rs +55 -0
- package/crates/js_to_tish/src/lib.rs +11 -0
- package/crates/js_to_tish/src/span_util.rs +35 -0
- package/crates/js_to_tish/src/transform/expr.rs +610 -0
- package/crates/js_to_tish/src/transform/stmt.rs +503 -0
- package/crates/js_to_tish/src/transform.rs +60 -0
- package/crates/tish/Cargo.toml +54 -0
- package/crates/tish/src/cargo_native_registry.rs +32 -0
- package/crates/tish/src/cli_help.rs +565 -0
- package/crates/tish/src/main.rs +781 -0
- package/crates/tish/src/repl_completion.rs +200 -0
- package/crates/tish/tests/cargo_example_compile.rs +67 -0
- package/crates/tish/tests/fixtures/cargo_example_project/Cargo.toml +3 -0
- package/crates/tish/tests/fixtures/cargo_example_project/crates/demo-shim/Cargo.toml +11 -0
- package/crates/tish/tests/fixtures/cargo_example_project/crates/demo-shim/src/lib.rs +12 -0
- package/crates/tish/tests/fixtures/cargo_example_project/package.json +10 -0
- package/crates/tish/tests/fixtures/cargo_example_project/src/main.tish +3 -0
- package/crates/tish/tests/integration_test.rs +1095 -0
- package/crates/tish/tests/run_optimize_stdout_parity.rs +50 -0
- package/crates/tish/tests/shortcircuit.rs +65 -0
- package/crates/tish_ast/Cargo.toml +9 -0
- package/crates/tish_ast/src/ast.rs +620 -0
- package/crates/tish_ast/src/lib.rs +5 -0
- package/crates/tish_build_utils/Cargo.toml +11 -0
- package/crates/tish_build_utils/src/lib.rs +577 -0
- package/crates/tish_builtins/Cargo.toml +20 -0
- package/crates/tish_builtins/src/array.rs +441 -0
- package/crates/tish_builtins/src/construct.rs +159 -0
- package/crates/tish_builtins/src/globals.rs +213 -0
- package/crates/tish_builtins/src/helpers.rs +35 -0
- package/crates/tish_builtins/src/lib.rs +16 -0
- package/crates/tish_builtins/src/math.rs +89 -0
- package/crates/tish_builtins/src/object.rs +36 -0
- package/crates/tish_builtins/src/string.rs +647 -0
- package/crates/tish_builtins/src/symbol.rs +83 -0
- package/crates/tish_bytecode/Cargo.toml +17 -0
- package/crates/tish_bytecode/src/chunk.rs +96 -0
- package/crates/tish_bytecode/src/compiler.rs +1760 -0
- package/crates/tish_bytecode/src/encoding.rs +100 -0
- package/crates/tish_bytecode/src/lib.rs +19 -0
- package/crates/tish_bytecode/src/opcode.rs +142 -0
- package/crates/tish_bytecode/src/peephole.rs +189 -0
- package/crates/tish_bytecode/src/serialize.rs +163 -0
- package/crates/tish_bytecode/tests/break_continue_bytecode.rs +44 -0
- package/crates/tish_bytecode/tests/constant_folding.rs +84 -0
- package/crates/tish_bytecode/tests/sort_optimization.rs +31 -0
- package/crates/tish_compile/Cargo.toml +26 -0
- package/crates/tish_compile/src/codegen.rs +5332 -0
- package/crates/tish_compile/src/infer.rs +292 -0
- package/crates/tish_compile/src/lib.rs +164 -0
- package/crates/tish_compile/src/resolve.rs +1388 -0
- package/crates/tish_compile/src/types.rs +501 -0
- package/crates/tish_compile_js/Cargo.toml +18 -0
- package/crates/tish_compile_js/examples/jsx_vdom_smoke.tish +8 -0
- package/crates/tish_compile_js/src/codegen.rs +871 -0
- package/crates/tish_compile_js/src/error.rs +20 -0
- package/crates/tish_compile_js/src/lib.rs +26 -0
- package/crates/tish_compile_js/src/tests_jsx.rs +350 -0
- package/crates/tish_compiler_wasm/Cargo.toml +21 -0
- package/crates/tish_compiler_wasm/src/lib.rs +57 -0
- package/crates/tish_compiler_wasm/src/resolve_virtual.rs +473 -0
- package/crates/tish_core/Cargo.toml +26 -0
- package/crates/tish_core/src/console_style.rs +160 -0
- package/crates/tish_core/src/json.rs +387 -0
- package/crates/tish_core/src/lib.rs +17 -0
- package/crates/tish_core/src/macros.rs +36 -0
- package/crates/tish_core/src/uri.rs +118 -0
- package/crates/tish_core/src/value.rs +696 -0
- package/crates/tish_core/src/vmref.rs +178 -0
- package/crates/tish_cranelift/Cargo.toml +19 -0
- package/crates/tish_cranelift/src/lib.rs +43 -0
- package/crates/tish_cranelift/src/link.rs +117 -0
- package/crates/tish_cranelift/src/lower.rs +85 -0
- package/crates/tish_cranelift_runtime/Cargo.toml +25 -0
- package/crates/tish_cranelift_runtime/src/lib.rs +45 -0
- package/crates/tish_eval/Cargo.toml +45 -0
- package/crates/tish_eval/src/eval.rs +3717 -0
- package/crates/tish_eval/src/http.rs +188 -0
- package/crates/tish_eval/src/lib.rs +99 -0
- package/crates/tish_eval/src/natives.rs +399 -0
- package/crates/tish_eval/src/promise.rs +179 -0
- package/crates/tish_eval/src/regex.rs +299 -0
- package/crates/tish_eval/src/timers.rs +120 -0
- package/crates/tish_eval/src/value.rs +318 -0
- package/crates/tish_eval/src/value_convert.rs +111 -0
- package/crates/tish_fmt/Cargo.toml +16 -0
- package/crates/tish_fmt/src/bin/tish-fmt.rs +41 -0
- package/crates/tish_fmt/src/lib.rs +2101 -0
- package/crates/tish_jsx_web/Cargo.toml +9 -0
- package/crates/tish_jsx_web/README.md +5 -0
- package/crates/tish_jsx_web/src/lib.rs +2 -0
- package/crates/tish_lexer/Cargo.toml +9 -0
- package/crates/tish_lexer/src/lib.rs +716 -0
- package/crates/tish_lexer/src/token.rs +163 -0
- package/crates/tish_lint/Cargo.toml +18 -0
- package/crates/tish_lint/src/bin/tish-lint.rs +195 -0
- package/crates/tish_lint/src/lib.rs +289 -0
- package/crates/tish_llvm/Cargo.toml +13 -0
- package/crates/tish_llvm/src/lib.rs +115 -0
- package/crates/tish_lsp/Cargo.toml +25 -0
- package/crates/tish_lsp/README.md +26 -0
- package/crates/tish_lsp/src/builtin_goto.rs +362 -0
- package/crates/tish_lsp/src/import_goto.rs +562 -0
- package/crates/tish_lsp/src/main.rs +1046 -0
- package/crates/tish_native/Cargo.toml +16 -0
- package/crates/tish_native/src/build.rs +427 -0
- package/crates/tish_native/src/config.rs +48 -0
- package/crates/tish_native/src/lib.rs +416 -0
- package/crates/tish_opt/Cargo.toml +13 -0
- package/crates/tish_opt/src/lib.rs +943 -0
- package/crates/tish_parser/Cargo.toml +11 -0
- package/crates/tish_parser/src/lib.rs +332 -0
- package/crates/tish_parser/src/parser.rs +2304 -0
- package/crates/tish_pg/Cargo.toml +34 -0
- package/crates/tish_pg/README.md +38 -0
- package/crates/tish_pg/src/error.rs +52 -0
- package/crates/tish_pg/src/lib.rs +955 -0
- package/crates/tish_resolve/Cargo.toml +13 -0
- package/crates/tish_resolve/src/lib.rs +3561 -0
- package/crates/tish_resolve/src/pos.rs +141 -0
- package/crates/tish_runtime/Cargo.toml +96 -0
- package/crates/tish_runtime/src/http.rs +1298 -0
- package/crates/tish_runtime/src/http_fetch.rs +471 -0
- package/crates/tish_runtime/src/http_hyper.rs +418 -0
- package/crates/tish_runtime/src/http_prefork.rs +189 -0
- package/crates/tish_runtime/src/lib.rs +1192 -0
- package/crates/tish_runtime/src/native_promise.rs +15 -0
- package/crates/tish_runtime/src/promise.rs +248 -0
- package/crates/tish_runtime/src/promise_io.rs +38 -0
- package/crates/tish_runtime/src/timers.rs +166 -0
- package/crates/tish_runtime/src/ws.rs +761 -0
- package/crates/tish_runtime/tests/fetch_readable_stream.rs +102 -0
- package/crates/tish_ui/Cargo.toml +17 -0
- package/crates/tish_ui/src/jsx.rs +682 -0
- package/crates/tish_ui/src/lib.rs +20 -0
- package/crates/tish_ui/src/runtime/hooks.rs +569 -0
- package/crates/tish_ui/src/runtime/mod.rs +180 -0
- package/crates/tish_vm/Cargo.toml +47 -0
- package/crates/tish_vm/src/lib.rs +39 -0
- package/crates/tish_vm/src/vm.rs +2192 -0
- package/crates/tish_vm/tests/fixtures/or_string_cmd.tish +2 -0
- package/crates/tish_vm/tests/lexical_scope_declare.rs +34 -0
- package/crates/tish_vm/tests/peephole_jump_chain_logical_or.rs +150 -0
- package/crates/tish_wasm/Cargo.toml +15 -0
- package/crates/tish_wasm/src/lib.rs +424 -0
- package/crates/tish_wasm_runtime/Cargo.toml +37 -0
- package/crates/tish_wasm_runtime/src/gpu.rs +413 -0
- package/crates/tish_wasm_runtime/src/lib.rs +42 -0
- package/crates/tishlang_cargo_bindgen/Cargo.toml +26 -0
- package/crates/tishlang_cargo_bindgen/src/classify.rs +263 -0
- package/crates/tishlang_cargo_bindgen/src/discover.rs +125 -0
- package/crates/tishlang_cargo_bindgen/src/infer.rs +382 -0
- package/crates/tishlang_cargo_bindgen/src/lib.rs +349 -0
- package/crates/tishlang_cargo_bindgen/src/main.rs +167 -0
- package/crates/tishlang_cargo_bindgen/src/metadata.rs +117 -0
- package/justfile +268 -0
- package/package.json +1 -1
- package/platform/darwin-arm64/tish-fmt +0 -0
package/Cargo.toml
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
[workspace]
|
|
2
|
+
members = [
|
|
3
|
+
"crates/tish_build_utils",
|
|
4
|
+
"crates/tish_cranelift",
|
|
5
|
+
"crates/tish_cranelift_runtime",
|
|
6
|
+
"crates/tish_wasm_runtime",
|
|
7
|
+
"crates/tish_core",
|
|
8
|
+
"crates/tish_builtins",
|
|
9
|
+
"crates/tish_lexer",
|
|
10
|
+
"crates/tish_ast",
|
|
11
|
+
"crates/tish_parser",
|
|
12
|
+
"crates/tish_opt",
|
|
13
|
+
"crates/tish_eval",
|
|
14
|
+
"crates/tish_runtime",
|
|
15
|
+
"crates/tish_pg",
|
|
16
|
+
"crates/tish_compile",
|
|
17
|
+
"crates/tish_ui",
|
|
18
|
+
"crates/tish_jsx_web",
|
|
19
|
+
"crates/tish_compile_js",
|
|
20
|
+
"crates/tish_bytecode",
|
|
21
|
+
"crates/tish_compiler_wasm",
|
|
22
|
+
"crates/tish_vm",
|
|
23
|
+
"crates/tish_llvm",
|
|
24
|
+
|
|
25
|
+
"crates/tish_native",
|
|
26
|
+
"crates/tish_wasm",
|
|
27
|
+
"crates/tish",
|
|
28
|
+
"crates/js_to_tish",
|
|
29
|
+
"crates/tish_fmt",
|
|
30
|
+
"crates/tish_lint",
|
|
31
|
+
"crates/tish_lsp",
|
|
32
|
+
"crates/tish_resolve",
|
|
33
|
+
"crates/tishlang_cargo_bindgen",
|
|
34
|
+
]
|
|
35
|
+
resolver = "2"
|
|
36
|
+
|
|
37
|
+
[workspace.package]
|
|
38
|
+
version = "1.0.0"
|
|
39
|
+
license-file = "LICENSE"
|
|
40
|
+
repository = "https://github.com/tishlang/tish"
|
|
41
|
+
|
|
42
|
+
[profile.release]
|
|
43
|
+
lto = "thin"
|
|
44
|
+
codegen-units = 1
|
|
45
|
+
opt-level = 3
|
|
46
|
+
|
|
47
|
+
[profile.bench]
|
|
48
|
+
inherits = "release"
|
|
49
|
+
debug = true
|
package/LICENSE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Pay It Forward License (PIF)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-present The Tish Project Authors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
This license includes a perpetual, worldwide, non-exclusive, royalty-free, irrevocable (except as stated below) grant for patent claims necessarily infringed by the use of the Software or any contributions submitted to it; terminating automatically when an entity initiates patent litigation (including a cross-claim or counterclaim) alleging that the Software or any portion thereof infringes a patent.
|
|
10
|
+
|
|
11
|
+
The software is provided "as is," without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and non-infringement. In no event shall the authors or copyright holders be liable for any claim, damages, or other liability, whether in an action of contract, tort, or otherwise, arising from, out of, or in connection with the software or the use or other dealings in the software.
|
|
12
|
+
|
|
13
|
+
Recipients of the Software should pay it forward by contributing to the open-source community through actions including but not limited to providing code, documentation, tutorials, guides, support, feedback, or promoting open-source projects through advocacy or related efforts that advance innovation and community growth.
|
package/README.md
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
<picture>
|
|
2
|
+
<img alt="Tishlang" src="https://tishlang.com/banner.png">
|
|
3
|
+
</picture>
|
|
4
|
+
|
|
5
|
+
# Tish
|
|
6
|
+
|
|
7
|
+
<p>
|
|
8
|
+
<a href="https://npmjs.com/package/@tishlang/tish?activeTab=readme"><img src="https://img.shields.io/npm/v/@tishlang/tish?style=flat-square&colorA=1C1C1C&colorB=B688FF" alt="npm version" /></a>
|
|
9
|
+
<a href="https://npmcharts.com/compare/@tishlang/tish"><img src="https://img.shields.io/npm/dm/@tishlang/tish.svg?style=flat-square&colorA=1C1C1C&colorB=B688FF" alt="downloads" /></a>
|
|
10
|
+
<a href="https://nodejs.org/en/about/previous-releases"><img src="https://img.shields.io/node/v/@tishlang/tish.svg?style=flat-square&colorA=1C1C1C&colorB=B688FF" alt="node version"></a>
|
|
11
|
+
<a href="https://crates.io/crates/tishlang"><img src="https://img.shields.io/crates/v/tishlang?style=flat-square&colorA=1C1C1C&colorB=B688FF" alt="crate version" /></a>
|
|
12
|
+
<a href="https://github.com/tishlang/tish/blob/main/LICENSE"><img src="https://img.shields.io/badge/License-PIF-blue.svg?style=flat-square&colorA=1C1C1C&colorB=B688FF" alt="license" /></a>
|
|
13
|
+
|
|
14
|
+
</p>
|
|
15
|
+
|
|
16
|
+
Tish is a TypeScript- and JavaScript-compatible language implemented in Rust. It is aimed at teams who want a familiar surface syntax, predictable semantics, and the option to ship either interpreted scripts or runtime free **native binaries**.
|
|
17
|
+
|
|
18
|
+
The same source can run on a tree-walking interpreter, a bytecode VM, or compiled targets (native, WASM/WASI, and others). Network, filesystem, and process APIs are **feature-gated** so defaults stay safe. For the full syntax and semantics, see the canonical spec in-repo; for tutorials and reference, see [tishlang.com/docs](https://tishlang.com/docs).
|
|
19
|
+
|
|
20
|
+
## 🔥 Features
|
|
21
|
+
|
|
22
|
+
- **JS-like surface** — `let` / `const`, `fn`, arrows, template literals, async/await, modules, and a large slice of familiar builtins (`console`, `Math`, `JSON`, arrays, strings, objects).
|
|
23
|
+
- **Two ways to run** — interpret for fast iteration (`tish run`, REPL); compile to native or WASM for distribution and performance (`tish build`).
|
|
24
|
+
- **Memory-safe implementation** — Rust-hosted runtime and compiler pipeline; no GC in the host language for the toolchain itself.
|
|
25
|
+
- **Secure by default** — I/O and platform APIs (`http`, `fs`, `process`, etc.) are opt-in via features.
|
|
26
|
+
- **No `undefined`** — `null` only where JS would use undefined; strict equality (`===` / `!==`) without loose coercion.
|
|
27
|
+
- **Optional types** — TypeScript-style annotations are parsed for tooling and future checking; see the language reference for status.
|
|
28
|
+
|
|
29
|
+
Full specification: [docs/LANGUAGE.md](docs/LANGUAGE.md). Implementation status, gaps, and JS compatibility: [docs/plan-gap-analysis.md](docs/plan-gap-analysis.md).
|
|
30
|
+
|
|
31
|
+
## 📚 Documentation
|
|
32
|
+
|
|
33
|
+
User-facing guides and reference:
|
|
34
|
+
|
|
35
|
+
| Section | Description |
|
|
36
|
+
|---------|-------------|
|
|
37
|
+
| [Getting started](https://tishlang.com/docs/getting-started/installation/) | Install Tish, build your first app |
|
|
38
|
+
| [First app](https://tishlang.com/docs/getting-started/first-app/) | Run and build workflows, targets |
|
|
39
|
+
| [Editor & IDE](https://tishlang.com/docs/getting-started/editor/) | VS Code, LSP, tasks, Neovim |
|
|
40
|
+
| [Language server](https://tishlang.com/docs/reference/language-server/) | `tish-lsp` capabilities |
|
|
41
|
+
| [Formatting](https://tishlang.com/docs/reference/formatting/) | `tish-fmt` |
|
|
42
|
+
| [Linting](https://tishlang.com/docs/reference/linting/) | `tish-lint` |
|
|
43
|
+
| [Interactive REPL](https://tishlang.com/docs/getting-started/repl/) | Multi-line input, completion, history |
|
|
44
|
+
| [Language overview](https://tishlang.com/docs/language/overview/) | Syntax, keywords, semantics |
|
|
45
|
+
| [Tish vs JavaScript](https://tishlang.com/docs/language/vs-javascript/) | Differences and additions from JS |
|
|
46
|
+
| [Builtins](https://tishlang.com/docs/builtins/overview/) | Console, Math, JSON, Array, String, Object |
|
|
47
|
+
| [Features (APIs)](https://tishlang.com/docs/features/http/) | `http`, `fs`, `process`, `regex` — feature-gated |
|
|
48
|
+
| [Native backend](https://tishlang.com/docs/reference/native-backend/) | Rust, Cranelift, LLVM compilation |
|
|
49
|
+
| [WASM targets](https://tishlang.com/docs/reference/wasm-targets/) | Web and WASI |
|
|
50
|
+
| [Deploy](https://tishlang.com/docs/deploy/overview/) | Platform and hosting |
|
|
51
|
+
|
|
52
|
+
### In-repo docs
|
|
53
|
+
|
|
54
|
+
Contributor- and spec-oriented material in [docs/](docs/):
|
|
55
|
+
|
|
56
|
+
| File | Purpose |
|
|
57
|
+
|------|---------|
|
|
58
|
+
| [LANGUAGE.md](docs/LANGUAGE.md) | Canonical language reference (syntax, semantics, builtins) |
|
|
59
|
+
| [ecma-alignment.md](docs/ecma-alignment.md) | ECMA-262 / test262 mapping |
|
|
60
|
+
| [plan-gap-analysis.md](docs/plan-gap-analysis.md) | Implementation audit, MVP checklist |
|
|
61
|
+
| [architecture-next-steps.md](docs/architecture-next-steps.md) | Crate layout, design decisions |
|
|
62
|
+
| [builtins-gap-analysis.md](docs/builtins-gap-analysis.md) | Builtins across Rust vs bytecode VM (Cranelift/WASI) |
|
|
63
|
+
|
|
64
|
+
## 🛠️ Toolchain
|
|
65
|
+
|
|
66
|
+
| Tool | Purpose |
|
|
67
|
+
|------|---------|
|
|
68
|
+
| **`tish`** | CLI — `run`, `repl`, `build`, `dump-ast` |
|
|
69
|
+
| **`tish-fmt`** | Formatter |
|
|
70
|
+
| **`tish-lint`** | Linter (`--format sarif` for code scanning) |
|
|
71
|
+
| **`tish-lsp`** | Language server; uses `tish_fmt` / `tish_lint` as libraries |
|
|
72
|
+
| **`tish-security/`** (sibling repo) | Rules & CI examples — clone next to `tish/` as `../tish-security` ([OpenGrep](https://github.com/opengrep/opengrep), ast-grep, Comby, Codacy scaffold, fixtures) |
|
|
73
|
+
| **`tree-sitter-tish/`** | Tree-sitter grammar (editors, ast-grep, future OpenGrep integration) |
|
|
74
|
+
| **VS Code extension** | [tish-vscode](https://github.com/tishlang/tish-vscode) — grammar, snippets, LSP client, tasks |
|
|
75
|
+
|
|
76
|
+
Related docs on [tishlang.com](https://tishlang.com/docs): [Editor & IDE](https://tishlang.com/docs/getting-started/editor/), [Language server](https://tishlang.com/docs/reference/language-server/), [Formatting](https://tishlang.com/docs/reference/formatting/), [Linting](https://tishlang.com/docs/reference/linting/).
|
|
77
|
+
|
|
78
|
+
## 📦 Installation
|
|
79
|
+
|
|
80
|
+
Install globally:
|
|
81
|
+
|
|
82
|
+
```sh
|
|
83
|
+
brew tap tishlang/tish https://github.com/tishlang/tish
|
|
84
|
+
brew install tish
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Or locally with npm:
|
|
88
|
+
|
|
89
|
+
```sh
|
|
90
|
+
npm install @tishlang/tish
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
More options: [Installation](https://tishlang.com/docs/getting-started/installation/).
|
|
94
|
+
|
|
95
|
+
## ⚡ Quick start
|
|
96
|
+
|
|
97
|
+
```sh
|
|
98
|
+
npx @tishlang/create-tish-app my-app
|
|
99
|
+
cd my-app
|
|
100
|
+
npx @tishlang/tish run src/main.tish
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## ▶️ Run and build
|
|
104
|
+
|
|
105
|
+
```tish
|
|
106
|
+
// hello.tish
|
|
107
|
+
fn greeting(name) = `Hello, ${name}!`
|
|
108
|
+
console.log(greeting("World"))
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
tish run hello.tish
|
|
113
|
+
# Hello, World!
|
|
114
|
+
|
|
115
|
+
tish build hello.tish -o hello
|
|
116
|
+
./hello
|
|
117
|
+
# Hello, World!
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Native binaries are standalone (no Tish or Rust runtime required on the machine that runs them). Backends, flags, and WASM are covered in [First app](https://tishlang.com/docs/getting-started/first-app/), [Native backend](https://tishlang.com/docs/reference/native-backend/), and [WASM targets](https://tishlang.com/docs/reference/wasm-targets/).
|
|
121
|
+
|
|
122
|
+
## 🤝 Contribution
|
|
123
|
+
|
|
124
|
+
Contributions are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md) for building, testing, and code style. Tish is licensed under the [Pay It Forward License (PIF)](https://payitforwardlicense.com/).
|
|
125
|
+
|
|
126
|
+
## 💪 Performance
|
|
127
|
+
|
|
128
|
+
JavaScript equivalents live in `tests/core/*.js`. Compare Tish with Node.js or Bun:
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
./scripts/run_performance_manual.sh
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Details: [docs/perf.md](docs/perf.md).
|
|
135
|
+
|
|
136
|
+
## 📝 License
|
|
137
|
+
|
|
138
|
+
Tish is licensed under the [Pay It Forward License (PIF)](https://payitforwardlicense.com/). See [LICENSE](LICENSE).
|
package/bin/tish-format
ADDED
|
Binary file
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "tishlang_js_to_tish"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
edition = "2021"
|
|
5
|
+
description = "Vanilla JavaScript to Tish AST converter"
|
|
6
|
+
|
|
7
|
+
license-file = { workspace = true }
|
|
8
|
+
repository = { workspace = true }
|
|
9
|
+
[dependencies]
|
|
10
|
+
oxc = { version = "0.121", features = ["semantic"] }
|
|
11
|
+
tishlang_ast = { path = "../tish_ast", version = ">=0.1" }
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# js_to_tish
|
|
2
|
+
|
|
3
|
+
Vanilla JavaScript to Tish AST converter. Parses JavaScript with OXC, runs semantic analysis, normalizes to Tish's model, and emits `tish_ast::Program`.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```rust
|
|
8
|
+
use js_to_tish;
|
|
9
|
+
use tish_compile_js;
|
|
10
|
+
|
|
11
|
+
let program = js_to_tish::convert(js_source)?;
|
|
12
|
+
let js = tish_compile_js::compile(&program)?; // output as JavaScript
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Output options
|
|
16
|
+
|
|
17
|
+
- **JavaScript**: `tish_compile_js::compile(&program)` → `String`
|
|
18
|
+
- **Bytecode (run)**: `tish_bytecode::compile(&program)` → `Chunk`, then `tish_vm::run(&chunk)`
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
//! Conversion error types.
|
|
2
|
+
|
|
3
|
+
use std::fmt;
|
|
4
|
+
|
|
5
|
+
/// Error returned when JS cannot be converted to Tish.
|
|
6
|
+
#[derive(Debug)]
|
|
7
|
+
pub struct ConvertError {
|
|
8
|
+
pub kind: ConvertErrorKind,
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
impl ConvertError {
|
|
12
|
+
pub fn new(kind: ConvertErrorKind) -> Self {
|
|
13
|
+
Self { kind }
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
impl fmt::Display for ConvertError {
|
|
18
|
+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
19
|
+
write!(f, "{}", self.kind)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
impl std::error::Error for ConvertError {}
|
|
24
|
+
|
|
25
|
+
/// Categorizes conversion failures.
|
|
26
|
+
#[derive(Debug)]
|
|
27
|
+
pub enum ConvertErrorKind {
|
|
28
|
+
/// Parse error from OXC.
|
|
29
|
+
Parse(String),
|
|
30
|
+
/// Semantic analysis error from OXC.
|
|
31
|
+
Semantic(String),
|
|
32
|
+
/// Unsupported construct (class, this, for-in, etc.).
|
|
33
|
+
Unsupported { what: String, hint: Option<String> },
|
|
34
|
+
/// JS feature that cannot be expressed in Tish.
|
|
35
|
+
Incompatible { what: String, reason: String },
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
impl fmt::Display for ConvertErrorKind {
|
|
39
|
+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
40
|
+
match self {
|
|
41
|
+
ConvertErrorKind::Parse(s) => write!(f, "parse error: {s}"),
|
|
42
|
+
ConvertErrorKind::Semantic(s) => write!(f, "semantic error: {s}"),
|
|
43
|
+
ConvertErrorKind::Unsupported { what, hint } => {
|
|
44
|
+
write!(f, "unsupported: {what}")?;
|
|
45
|
+
if let Some(h) = hint {
|
|
46
|
+
write!(f, " ({h})")?;
|
|
47
|
+
}
|
|
48
|
+
Ok(())
|
|
49
|
+
}
|
|
50
|
+
ConvertErrorKind::Incompatible { what, reason } => {
|
|
51
|
+
write!(f, "incompatible: {what} — {reason}")
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//! Vanilla JavaScript to Tish AST converter.
|
|
2
|
+
//!
|
|
3
|
+
//! Parses JavaScript with OXC, runs semantic analysis for scope/hoisting,
|
|
4
|
+
//! normalizes to Tish's simpler model, and emits Tish AST.
|
|
5
|
+
|
|
6
|
+
mod error;
|
|
7
|
+
mod span_util;
|
|
8
|
+
mod transform;
|
|
9
|
+
|
|
10
|
+
pub use error::{ConvertError, ConvertErrorKind};
|
|
11
|
+
pub use transform::convert;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//! Span conversion from OXC offsets to Tish (line, col).
|
|
2
|
+
|
|
3
|
+
use oxc::span::GetSpan;
|
|
4
|
+
use tishlang_ast::Span;
|
|
5
|
+
|
|
6
|
+
/// Convert OXC span (byte start/end) to Tish Span (line, col).
|
|
7
|
+
/// Uses source text to compute line/column from offsets.
|
|
8
|
+
pub fn oxc_span_to_tish<T: GetSpan>(source: &str, oxc_span: &T) -> Span {
|
|
9
|
+
let s = oxc_span.span();
|
|
10
|
+
let start = offset_to_line_col(source, s.start);
|
|
11
|
+
let end = offset_to_line_col(source, s.end);
|
|
12
|
+
Span { start, end }
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/// Compute (line, col) for byte offset. Lines and columns are 0-based.
|
|
16
|
+
fn offset_to_line_col(source: &str, offset: u32) -> (usize, usize) {
|
|
17
|
+
let offset = offset as usize;
|
|
18
|
+
if offset >= source.len() {
|
|
19
|
+
let lines = source.lines().count();
|
|
20
|
+
let last_line_len = source.lines().last().map(str::len).unwrap_or(0);
|
|
21
|
+
return (lines.saturating_sub(1), last_line_len);
|
|
22
|
+
}
|
|
23
|
+
let prefix = &source[..offset];
|
|
24
|
+
let line = prefix.lines().count().saturating_sub(1);
|
|
25
|
+
let col = prefix.lines().last().map(str::len).unwrap_or(0);
|
|
26
|
+
(line, col)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/// Stub span when source is not available (e.g. synthetic nodes).
|
|
30
|
+
pub fn stub_span() -> Span {
|
|
31
|
+
Span {
|
|
32
|
+
start: (0, 0),
|
|
33
|
+
end: (0, 0),
|
|
34
|
+
}
|
|
35
|
+
}
|