@tishlang/tish 1.0.7 → 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.
Files changed (127) hide show
  1. package/Cargo.toml +43 -0
  2. package/LICENSE +13 -0
  3. package/README.md +66 -0
  4. package/crates/js_to_tish/Cargo.toml +9 -0
  5. package/crates/js_to_tish/README.md +18 -0
  6. package/crates/js_to_tish/src/error.rs +61 -0
  7. package/crates/js_to_tish/src/lib.rs +11 -0
  8. package/crates/js_to_tish/src/span_util.rs +35 -0
  9. package/crates/js_to_tish/src/transform/expr.rs +608 -0
  10. package/crates/js_to_tish/src/transform/stmt.rs +474 -0
  11. package/crates/js_to_tish/src/transform.rs +60 -0
  12. package/crates/tish/Cargo.toml +44 -0
  13. package/crates/tish/src/main.rs +585 -0
  14. package/crates/tish/src/repl_completion.rs +200 -0
  15. package/crates/tish/tests/integration_test.rs +726 -0
  16. package/crates/tish_ast/Cargo.toml +7 -0
  17. package/crates/tish_ast/src/ast.rs +494 -0
  18. package/crates/tish_ast/src/lib.rs +5 -0
  19. package/crates/tish_build_utils/Cargo.toml +5 -0
  20. package/crates/tish_build_utils/src/lib.rs +175 -0
  21. package/crates/tish_builtins/Cargo.toml +12 -0
  22. package/crates/tish_builtins/src/array.rs +410 -0
  23. package/crates/tish_builtins/src/globals.rs +197 -0
  24. package/crates/tish_builtins/src/helpers.rs +38 -0
  25. package/crates/tish_builtins/src/lib.rs +14 -0
  26. package/crates/tish_builtins/src/math.rs +80 -0
  27. package/crates/tish_builtins/src/object.rs +36 -0
  28. package/crates/tish_builtins/src/string.rs +253 -0
  29. package/crates/tish_bytecode/Cargo.toml +15 -0
  30. package/crates/tish_bytecode/src/chunk.rs +97 -0
  31. package/crates/tish_bytecode/src/compiler.rs +1361 -0
  32. package/crates/tish_bytecode/src/encoding.rs +100 -0
  33. package/crates/tish_bytecode/src/lib.rs +19 -0
  34. package/crates/tish_bytecode/src/opcode.rs +110 -0
  35. package/crates/tish_bytecode/src/peephole.rs +159 -0
  36. package/crates/tish_bytecode/src/serialize.rs +163 -0
  37. package/crates/tish_bytecode/tests/constant_folding.rs +84 -0
  38. package/crates/tish_bytecode/tests/shortcircuit.rs +49 -0
  39. package/crates/tish_bytecode/tests/sort_optimization.rs +31 -0
  40. package/crates/tish_compile/Cargo.toml +21 -0
  41. package/crates/tish_compile/src/codegen.rs +3316 -0
  42. package/crates/tish_compile/src/lib.rs +71 -0
  43. package/crates/tish_compile/src/resolve.rs +631 -0
  44. package/crates/tish_compile/src/types.rs +304 -0
  45. package/crates/tish_compile_js/Cargo.toml +16 -0
  46. package/crates/tish_compile_js/examples/jsx_vdom_smoke.tish +8 -0
  47. package/crates/tish_compile_js/src/codegen.rs +794 -0
  48. package/crates/tish_compile_js/src/error.rs +20 -0
  49. package/crates/tish_compile_js/src/js_intrinsics.rs +82 -0
  50. package/crates/tish_compile_js/src/lib.rs +27 -0
  51. package/crates/tish_compile_js/src/tests_jsx.rs +32 -0
  52. package/crates/tish_compiler_wasm/Cargo.toml +19 -0
  53. package/crates/tish_compiler_wasm/src/lib.rs +55 -0
  54. package/crates/tish_compiler_wasm/src/resolve_virtual.rs +462 -0
  55. package/crates/tish_core/Cargo.toml +11 -0
  56. package/crates/tish_core/src/console_style.rs +128 -0
  57. package/crates/tish_core/src/json.rs +327 -0
  58. package/crates/tish_core/src/lib.rs +15 -0
  59. package/crates/tish_core/src/macros.rs +37 -0
  60. package/crates/tish_core/src/uri.rs +115 -0
  61. package/crates/tish_core/src/value.rs +376 -0
  62. package/crates/tish_cranelift/Cargo.toml +17 -0
  63. package/crates/tish_cranelift/src/lib.rs +41 -0
  64. package/crates/tish_cranelift/src/link.rs +120 -0
  65. package/crates/tish_cranelift/src/lower.rs +77 -0
  66. package/crates/tish_cranelift_runtime/Cargo.toml +19 -0
  67. package/crates/tish_cranelift_runtime/src/lib.rs +43 -0
  68. package/crates/tish_eval/Cargo.toml +26 -0
  69. package/crates/tish_eval/src/eval.rs +3205 -0
  70. package/crates/tish_eval/src/http.rs +122 -0
  71. package/crates/tish_eval/src/lib.rs +59 -0
  72. package/crates/tish_eval/src/natives.rs +301 -0
  73. package/crates/tish_eval/src/promise.rs +173 -0
  74. package/crates/tish_eval/src/regex.rs +298 -0
  75. package/crates/tish_eval/src/timers.rs +111 -0
  76. package/crates/tish_eval/src/value.rs +224 -0
  77. package/crates/tish_eval/src/value_convert.rs +85 -0
  78. package/crates/tish_fmt/Cargo.toml +16 -0
  79. package/crates/tish_fmt/src/bin/tish-fmt.rs +41 -0
  80. package/crates/tish_fmt/src/lib.rs +884 -0
  81. package/crates/tish_jsx_web/Cargo.toml +7 -0
  82. package/crates/tish_jsx_web/README.md +18 -0
  83. package/crates/tish_jsx_web/src/lib.rs +157 -0
  84. package/crates/tish_jsx_web/vendor/Lattish.tish +347 -0
  85. package/crates/tish_lexer/Cargo.toml +7 -0
  86. package/crates/tish_lexer/src/lib.rs +430 -0
  87. package/crates/tish_lexer/src/token.rs +155 -0
  88. package/crates/tish_lint/Cargo.toml +17 -0
  89. package/crates/tish_lint/src/bin/tish-lint.rs +77 -0
  90. package/crates/tish_lint/src/lib.rs +278 -0
  91. package/crates/tish_llvm/Cargo.toml +11 -0
  92. package/crates/tish_llvm/src/lib.rs +106 -0
  93. package/crates/tish_lsp/Cargo.toml +22 -0
  94. package/crates/tish_lsp/README.md +26 -0
  95. package/crates/tish_lsp/src/main.rs +615 -0
  96. package/crates/tish_native/Cargo.toml +14 -0
  97. package/crates/tish_native/src/build.rs +102 -0
  98. package/crates/tish_native/src/lib.rs +237 -0
  99. package/crates/tish_opt/Cargo.toml +11 -0
  100. package/crates/tish_opt/src/lib.rs +896 -0
  101. package/crates/tish_parser/Cargo.toml +9 -0
  102. package/crates/tish_parser/src/lib.rs +123 -0
  103. package/crates/tish_parser/src/parser.rs +1714 -0
  104. package/crates/tish_runtime/Cargo.toml +26 -0
  105. package/crates/tish_runtime/src/http.rs +308 -0
  106. package/crates/tish_runtime/src/http_fetch.rs +453 -0
  107. package/crates/tish_runtime/src/lib.rs +1004 -0
  108. package/crates/tish_runtime/src/native_promise.rs +26 -0
  109. package/crates/tish_runtime/src/promise.rs +77 -0
  110. package/crates/tish_runtime/src/promise_io.rs +41 -0
  111. package/crates/tish_runtime/src/timers.rs +125 -0
  112. package/crates/tish_runtime/src/ws.rs +725 -0
  113. package/crates/tish_runtime/tests/fetch_readable_stream.rs +99 -0
  114. package/crates/tish_vm/Cargo.toml +31 -0
  115. package/crates/tish_vm/src/lib.rs +39 -0
  116. package/crates/tish_vm/src/vm.rs +1399 -0
  117. package/crates/tish_wasm/Cargo.toml +13 -0
  118. package/crates/tish_wasm/src/lib.rs +358 -0
  119. package/crates/tish_wasm_runtime/Cargo.toml +25 -0
  120. package/crates/tish_wasm_runtime/src/lib.rs +36 -0
  121. package/justfile +260 -0
  122. package/package.json +8 -3
  123. package/platform/darwin-arm64/tish +0 -0
  124. package/platform/darwin-x64/tish +0 -0
  125. package/platform/linux-arm64/tish +0 -0
  126. package/platform/linux-x64/tish +0 -0
  127. package/platform/win32-x64/tish.exe +0 -0
@@ -0,0 +1,85 @@
1
+ //! Conversion between tish_eval::Value and tish_core::Value for opaque method calls.
2
+
3
+ use std::cell::RefCell;
4
+ use std::collections::HashMap;
5
+ use std::rc::Rc;
6
+ use std::sync::Arc;
7
+
8
+ use tish_core::Value as CoreValue;
9
+
10
+ use crate::value::Value;
11
+
12
+ /// Convert interpreter Value to core Value. Fails for interpreter-only variants.
13
+ pub fn eval_to_core(v: &Value) -> Result<CoreValue, String> {
14
+ match v {
15
+ Value::Number(n) => Ok(CoreValue::Number(*n)),
16
+ Value::String(s) => Ok(CoreValue::String(Arc::clone(s))),
17
+ Value::Bool(b) => Ok(CoreValue::Bool(*b)),
18
+ Value::Null => Ok(CoreValue::Null),
19
+ Value::Array(arr) => {
20
+ let mut out = Vec::new();
21
+ for item in arr.borrow().iter() {
22
+ out.push(eval_to_core(item)?);
23
+ }
24
+ Ok(CoreValue::Array(Rc::new(RefCell::new(out))))
25
+ }
26
+ Value::Object(map) => {
27
+ let mut out = HashMap::new();
28
+ for (k, v) in map.borrow().iter() {
29
+ out.insert(Arc::clone(k), eval_to_core(v)?);
30
+ }
31
+ Ok(CoreValue::Object(Rc::new(RefCell::new(out))))
32
+ }
33
+ Value::Opaque(o) => Ok(CoreValue::Opaque(Arc::clone(o))),
34
+ _ => Err(format!(
35
+ "Cannot pass {:?} to native function (unsupported type)",
36
+ std::mem::discriminant(v)
37
+ )),
38
+ }
39
+ }
40
+
41
+ /// Convert core Value to interpreter Value.
42
+ pub fn core_to_eval(v: CoreValue) -> Value {
43
+ match v {
44
+ CoreValue::Number(n) => Value::Number(n),
45
+ CoreValue::String(s) => Value::String(s),
46
+ CoreValue::Bool(b) => Value::Bool(b),
47
+ CoreValue::Null => Value::Null,
48
+ CoreValue::Array(arr) => {
49
+ let mut out = Vec::new();
50
+ for item in arr.borrow().iter() {
51
+ out.push(core_to_eval(item.clone()));
52
+ }
53
+ Value::Array(Rc::new(RefCell::new(out)))
54
+ }
55
+ CoreValue::Object(map) => {
56
+ let mut out = HashMap::new();
57
+ for (k, v) in map.borrow().iter() {
58
+ out.insert(Arc::clone(k), core_to_eval(v.clone()));
59
+ }
60
+ Value::Object(Rc::new(RefCell::new(out)))
61
+ }
62
+ CoreValue::Opaque(o) => Value::Opaque(o),
63
+ #[cfg(feature = "http")]
64
+ CoreValue::Promise(p) => Value::CorePromise(Arc::clone(&p)),
65
+ #[cfg(not(feature = "http"))]
66
+ CoreValue::Promise(_) => Value::Null,
67
+ #[cfg(any(feature = "http", feature = "ws"))]
68
+ CoreValue::Function(f) => Value::CoreFn(Rc::clone(&f)),
69
+ #[cfg(not(any(feature = "http", feature = "ws")))]
70
+ CoreValue::Function(_) => Value::Null,
71
+ // tish_core gets regex from http or regex features; handle RegExp when it exists
72
+ #[cfg(any(feature = "http", feature = "regex"))]
73
+ CoreValue::RegExp(re) => {
74
+ #[cfg(feature = "regex")]
75
+ {
76
+ Value::RegExp(re)
77
+ }
78
+ #[cfg(not(feature = "regex"))]
79
+ {
80
+ let _ = re;
81
+ Value::Null
82
+ }
83
+ }
84
+ }
85
+ }
@@ -0,0 +1,16 @@
1
+ [package]
2
+ name = "tish_fmt"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+ description = "Opinionated formatter for Tish source (parse → pretty-print)"
6
+ license-file = { workspace = true }
7
+ repository = { workspace = true }
8
+
9
+ [[bin]]
10
+ name = "tish-fmt"
11
+ path = "src/bin/tish-fmt.rs"
12
+
13
+ [dependencies]
14
+ clap = { version = "4.6.0", features = ["derive"] }
15
+ tish_ast = { path = "../tish_ast" }
16
+ tish_parser = { path = "../tish_parser" }
@@ -0,0 +1,41 @@
1
+ //! Standalone formatter — not part of the `tish` compiler CLI.
2
+
3
+ use std::fs;
4
+
5
+ use clap::Parser;
6
+
7
+ #[derive(Parser)]
8
+ #[command(name = "tish-fmt")]
9
+ #[command(about = "Format Tish source (pretty-print via AST)")]
10
+ struct Cli {
11
+ #[arg(required = true)]
12
+ file: String,
13
+ #[arg(long)]
14
+ check: bool,
15
+ }
16
+
17
+ fn main() {
18
+ let cli = Cli::parse();
19
+ if let Err(e) = run(&cli.file, cli.check) {
20
+ eprintln!("{}", e);
21
+ std::process::exit(1);
22
+ }
23
+ }
24
+
25
+ fn run(path: &str, check: bool) -> Result<(), String> {
26
+ let source = fs::read_to_string(path).map_err(|e| format!("Cannot read {}: {}", path, e))?;
27
+ let formatted = tish_fmt::format_source(&source)?;
28
+ if check {
29
+ if formatted != source {
30
+ return Err(format!(
31
+ "Format check failed: {} needs formatting (run `tish-fmt {}`)",
32
+ path, path
33
+ ));
34
+ }
35
+ println!("{}: OK", path);
36
+ return Ok(());
37
+ }
38
+ fs::write(path, formatted).map_err(|e| format!("Cannot write {}: {}", path, e))?;
39
+ println!("Formatted: {}", path);
40
+ Ok(())
41
+ }