@tishlang/tish 1.0.6 → 1.0.10
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
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
//! ReadableStream + reader.read() chunk boundaries over local HTTP.
|
|
2
|
+
#![cfg(feature = "http")]
|
|
3
|
+
|
|
4
|
+
use std::io::{Read, Write};
|
|
5
|
+
use std::net::TcpListener;
|
|
6
|
+
use std::thread;
|
|
7
|
+
use std::time::Duration;
|
|
8
|
+
|
|
9
|
+
use tish_core::Value;
|
|
10
|
+
use tish_runtime::{await_promise, fetch_promise};
|
|
11
|
+
|
|
12
|
+
fn chunked_body_server(listener: TcpListener) {
|
|
13
|
+
let (mut stream, _) = listener.accept().expect("accept");
|
|
14
|
+
let _ = stream.set_read_timeout(Some(Duration::from_secs(2)));
|
|
15
|
+
let mut buf = vec![0u8; 512];
|
|
16
|
+
let _ = stream.read(&mut buf);
|
|
17
|
+
|
|
18
|
+
let _ = stream.write_all(b"HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n");
|
|
19
|
+
let _ = stream.write_all(b"3\r\nabc\r\n");
|
|
20
|
+
let _ = stream.flush();
|
|
21
|
+
thread::sleep(Duration::from_millis(40));
|
|
22
|
+
let _ = stream.write_all(b"3\r\ndef\r\n0\r\n\r\n");
|
|
23
|
+
let _ = stream.flush();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
fn byte_array_to_vec(v: &Value) -> Vec<u8> {
|
|
27
|
+
match v {
|
|
28
|
+
Value::Array(a) => a
|
|
29
|
+
.borrow()
|
|
30
|
+
.iter()
|
|
31
|
+
.filter_map(|x| match x {
|
|
32
|
+
Value::Number(n) => Some(*n as u8),
|
|
33
|
+
_ => None,
|
|
34
|
+
})
|
|
35
|
+
.collect(),
|
|
36
|
+
_ => vec![],
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
#[test]
|
|
41
|
+
fn fetch_readable_stream_read_chunks() {
|
|
42
|
+
let listener = TcpListener::bind("127.0.0.1:0").expect("bind");
|
|
43
|
+
let port = listener.local_addr().unwrap().port();
|
|
44
|
+
let th = thread::spawn(move || chunked_body_server(listener));
|
|
45
|
+
|
|
46
|
+
let url = format!("http://127.0.0.1:{}/c", port);
|
|
47
|
+
let prom = fetch_promise(vec![Value::String(url.into())]);
|
|
48
|
+
let resp = await_promise(prom);
|
|
49
|
+
|
|
50
|
+
let obj = match &resp {
|
|
51
|
+
Value::Object(o) => o.borrow(),
|
|
52
|
+
_ => panic!("expected object response, got {:?}", resp),
|
|
53
|
+
};
|
|
54
|
+
assert!(obj.get(&std::sync::Arc::from("ok")).map(|v| matches!(v, Value::Bool(true))).unwrap_or(false));
|
|
55
|
+
|
|
56
|
+
let body = obj.get(&std::sync::Arc::from("body")).expect("body");
|
|
57
|
+
let stream = match body {
|
|
58
|
+
Value::Opaque(s) => s.as_ref(),
|
|
59
|
+
_ => panic!("expected ReadableStream opaque"),
|
|
60
|
+
};
|
|
61
|
+
let reader_val = stream
|
|
62
|
+
.get_method("getReader")
|
|
63
|
+
.expect("getReader")(&[]);
|
|
64
|
+
let reader = match reader_val {
|
|
65
|
+
Value::Opaque(r) => r,
|
|
66
|
+
_ => panic!("expected reader opaque, got {:?}", reader_val),
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
let mut acc = Vec::new();
|
|
70
|
+
loop {
|
|
71
|
+
let read_p = reader.get_method("read").expect("read")(&[]);
|
|
72
|
+
let chunk = await_promise(read_p);
|
|
73
|
+
let (done, chunk_bytes) = match chunk {
|
|
74
|
+
Value::Object(o) => {
|
|
75
|
+
let m = o.borrow();
|
|
76
|
+
let done = m
|
|
77
|
+
.get(&std::sync::Arc::from("done"))
|
|
78
|
+
.and_then(|v| match v {
|
|
79
|
+
Value::Bool(b) => Some(*b),
|
|
80
|
+
_ => None,
|
|
81
|
+
})
|
|
82
|
+
.unwrap_or(true);
|
|
83
|
+
let bytes = m
|
|
84
|
+
.get(&std::sync::Arc::from("value"))
|
|
85
|
+
.map(|v| byte_array_to_vec(v))
|
|
86
|
+
.unwrap_or_default();
|
|
87
|
+
(done, bytes)
|
|
88
|
+
}
|
|
89
|
+
_ => panic!("expected read result object"),
|
|
90
|
+
};
|
|
91
|
+
if done {
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
acc.extend(chunk_bytes);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
th.join().expect("server");
|
|
98
|
+
assert_eq!(acc, b"abcdef");
|
|
99
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "tish_vm"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
edition = "2021"
|
|
5
|
+
description = "Bytecode VM for Tish"
|
|
6
|
+
|
|
7
|
+
[features]
|
|
8
|
+
default = []
|
|
9
|
+
regex = ["tish_core/regex"]
|
|
10
|
+
# For wasm32 target: use web_sys console for output
|
|
11
|
+
wasm = ["dep:wasm-bindgen"]
|
|
12
|
+
# Built-in modules: fs, http, process (for bytecode LoadNativeExport)
|
|
13
|
+
fs = ["tish_runtime/fs"]
|
|
14
|
+
process = ["tish_runtime/process"]
|
|
15
|
+
http = ["tish_runtime/http"]
|
|
16
|
+
ws = ["tish_runtime/ws"]
|
|
17
|
+
|
|
18
|
+
[dependencies]
|
|
19
|
+
tish_ast = { path = "../tish_ast" }
|
|
20
|
+
tish_builtins = { path = "../tish_builtins" }
|
|
21
|
+
tish_bytecode = { path = "../tish_bytecode" }
|
|
22
|
+
tish_core = { path = "../tish_core" }
|
|
23
|
+
tish_runtime = { path = "../tish_runtime", optional = true }
|
|
24
|
+
rand = "0.10"
|
|
25
|
+
wasm-bindgen = { version = "0.2", optional = true }
|
|
26
|
+
|
|
27
|
+
[dev-dependencies]
|
|
28
|
+
tish_parser = { path = "../tish_parser" }
|
|
29
|
+
|
|
30
|
+
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
|
31
|
+
getrandom = { version = "0.4", features = ["wasm_js"] }
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//! Bytecode VM for Tish execution.
|
|
2
|
+
|
|
3
|
+
mod vm;
|
|
4
|
+
|
|
5
|
+
pub use vm::{run, Vm};
|
|
6
|
+
|
|
7
|
+
#[cfg(test)]
|
|
8
|
+
mod tests {
|
|
9
|
+
use super::*;
|
|
10
|
+
|
|
11
|
+
#[test]
|
|
12
|
+
fn bytecode_for_of_break_continue_switch_try() {
|
|
13
|
+
let src = r#"
|
|
14
|
+
let sum = 0;
|
|
15
|
+
for (let x of [1, 2, 3]) { sum = sum + x; }
|
|
16
|
+
console.log(sum);
|
|
17
|
+
let n = 0;
|
|
18
|
+
do { n = n + 1; } while (n < 3);
|
|
19
|
+
console.log(n);
|
|
20
|
+
const k = 2;
|
|
21
|
+
switch (k) {
|
|
22
|
+
case 1: console.log(1); break;
|
|
23
|
+
case 2: console.log(2); break;
|
|
24
|
+
default: console.log(0);
|
|
25
|
+
}
|
|
26
|
+
try { throw "ok"; } catch (e) { console.log(e); }
|
|
27
|
+
let x = 10;
|
|
28
|
+
x++;
|
|
29
|
+
++x;
|
|
30
|
+
x += 3;
|
|
31
|
+
console.log(x);
|
|
32
|
+
fn f(a, b, ...rest) { return rest.length; }
|
|
33
|
+
console.log(f(1,2,3,4));
|
|
34
|
+
"#;
|
|
35
|
+
let program = tish_parser::parse(src).expect("parse");
|
|
36
|
+
let chunk = tish_bytecode::compile(&program).expect("compile");
|
|
37
|
+
let _ = run(&chunk).expect("run");
|
|
38
|
+
}
|
|
39
|
+
}
|