@tishlang/tish 1.0.7 → 1.0.11
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 +43 -0
- package/LICENSE +13 -0
- package/README.md +66 -0
- package/crates/js_to_tish/Cargo.toml +9 -0
- package/crates/js_to_tish/README.md +18 -0
- package/crates/js_to_tish/src/error.rs +61 -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 +608 -0
- package/crates/js_to_tish/src/transform/stmt.rs +474 -0
- package/crates/js_to_tish/src/transform.rs +60 -0
- package/crates/tish/Cargo.toml +44 -0
- package/crates/tish/src/main.rs +585 -0
- package/crates/tish/src/repl_completion.rs +200 -0
- package/crates/tish/tests/integration_test.rs +726 -0
- package/crates/tish_ast/Cargo.toml +7 -0
- package/crates/tish_ast/src/ast.rs +494 -0
- package/crates/tish_ast/src/lib.rs +5 -0
- package/crates/tish_build_utils/Cargo.toml +5 -0
- package/crates/tish_build_utils/src/lib.rs +175 -0
- package/crates/tish_builtins/Cargo.toml +12 -0
- package/crates/tish_builtins/src/array.rs +410 -0
- package/crates/tish_builtins/src/globals.rs +197 -0
- package/crates/tish_builtins/src/helpers.rs +38 -0
- package/crates/tish_builtins/src/lib.rs +14 -0
- package/crates/tish_builtins/src/math.rs +80 -0
- package/crates/tish_builtins/src/object.rs +36 -0
- package/crates/tish_builtins/src/string.rs +253 -0
- package/crates/tish_bytecode/Cargo.toml +15 -0
- package/crates/tish_bytecode/src/chunk.rs +97 -0
- package/crates/tish_bytecode/src/compiler.rs +1361 -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 +110 -0
- package/crates/tish_bytecode/src/peephole.rs +159 -0
- package/crates/tish_bytecode/src/serialize.rs +163 -0
- package/crates/tish_bytecode/tests/constant_folding.rs +84 -0
- package/crates/tish_bytecode/tests/shortcircuit.rs +49 -0
- package/crates/tish_bytecode/tests/sort_optimization.rs +31 -0
- package/crates/tish_compile/Cargo.toml +21 -0
- package/crates/tish_compile/src/codegen.rs +3316 -0
- package/crates/tish_compile/src/lib.rs +71 -0
- package/crates/tish_compile/src/resolve.rs +631 -0
- package/crates/tish_compile/src/types.rs +304 -0
- package/crates/tish_compile_js/Cargo.toml +16 -0
- package/crates/tish_compile_js/examples/jsx_vdom_smoke.tish +8 -0
- package/crates/tish_compile_js/src/codegen.rs +794 -0
- package/crates/tish_compile_js/src/error.rs +20 -0
- package/crates/tish_compile_js/src/js_intrinsics.rs +82 -0
- package/crates/tish_compile_js/src/lib.rs +27 -0
- package/crates/tish_compile_js/src/tests_jsx.rs +32 -0
- package/crates/tish_compiler_wasm/Cargo.toml +19 -0
- package/crates/tish_compiler_wasm/src/lib.rs +55 -0
- package/crates/tish_compiler_wasm/src/resolve_virtual.rs +462 -0
- package/crates/tish_core/Cargo.toml +11 -0
- package/crates/tish_core/src/console_style.rs +128 -0
- package/crates/tish_core/src/json.rs +327 -0
- package/crates/tish_core/src/lib.rs +15 -0
- package/crates/tish_core/src/macros.rs +37 -0
- package/crates/tish_core/src/uri.rs +115 -0
- package/crates/tish_core/src/value.rs +376 -0
- package/crates/tish_cranelift/Cargo.toml +17 -0
- package/crates/tish_cranelift/src/lib.rs +41 -0
- package/crates/tish_cranelift/src/link.rs +120 -0
- package/crates/tish_cranelift/src/lower.rs +77 -0
- package/crates/tish_cranelift_runtime/Cargo.toml +19 -0
- package/crates/tish_cranelift_runtime/src/lib.rs +43 -0
- package/crates/tish_eval/Cargo.toml +26 -0
- package/crates/tish_eval/src/eval.rs +3205 -0
- package/crates/tish_eval/src/http.rs +122 -0
- package/crates/tish_eval/src/lib.rs +59 -0
- package/crates/tish_eval/src/natives.rs +301 -0
- package/crates/tish_eval/src/promise.rs +173 -0
- package/crates/tish_eval/src/regex.rs +298 -0
- package/crates/tish_eval/src/timers.rs +111 -0
- package/crates/tish_eval/src/value.rs +224 -0
- package/crates/tish_eval/src/value_convert.rs +85 -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 +884 -0
- package/crates/tish_jsx_web/Cargo.toml +7 -0
- package/crates/tish_jsx_web/README.md +18 -0
- package/crates/tish_jsx_web/src/lib.rs +157 -0
- package/crates/tish_jsx_web/vendor/Lattish.tish +347 -0
- package/crates/tish_lexer/Cargo.toml +7 -0
- package/crates/tish_lexer/src/lib.rs +430 -0
- package/crates/tish_lexer/src/token.rs +155 -0
- package/crates/tish_lint/Cargo.toml +17 -0
- package/crates/tish_lint/src/bin/tish-lint.rs +77 -0
- package/crates/tish_lint/src/lib.rs +278 -0
- package/crates/tish_llvm/Cargo.toml +11 -0
- package/crates/tish_llvm/src/lib.rs +106 -0
- package/crates/tish_lsp/Cargo.toml +22 -0
- package/crates/tish_lsp/README.md +26 -0
- package/crates/tish_lsp/src/main.rs +615 -0
- package/crates/tish_native/Cargo.toml +14 -0
- package/crates/tish_native/src/build.rs +102 -0
- package/crates/tish_native/src/lib.rs +237 -0
- package/crates/tish_opt/Cargo.toml +11 -0
- package/crates/tish_opt/src/lib.rs +896 -0
- package/crates/tish_parser/Cargo.toml +9 -0
- package/crates/tish_parser/src/lib.rs +123 -0
- package/crates/tish_parser/src/parser.rs +1714 -0
- package/crates/tish_runtime/Cargo.toml +26 -0
- package/crates/tish_runtime/src/http.rs +308 -0
- package/crates/tish_runtime/src/http_fetch.rs +453 -0
- package/crates/tish_runtime/src/lib.rs +1004 -0
- package/crates/tish_runtime/src/native_promise.rs +26 -0
- package/crates/tish_runtime/src/promise.rs +77 -0
- package/crates/tish_runtime/src/promise_io.rs +41 -0
- package/crates/tish_runtime/src/timers.rs +125 -0
- package/crates/tish_runtime/src/ws.rs +725 -0
- package/crates/tish_runtime/tests/fetch_readable_stream.rs +99 -0
- package/crates/tish_vm/Cargo.toml +31 -0
- package/crates/tish_vm/src/lib.rs +39 -0
- package/crates/tish_vm/src/vm.rs +1399 -0
- package/crates/tish_wasm/Cargo.toml +13 -0
- package/crates/tish_wasm/src/lib.rs +358 -0
- package/crates/tish_wasm_runtime/Cargo.toml +25 -0
- package/crates/tish_wasm_runtime/src/lib.rs +36 -0
- package/justfile +260 -0
- package/package.json +8 -3
- package/platform/darwin-arm64/tish +0 -0
- package/platform/darwin-x64/tish +0 -0
- package/platform/linux-arm64/tish +0 -0
- package/platform/linux-x64/tish +0 -0
- package/platform/win32-x64/tish.exe +0 -0
package/Cargo.toml
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
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_compile",
|
|
16
|
+
"crates/tish_jsx_web",
|
|
17
|
+
"crates/tish_compile_js",
|
|
18
|
+
"crates/tish_bytecode",
|
|
19
|
+
"crates/tish_compiler_wasm",
|
|
20
|
+
"crates/tish_vm",
|
|
21
|
+
"crates/tish_llvm",
|
|
22
|
+
"crates/tish_native",
|
|
23
|
+
"crates/tish_wasm",
|
|
24
|
+
"crates/tish",
|
|
25
|
+
"crates/js_to_tish",
|
|
26
|
+
"crates/tish_fmt",
|
|
27
|
+
"crates/tish_lint",
|
|
28
|
+
"crates/tish_lsp",
|
|
29
|
+
]
|
|
30
|
+
resolver = "2"
|
|
31
|
+
|
|
32
|
+
[workspace.package]
|
|
33
|
+
license-file = "LICENSE"
|
|
34
|
+
repository = "https://github.com/tishlang/tish"
|
|
35
|
+
|
|
36
|
+
[profile.release]
|
|
37
|
+
lto = "thin"
|
|
38
|
+
codegen-units = 1
|
|
39
|
+
opt-level = 3
|
|
40
|
+
|
|
41
|
+
[profile.bench]
|
|
42
|
+
inherits = "release"
|
|
43
|
+
debug = true
|
package/LICENSE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Pay It Forward License (PIF)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 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,66 @@
|
|
|
1
|
+
# @tishlang/tish
|
|
2
|
+
|
|
3
|
+
[Tish](https://github.com/tishlang/tish) is a minimal TypeScript/JavaScript–compatible language: run with an interpreter, use a REPL, or compile to native binaries.
|
|
4
|
+
|
|
5
|
+
This npm package ships the **Tish CLI** for Node.js **22+**. It includes platform-specific native binaries; the `tish` command picks the right one for your OS and CPU.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @tishlang/tish
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or run without installing:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npx @tishlang/tish --help
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick start
|
|
20
|
+
|
|
21
|
+
Run a `.tish` file (shorthand: first argument is treated as a file → `run`):
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npx @tishlang/tish hello.tish
|
|
25
|
+
npx @tishlang/tish run src/main.tish
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Compile to a native executable:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npx @tishlang/tish compile app.tish -o app
|
|
32
|
+
./app
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Native compilation uses the Rust backend by default (requires [Rust](https://rustup.rs) and `cargo` on your PATH). The package includes the Tish workspace source (`Cargo.toml`, `crates/`, `justfile`) so `tish compile` can run `cargo build` for your program. For pure Tish without native imports, use `--native-backend cranelift` (no Rust toolchain needed).
|
|
36
|
+
|
|
37
|
+
Start the REPL:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npx @tishlang/tish repl
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Supported platforms
|
|
44
|
+
|
|
45
|
+
Prebuilt binaries are included for:
|
|
46
|
+
|
|
47
|
+
- `darwin-arm64`, `darwin-x64`
|
|
48
|
+
- `linux-x64`, `linux-arm64`
|
|
49
|
+
- `win32-x64`
|
|
50
|
+
|
|
51
|
+
If your platform is missing, [build from source](https://github.com/tishlang/tish).
|
|
52
|
+
|
|
53
|
+
## Documentation
|
|
54
|
+
|
|
55
|
+
- Repository: <https://github.com/tishlang/tish>
|
|
56
|
+
- User docs: <https://github.com/tishlang/tish-docs>
|
|
57
|
+
|
|
58
|
+
## Scaffold a project
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
npx @tishlang/create-tish-app my-app
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## License
|
|
65
|
+
|
|
66
|
+
See the [Tish repository LICENSE](https://github.com/tishlang/tish/blob/main/LICENSE) (Pay It Forward).
|
|
@@ -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,61 @@
|
|
|
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 {
|
|
34
|
+
what: String,
|
|
35
|
+
hint: Option<String>,
|
|
36
|
+
},
|
|
37
|
+
/// JS feature that cannot be expressed in Tish.
|
|
38
|
+
Incompatible {
|
|
39
|
+
what: String,
|
|
40
|
+
reason: String,
|
|
41
|
+
},
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
impl fmt::Display for ConvertErrorKind {
|
|
45
|
+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
46
|
+
match self {
|
|
47
|
+
ConvertErrorKind::Parse(s) => write!(f, "parse error: {s}"),
|
|
48
|
+
ConvertErrorKind::Semantic(s) => write!(f, "semantic error: {s}"),
|
|
49
|
+
ConvertErrorKind::Unsupported { what, hint } => {
|
|
50
|
+
write!(f, "unsupported: {what}")?;
|
|
51
|
+
if let Some(h) = hint {
|
|
52
|
+
write!(f, " ({h})")?;
|
|
53
|
+
}
|
|
54
|
+
Ok(())
|
|
55
|
+
}
|
|
56
|
+
ConvertErrorKind::Incompatible { what, reason } => {
|
|
57
|
+
write!(f, "incompatible: {what} — {reason}")
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -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 tish_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
|
+
}
|