@tishlang/tish-format 2.38.0 → 2.43.8

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 (76) hide show
  1. package/Cargo.toml +4 -1
  2. package/bin/tish-format +0 -0
  3. package/crates/tish/src/cli_help.rs +28 -0
  4. package/crates/tish/src/main.rs +41 -5
  5. package/crates/tish/tests/scope_merge.rs +79 -0
  6. package/crates/tish_build_utils/src/lib.rs +27 -1
  7. package/crates/tish_builtins/Cargo.toml +14 -6
  8. package/crates/tish_builtins/src/array.rs +130 -54
  9. package/crates/tish_builtins/src/collections.rs +9 -5
  10. package/crates/tish_builtins/src/construct.rs +7 -1
  11. package/crates/tish_builtins/src/date.rs +15 -1
  12. package/crates/tish_builtins/src/globals.rs +38 -3
  13. package/crates/tish_builtins/src/helpers.rs +7 -3
  14. package/crates/tish_builtins/src/iterator.rs +5 -1
  15. package/crates/tish_builtins/src/lib.rs +3 -0
  16. package/crates/tish_builtins/src/math.rs +14 -0
  17. package/crates/tish_builtins/src/number.rs +72 -6
  18. package/crates/tish_builtins/src/object.rs +6 -1
  19. package/crates/tish_builtins/src/string.rs +13 -2
  20. package/crates/tish_builtins/src/symbol.rs +17 -17
  21. package/crates/tish_builtins/src/typedarrays.rs +9 -2
  22. package/crates/tish_bytecode/src/compiler.rs +76 -2
  23. package/crates/tish_bytecode/src/lib.rs +1 -1
  24. package/crates/tish_bytecode/src/opcode.rs +77 -2
  25. package/crates/tish_compile/src/codegen.rs +812 -47
  26. package/crates/tish_compile/src/infer.rs +37 -41
  27. package/crates/tish_compile/src/lib.rs +13 -1
  28. package/crates/tish_compile/src/platform_resolve.rs +361 -0
  29. package/crates/tish_compile/src/resolve.rs +148 -10
  30. package/crates/tish_compile/src/schemes.rs +278 -0
  31. package/crates/tish_compile/src/types.rs +141 -2
  32. package/crates/tish_compile/tests/perf_codegen_320.rs +2 -2
  33. package/crates/tish_compile/tests/perf_codegen_module_const_forof.rs +3 -1
  34. package/crates/tish_compile/tests/platform_resolve_cli.rs +164 -0
  35. package/crates/tish_compile/tests/regr_gba_numerics_gated.rs +58 -0
  36. package/crates/tish_compiler_wasm/Cargo.toml +1 -0
  37. package/crates/tish_compiler_wasm/src/resolve_virtual.rs +56 -6
  38. package/crates/tish_core/Cargo.toml +39 -4
  39. package/crates/tish_core/src/compat.rs +506 -0
  40. package/crates/tish_core/src/console_style.rs +19 -1
  41. package/crates/tish_core/src/json.rs +34 -10
  42. package/crates/tish_core/src/lib.rs +121 -25
  43. package/crates/tish_core/src/macros.rs +1 -1
  44. package/crates/tish_core/src/shape.rs +4 -2
  45. package/crates/tish_core/src/uri.rs +8 -1
  46. package/crates/tish_core/src/value.rs +182 -54
  47. package/crates/tish_core/src/vmref.rs +17 -5
  48. package/crates/tish_eval/Cargo.toml +2 -0
  49. package/crates/tish_eval/src/eval.rs +90 -3
  50. package/crates/tish_eval/src/value.rs +8 -0
  51. package/crates/tish_eval/src/value_convert.rs +316 -21
  52. package/crates/tish_fmt/Cargo.toml +1 -1
  53. package/crates/tish_lsp/Cargo.toml +2 -0
  54. package/crates/tish_lsp/src/import_goto.rs +41 -14
  55. package/crates/tish_lsp/src/main.rs +18 -0
  56. package/crates/tish_native/src/build.rs +246 -0
  57. package/crates/tish_native/src/config.rs +20 -0
  58. package/crates/tish_native/src/lib.rs +16 -6
  59. package/crates/tish_parser/src/lib.rs +28 -0
  60. package/crates/tish_parser/src/parser.rs +25 -4
  61. package/crates/tish_runtime/src/http_hyper.rs +70 -0
  62. package/crates/tish_runtime/src/lib.rs +55 -10
  63. package/crates/tish_runtime/src/ws.rs +94 -21
  64. package/crates/tish_runtime_gba/Cargo.lock +837 -0
  65. package/crates/tish_runtime_gba/Cargo.toml +16 -0
  66. package/crates/tish_runtime_gba/src/gba.rs +211 -0
  67. package/crates/tish_runtime_gba/src/lib.rs +620 -0
  68. package/crates/tish_vm/src/jit.rs +1446 -164
  69. package/crates/tish_vm/src/vm.rs +535 -173
  70. package/justfile +9 -0
  71. package/package.json +1 -1
  72. package/platform/darwin-arm64/tish-fmt +0 -0
  73. package/platform/darwin-x64/tish-fmt +0 -0
  74. package/platform/linux-arm64/tish-fmt +0 -0
  75. package/platform/linux-x64/tish-fmt +0 -0
  76. package/platform/win32-x64/tish-fmt.exe +0 -0
@@ -145,6 +145,11 @@ pub enum Opcode {
145
145
  /// lower it to a native op / libcall without a runtime shape guard. Behaviour is identical to
146
146
  /// `LoadVar Math; GetMember fn; <arg>; Call 1` on a number.
147
147
  MathUnary = 55,
148
+ /// #203 — apply a BINARY `Math.<fn>` intrinsic (max / min / pow / atan2 / hypot) to the top TWO
149
+ /// numbers: pop `b`, pop `a`, push `Math.fn(a, b)`. The u16 operand is the [`MathBinaryFn`] id.
150
+ /// Same emission gate as [`Opcode::MathUnary`] (`Math` provably the unshadowed global) but for
151
+ /// exactly two args. Behaviour identical to `LoadVar Math; GetMember fn; <a>; <b>; Call 2`.
152
+ MathBinary = 56,
148
153
  }
149
154
 
150
155
  /// The unary `Math` functions the [`Opcode::MathUnary`] fast path recognizes (#186). f64→f64;
@@ -289,11 +294,81 @@ impl MathUnaryFn {
289
294
  }
290
295
  }
291
296
 
297
+ /// The binary `Math` functions the [`Opcode::MathBinary`] fast path recognizes (#203). `(f64, f64) →
298
+ /// f64`; the discriminant is the opcode operand. Kept in sync with the VM handler and JIT lowering.
299
+ /// (`hypot` is intentionally NOT here — it stays a correct generic call to avoid replicating its
300
+ /// scaled-sum-of-squares in this below-builtins crate.)
301
+ #[derive(Debug, Clone, Copy, PartialEq, Eq)]
302
+ #[repr(u16)]
303
+ pub enum MathBinaryFn {
304
+ Max = 0,
305
+ Min = 1,
306
+ Pow = 2,
307
+ Atan2 = 3,
308
+ }
309
+
310
+ impl MathBinaryFn {
311
+ /// Map a `Math.<name>` member to its id, or `None` if it isn't a supported 2-arg intrinsic.
312
+ pub fn from_name(name: &str) -> Option<MathBinaryFn> {
313
+ Some(match name {
314
+ "max" => MathBinaryFn::Max,
315
+ "min" => MathBinaryFn::Min,
316
+ "pow" => MathBinaryFn::Pow,
317
+ "atan2" => MathBinaryFn::Atan2,
318
+ _ => return None,
319
+ })
320
+ }
321
+
322
+ /// Decode an opcode operand to the fn id (safe match — no transmute).
323
+ pub fn from_u16(v: u16) -> Option<MathBinaryFn> {
324
+ use MathBinaryFn::*;
325
+ Some(match v {
326
+ 0 => Max,
327
+ 1 => Min,
328
+ 2 => Pow,
329
+ 3 => Atan2,
330
+ _ => return None,
331
+ })
332
+ }
333
+
334
+ /// Apply the intrinsic — the single source of truth for VM + JIT result parity. Replicates the JS
335
+ /// semantics of `tishlang_builtins::math` (this crate sits below builtins), so VM/JIT == interp.
336
+ #[inline]
337
+ pub fn apply(self, a: f64, b: f64) -> f64 {
338
+ match self {
339
+ // Math.max(a,b): NaN if either is NaN; else the larger, with +0 preferred over -0. Exactly
340
+ // `max_f64(&[a, b])`.
341
+ MathBinaryFn::Max => {
342
+ if a.is_nan() || b.is_nan() {
343
+ f64::NAN
344
+ } else if a > b || (a == 0.0 && b == 0.0 && a.is_sign_positive()) {
345
+ a
346
+ } else {
347
+ b
348
+ }
349
+ }
350
+ // Math.min(a,b): NaN if either is NaN; else the smaller, with -0 preferred. Exactly
351
+ // `min_f64(&[a, b])`.
352
+ MathBinaryFn::Min => {
353
+ if a.is_nan() || b.is_nan() {
354
+ f64::NAN
355
+ } else if a < b || (a == 0.0 && b == 0.0 && a.is_sign_negative()) {
356
+ a
357
+ } else {
358
+ b
359
+ }
360
+ }
361
+ MathBinaryFn::Pow => a.powf(b),
362
+ MathBinaryFn::Atan2 => a.atan2(b),
363
+ }
364
+ }
365
+ }
366
+
292
367
  impl Opcode {
293
- /// Decode byte to opcode. Safe for b in 0..=55 (matches #[repr(u8)] discriminants).
368
+ /// Decode byte to opcode. Safe for b in 0..=56 (matches #[repr(u8)] discriminants).
294
369
  #[inline]
295
370
  pub fn from_u8(b: u8) -> Option<Opcode> {
296
- if b <= 55 {
371
+ if b <= 56 {
297
372
  Some(unsafe { std::mem::transmute::<u8, Opcode>(b) })
298
373
  } else {
299
374
  None