@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.
Files changed (79) hide show
  1. package/Cargo.toml +1 -0
  2. package/bin/tish +0 -0
  3. package/crates/js_to_tish/src/error.rs +2 -8
  4. package/crates/js_to_tish/src/transform/expr.rs +101 -130
  5. package/crates/js_to_tish/src/transform/stmt.rs +25 -22
  6. package/crates/tish/Cargo.toml +1 -1
  7. package/crates/tish/src/cli_help.rs +76 -29
  8. package/crates/tish/src/main.rs +85 -54
  9. package/crates/tish/tests/cargo_example_compile.rs +3 -1
  10. package/crates/tish/tests/integration_test.rs +197 -47
  11. package/crates/tish/tests/run_optimize_stdout_parity.rs +3 -7
  12. package/crates/tish/tests/shortcircuit.rs +19 -4
  13. package/crates/tish_ast/src/ast.rs +12 -14
  14. package/crates/tish_build_utils/src/lib.rs +31 -6
  15. package/crates/tish_builtins/src/array.rs +52 -21
  16. package/crates/tish_builtins/src/construct.rs +2 -8
  17. package/crates/tish_builtins/src/globals.rs +30 -15
  18. package/crates/tish_builtins/src/lib.rs +5 -5
  19. package/crates/tish_builtins/src/math.rs +5 -3
  20. package/crates/tish_builtins/src/string.rs +71 -19
  21. package/crates/tish_bytecode/src/chunk.rs +0 -1
  22. package/crates/tish_bytecode/src/compiler.rs +164 -60
  23. package/crates/tish_bytecode/src/opcode.rs +13 -4
  24. package/crates/tish_bytecode/src/peephole.rs +2 -2
  25. package/crates/tish_compile/src/codegen.rs +921 -299
  26. package/crates/tish_compile/src/infer.rs +69 -19
  27. package/crates/tish_compile/src/lib.rs +15 -5
  28. package/crates/tish_compile/src/resolve.rs +112 -69
  29. package/crates/tish_compile/src/types.rs +10 -14
  30. package/crates/tish_compile_js/src/codegen.rs +34 -13
  31. package/crates/tish_compile_js/src/tests_jsx.rs +30 -6
  32. package/crates/tish_compiler_wasm/src/lib.rs +16 -13
  33. package/crates/tish_compiler_wasm/src/resolve_virtual.rs +39 -48
  34. package/crates/tish_core/src/json.rs +5 -3
  35. package/crates/tish_core/src/lib.rs +1 -1
  36. package/crates/tish_core/src/uri.rs +9 -6
  37. package/crates/tish_core/src/value.rs +92 -28
  38. package/crates/tish_cranelift/src/link.rs +6 -9
  39. package/crates/tish_cranelift/src/lower.rs +14 -8
  40. package/crates/tish_eval/src/eval.rs +389 -142
  41. package/crates/tish_eval/src/lib.rs +10 -6
  42. package/crates/tish_eval/src/natives.rs +95 -38
  43. package/crates/tish_eval/src/promise.rs +14 -8
  44. package/crates/tish_eval/src/timers.rs +28 -19
  45. package/crates/tish_eval/src/value.rs +10 -3
  46. package/crates/tish_fmt/src/lib.rs +29 -13
  47. package/crates/tish_lexer/src/lib.rs +217 -63
  48. package/crates/tish_lexer/src/token.rs +6 -6
  49. package/crates/tish_llvm/src/lib.rs +15 -8
  50. package/crates/tish_lsp/src/main.rs +41 -43
  51. package/crates/tish_native/src/build.rs +1 -6
  52. package/crates/tish_native/src/lib.rs +48 -19
  53. package/crates/tish_opt/src/lib.rs +67 -50
  54. package/crates/tish_parser/src/lib.rs +36 -11
  55. package/crates/tish_parser/src/parser.rs +172 -87
  56. package/crates/tish_runtime/src/http.rs +15 -6
  57. package/crates/tish_runtime/src/http_fetch.rs +24 -14
  58. package/crates/tish_runtime/src/lib.rs +224 -168
  59. package/crates/tish_runtime/src/promise.rs +1 -5
  60. package/crates/tish_runtime/src/ws.rs +45 -20
  61. package/crates/tish_runtime/tests/fetch_readable_stream.rs +5 -4
  62. package/crates/tish_ui/src/jsx.rs +41 -22
  63. package/crates/tish_ui/src/lib.rs +2 -2
  64. package/crates/tish_vm/src/vm.rs +309 -112
  65. package/crates/tish_vm/tests/peephole_jump_chain_logical_or.rs +8 -3
  66. package/crates/tish_wasm/src/lib.rs +38 -28
  67. package/crates/tishlang_cargo_bindgen/Cargo.toml +25 -0
  68. package/crates/tishlang_cargo_bindgen/src/classify.rs +265 -0
  69. package/crates/tishlang_cargo_bindgen/src/discover.rs +52 -0
  70. package/crates/tishlang_cargo_bindgen/src/infer.rs +372 -0
  71. package/crates/tishlang_cargo_bindgen/src/lib.rs +349 -0
  72. package/crates/tishlang_cargo_bindgen/src/main.rs +164 -0
  73. package/crates/tishlang_cargo_bindgen/src/metadata.rs +114 -0
  74. package/package.json +1 -1
  75. package/platform/darwin-arm64/tish +0 -0
  76. package/platform/darwin-x64/tish +0 -0
  77. package/platform/linux-arm64/tish +0 -0
  78. package/platform/linux-x64/tish +0 -0
  79. 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<Option<tokio::sync::oneshot::Receiver<Result<Vec<Result<reqwest::Response, String>>, String>>>>,
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| x.map(response_value_from_reqwest).unwrap_or_else(|e| build_error_response(&e)))
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.take().ok_or_else(|| "Response body already consumed".to_string())?;
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 => Err("ReadableStream is locked; getReader() already called".into()),
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 => Err(
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 _ = tx.send(Err("Each request object must have a 'url' property".into()));
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)),