@tishlang/tish 1.6.0 → 1.7.0
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 +1 -0
- package/bin/tish +0 -0
- package/crates/js_to_tish/src/error.rs +2 -8
- package/crates/js_to_tish/src/transform/expr.rs +101 -130
- package/crates/js_to_tish/src/transform/stmt.rs +25 -22
- package/crates/tish/Cargo.toml +1 -1
- package/crates/tish/src/cli_help.rs +76 -29
- package/crates/tish/src/main.rs +85 -54
- package/crates/tish/tests/cargo_example_compile.rs +3 -1
- package/crates/tish/tests/integration_test.rs +197 -47
- package/crates/tish/tests/run_optimize_stdout_parity.rs +3 -7
- package/crates/tish/tests/shortcircuit.rs +19 -4
- package/crates/tish_ast/src/ast.rs +12 -14
- package/crates/tish_build_utils/src/lib.rs +31 -6
- package/crates/tish_builtins/src/array.rs +52 -21
- package/crates/tish_builtins/src/construct.rs +2 -8
- package/crates/tish_builtins/src/globals.rs +30 -15
- package/crates/tish_builtins/src/lib.rs +5 -5
- package/crates/tish_builtins/src/math.rs +5 -3
- package/crates/tish_builtins/src/string.rs +71 -19
- package/crates/tish_bytecode/src/chunk.rs +0 -1
- package/crates/tish_bytecode/src/compiler.rs +164 -60
- package/crates/tish_bytecode/src/opcode.rs +13 -4
- package/crates/tish_bytecode/src/peephole.rs +2 -2
- package/crates/tish_compile/src/codegen.rs +921 -299
- package/crates/tish_compile/src/infer.rs +69 -19
- package/crates/tish_compile/src/lib.rs +15 -5
- package/crates/tish_compile/src/resolve.rs +112 -69
- package/crates/tish_compile/src/types.rs +10 -14
- package/crates/tish_compile_js/src/codegen.rs +34 -13
- package/crates/tish_compile_js/src/tests_jsx.rs +30 -6
- package/crates/tish_compiler_wasm/src/lib.rs +16 -13
- package/crates/tish_compiler_wasm/src/resolve_virtual.rs +39 -48
- package/crates/tish_core/src/json.rs +5 -3
- package/crates/tish_core/src/lib.rs +1 -1
- package/crates/tish_core/src/uri.rs +9 -6
- package/crates/tish_core/src/value.rs +92 -28
- package/crates/tish_cranelift/src/link.rs +6 -9
- package/crates/tish_cranelift/src/lower.rs +14 -8
- package/crates/tish_eval/src/eval.rs +389 -142
- package/crates/tish_eval/src/lib.rs +10 -6
- package/crates/tish_eval/src/natives.rs +95 -38
- package/crates/tish_eval/src/promise.rs +14 -8
- package/crates/tish_eval/src/timers.rs +28 -19
- package/crates/tish_eval/src/value.rs +10 -3
- package/crates/tish_fmt/src/lib.rs +29 -13
- package/crates/tish_lexer/src/lib.rs +217 -63
- package/crates/tish_lexer/src/token.rs +6 -6
- package/crates/tish_llvm/src/lib.rs +15 -8
- package/crates/tish_lsp/src/main.rs +41 -43
- package/crates/tish_native/src/build.rs +1 -6
- package/crates/tish_native/src/lib.rs +48 -19
- package/crates/tish_opt/src/lib.rs +67 -50
- package/crates/tish_parser/src/lib.rs +36 -11
- package/crates/tish_parser/src/parser.rs +172 -87
- package/crates/tish_runtime/src/http.rs +15 -6
- package/crates/tish_runtime/src/http_fetch.rs +24 -14
- package/crates/tish_runtime/src/lib.rs +224 -168
- package/crates/tish_runtime/src/promise.rs +1 -5
- package/crates/tish_runtime/src/ws.rs +45 -20
- package/crates/tish_runtime/tests/fetch_readable_stream.rs +5 -4
- package/crates/tish_ui/src/jsx.rs +41 -22
- package/crates/tish_ui/src/lib.rs +2 -2
- package/crates/tish_vm/src/vm.rs +309 -112
- package/crates/tish_vm/tests/peephole_jump_chain_logical_or.rs +8 -3
- package/crates/tish_wasm/src/lib.rs +38 -28
- package/crates/tishlang_cargo_bindgen/Cargo.toml +25 -0
- package/crates/tishlang_cargo_bindgen/src/classify.rs +265 -0
- package/crates/tishlang_cargo_bindgen/src/discover.rs +52 -0
- package/crates/tishlang_cargo_bindgen/src/infer.rs +372 -0
- package/crates/tishlang_cargo_bindgen/src/lib.rs +349 -0
- package/crates/tishlang_cargo_bindgen/src/main.rs +164 -0
- package/crates/tishlang_cargo_bindgen/src/metadata.rs +114 -0
- package/package.json +1 -1
- 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
|
@@ -35,7 +35,11 @@ impl TishPromise for FetchResponsePromise {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
struct FetchAllResponsesPromise {
|
|
38
|
-
rx: Mutex<
|
|
38
|
+
rx: Mutex<
|
|
39
|
+
Option<
|
|
40
|
+
tokio::sync::oneshot::Receiver<Result<Vec<Result<reqwest::Response, String>>, String>>,
|
|
41
|
+
>,
|
|
42
|
+
>,
|
|
39
43
|
}
|
|
40
44
|
|
|
41
45
|
impl TishPromise for FetchAllResponsesPromise {
|
|
@@ -47,7 +51,10 @@ impl TishPromise for FetchAllResponsesPromise {
|
|
|
47
51
|
Ok(Ok(vec)) => {
|
|
48
52
|
let out: Vec<Value> = vec
|
|
49
53
|
.into_iter()
|
|
50
|
-
.map(|x|
|
|
54
|
+
.map(|x| {
|
|
55
|
+
x.map(response_value_from_reqwest)
|
|
56
|
+
.unwrap_or_else(|e| build_error_response(&e))
|
|
57
|
+
})
|
|
51
58
|
.collect();
|
|
52
59
|
Ok(Value::Array(Rc::new(RefCell::new(out))))
|
|
53
60
|
}
|
|
@@ -85,10 +92,7 @@ impl TishPromise for ReadChunkPromise {
|
|
|
85
92
|
let arr: Vec<Value> = b.iter().map(|u| Value::Number(*u as f64)).collect();
|
|
86
93
|
let mut o = ObjectMap::default();
|
|
87
94
|
o.insert(Arc::from("done"), Value::Bool(false));
|
|
88
|
-
o.insert(
|
|
89
|
-
Arc::from("value"),
|
|
90
|
-
Value::Array(Rc::new(RefCell::new(arr))),
|
|
91
|
-
);
|
|
95
|
+
o.insert(Arc::from("value"), Value::Array(Rc::new(RefCell::new(arr))));
|
|
92
96
|
Ok(Value::Object(Rc::new(RefCell::new(o))))
|
|
93
97
|
}
|
|
94
98
|
Ok(Err(e)) => Err({
|
|
@@ -160,18 +164,23 @@ impl HttpBody {
|
|
|
160
164
|
let mut g = self.state.lock().unwrap();
|
|
161
165
|
match &mut *g {
|
|
162
166
|
BodyState::Fresh(r) => {
|
|
163
|
-
let resp = r
|
|
167
|
+
let resp = r
|
|
168
|
+
.take()
|
|
169
|
+
.ok_or_else(|| "Response body already consumed".to_string())?;
|
|
164
170
|
*g = BodyState::ReadInProgress;
|
|
165
171
|
Ok(Box::pin(resp.bytes_stream()))
|
|
166
172
|
}
|
|
167
|
-
BodyState::ReadInProgress =>
|
|
173
|
+
BodyState::ReadInProgress => {
|
|
174
|
+
Err("ReadableStream is locked; getReader() already called".into())
|
|
175
|
+
}
|
|
168
176
|
BodyState::Gone => Err("Response body already consumed".into()),
|
|
169
177
|
}
|
|
170
178
|
}
|
|
171
179
|
|
|
172
180
|
pub fn take_text_async(
|
|
173
181
|
&self,
|
|
174
|
-
) -> std::pin::Pin<Box<dyn std::future::Future<Output = Result<String, String>> + Send + '_>>
|
|
182
|
+
) -> std::pin::Pin<Box<dyn std::future::Future<Output = Result<String, String>> + Send + '_>>
|
|
183
|
+
{
|
|
175
184
|
let resp = {
|
|
176
185
|
let mut g = self.state.lock().unwrap();
|
|
177
186
|
match &mut *g {
|
|
@@ -182,9 +191,9 @@ impl HttpBody {
|
|
|
182
191
|
}
|
|
183
192
|
None => Err("Response body already consumed".into()),
|
|
184
193
|
},
|
|
185
|
-
BodyState::ReadInProgress =>
|
|
186
|
-
"Cannot call text(): body is locked by ReadableStreamDefaultReader".into()
|
|
187
|
-
|
|
194
|
+
BodyState::ReadInProgress => {
|
|
195
|
+
Err("Cannot call text(): body is locked by ReadableStreamDefaultReader".into())
|
|
196
|
+
}
|
|
188
197
|
BodyState::Gone => Err("Response body already consumed".into()),
|
|
189
198
|
}
|
|
190
199
|
};
|
|
@@ -420,7 +429,8 @@ pub fn fetch_all_promise_from_args(args: Vec<Value>) -> Value {
|
|
|
420
429
|
Some(u) => (u, Some(req.clone())),
|
|
421
430
|
None => {
|
|
422
431
|
let (tx, rx) = tokio::sync::oneshot::channel();
|
|
423
|
-
let _ =
|
|
432
|
+
let _ =
|
|
433
|
+
tx.send(Err("Each request object must have a 'url' property".into()));
|
|
424
434
|
return Value::Promise(Arc::new(FetchAllResponsesPromise {
|
|
425
435
|
rx: Mutex::new(Some(rx)),
|
|
426
436
|
}));
|
|
@@ -430,7 +440,7 @@ pub fn fetch_all_promise_from_args(args: Vec<Value>) -> Value {
|
|
|
430
440
|
_ => {
|
|
431
441
|
let (tx, rx) = tokio::sync::oneshot::channel();
|
|
432
442
|
let _ = tx.send(Err(
|
|
433
|
-
"Each request must be a string URL or request object".into()
|
|
443
|
+
"Each request must be a string URL or request object".into()
|
|
434
444
|
));
|
|
435
445
|
return Value::Promise(Arc::new(FetchAllResponsesPromise {
|
|
436
446
|
rx: Mutex::new(Some(rx)),
|