@tishlang/tish-format 1.0.12 → 1.0.13

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 (164) hide show
  1. package/Cargo.toml +49 -0
  2. package/LICENSE +13 -0
  3. package/README.md +138 -0
  4. package/bin/tish-format +0 -0
  5. package/crates/js_to_tish/Cargo.toml +11 -0
  6. package/crates/js_to_tish/README.md +18 -0
  7. package/crates/js_to_tish/src/error.rs +55 -0
  8. package/crates/js_to_tish/src/lib.rs +11 -0
  9. package/crates/js_to_tish/src/span_util.rs +35 -0
  10. package/crates/js_to_tish/src/transform/expr.rs +610 -0
  11. package/crates/js_to_tish/src/transform/stmt.rs +503 -0
  12. package/crates/js_to_tish/src/transform.rs +60 -0
  13. package/crates/tish/Cargo.toml +54 -0
  14. package/crates/tish/src/cargo_native_registry.rs +32 -0
  15. package/crates/tish/src/cli_help.rs +565 -0
  16. package/crates/tish/src/main.rs +781 -0
  17. package/crates/tish/src/repl_completion.rs +200 -0
  18. package/crates/tish/tests/cargo_example_compile.rs +67 -0
  19. package/crates/tish/tests/fixtures/cargo_example_project/Cargo.toml +3 -0
  20. package/crates/tish/tests/fixtures/cargo_example_project/crates/demo-shim/Cargo.toml +11 -0
  21. package/crates/tish/tests/fixtures/cargo_example_project/crates/demo-shim/src/lib.rs +12 -0
  22. package/crates/tish/tests/fixtures/cargo_example_project/package.json +10 -0
  23. package/crates/tish/tests/fixtures/cargo_example_project/src/main.tish +3 -0
  24. package/crates/tish/tests/integration_test.rs +1095 -0
  25. package/crates/tish/tests/run_optimize_stdout_parity.rs +50 -0
  26. package/crates/tish/tests/shortcircuit.rs +65 -0
  27. package/crates/tish_ast/Cargo.toml +9 -0
  28. package/crates/tish_ast/src/ast.rs +620 -0
  29. package/crates/tish_ast/src/lib.rs +5 -0
  30. package/crates/tish_build_utils/Cargo.toml +11 -0
  31. package/crates/tish_build_utils/src/lib.rs +577 -0
  32. package/crates/tish_builtins/Cargo.toml +20 -0
  33. package/crates/tish_builtins/src/array.rs +441 -0
  34. package/crates/tish_builtins/src/construct.rs +159 -0
  35. package/crates/tish_builtins/src/globals.rs +213 -0
  36. package/crates/tish_builtins/src/helpers.rs +35 -0
  37. package/crates/tish_builtins/src/lib.rs +16 -0
  38. package/crates/tish_builtins/src/math.rs +89 -0
  39. package/crates/tish_builtins/src/object.rs +36 -0
  40. package/crates/tish_builtins/src/string.rs +647 -0
  41. package/crates/tish_builtins/src/symbol.rs +83 -0
  42. package/crates/tish_bytecode/Cargo.toml +17 -0
  43. package/crates/tish_bytecode/src/chunk.rs +96 -0
  44. package/crates/tish_bytecode/src/compiler.rs +1760 -0
  45. package/crates/tish_bytecode/src/encoding.rs +100 -0
  46. package/crates/tish_bytecode/src/lib.rs +19 -0
  47. package/crates/tish_bytecode/src/opcode.rs +142 -0
  48. package/crates/tish_bytecode/src/peephole.rs +189 -0
  49. package/crates/tish_bytecode/src/serialize.rs +163 -0
  50. package/crates/tish_bytecode/tests/break_continue_bytecode.rs +44 -0
  51. package/crates/tish_bytecode/tests/constant_folding.rs +84 -0
  52. package/crates/tish_bytecode/tests/sort_optimization.rs +31 -0
  53. package/crates/tish_compile/Cargo.toml +26 -0
  54. package/crates/tish_compile/src/codegen.rs +5332 -0
  55. package/crates/tish_compile/src/infer.rs +292 -0
  56. package/crates/tish_compile/src/lib.rs +164 -0
  57. package/crates/tish_compile/src/resolve.rs +1388 -0
  58. package/crates/tish_compile/src/types.rs +501 -0
  59. package/crates/tish_compile_js/Cargo.toml +18 -0
  60. package/crates/tish_compile_js/examples/jsx_vdom_smoke.tish +8 -0
  61. package/crates/tish_compile_js/src/codegen.rs +871 -0
  62. package/crates/tish_compile_js/src/error.rs +20 -0
  63. package/crates/tish_compile_js/src/lib.rs +26 -0
  64. package/crates/tish_compile_js/src/tests_jsx.rs +350 -0
  65. package/crates/tish_compiler_wasm/Cargo.toml +21 -0
  66. package/crates/tish_compiler_wasm/src/lib.rs +57 -0
  67. package/crates/tish_compiler_wasm/src/resolve_virtual.rs +473 -0
  68. package/crates/tish_core/Cargo.toml +26 -0
  69. package/crates/tish_core/src/console_style.rs +160 -0
  70. package/crates/tish_core/src/json.rs +387 -0
  71. package/crates/tish_core/src/lib.rs +17 -0
  72. package/crates/tish_core/src/macros.rs +36 -0
  73. package/crates/tish_core/src/uri.rs +118 -0
  74. package/crates/tish_core/src/value.rs +696 -0
  75. package/crates/tish_core/src/vmref.rs +178 -0
  76. package/crates/tish_cranelift/Cargo.toml +19 -0
  77. package/crates/tish_cranelift/src/lib.rs +43 -0
  78. package/crates/tish_cranelift/src/link.rs +117 -0
  79. package/crates/tish_cranelift/src/lower.rs +85 -0
  80. package/crates/tish_cranelift_runtime/Cargo.toml +25 -0
  81. package/crates/tish_cranelift_runtime/src/lib.rs +45 -0
  82. package/crates/tish_eval/Cargo.toml +45 -0
  83. package/crates/tish_eval/src/eval.rs +3717 -0
  84. package/crates/tish_eval/src/http.rs +188 -0
  85. package/crates/tish_eval/src/lib.rs +99 -0
  86. package/crates/tish_eval/src/natives.rs +399 -0
  87. package/crates/tish_eval/src/promise.rs +179 -0
  88. package/crates/tish_eval/src/regex.rs +299 -0
  89. package/crates/tish_eval/src/timers.rs +120 -0
  90. package/crates/tish_eval/src/value.rs +318 -0
  91. package/crates/tish_eval/src/value_convert.rs +111 -0
  92. package/crates/tish_fmt/Cargo.toml +16 -0
  93. package/crates/tish_fmt/src/bin/tish-fmt.rs +41 -0
  94. package/crates/tish_fmt/src/lib.rs +2101 -0
  95. package/crates/tish_jsx_web/Cargo.toml +9 -0
  96. package/crates/tish_jsx_web/README.md +5 -0
  97. package/crates/tish_jsx_web/src/lib.rs +2 -0
  98. package/crates/tish_lexer/Cargo.toml +9 -0
  99. package/crates/tish_lexer/src/lib.rs +716 -0
  100. package/crates/tish_lexer/src/token.rs +163 -0
  101. package/crates/tish_lint/Cargo.toml +18 -0
  102. package/crates/tish_lint/src/bin/tish-lint.rs +195 -0
  103. package/crates/tish_lint/src/lib.rs +289 -0
  104. package/crates/tish_llvm/Cargo.toml +13 -0
  105. package/crates/tish_llvm/src/lib.rs +115 -0
  106. package/crates/tish_lsp/Cargo.toml +25 -0
  107. package/crates/tish_lsp/README.md +26 -0
  108. package/crates/tish_lsp/src/builtin_goto.rs +362 -0
  109. package/crates/tish_lsp/src/import_goto.rs +562 -0
  110. package/crates/tish_lsp/src/main.rs +1046 -0
  111. package/crates/tish_native/Cargo.toml +16 -0
  112. package/crates/tish_native/src/build.rs +427 -0
  113. package/crates/tish_native/src/config.rs +48 -0
  114. package/crates/tish_native/src/lib.rs +416 -0
  115. package/crates/tish_opt/Cargo.toml +13 -0
  116. package/crates/tish_opt/src/lib.rs +943 -0
  117. package/crates/tish_parser/Cargo.toml +11 -0
  118. package/crates/tish_parser/src/lib.rs +332 -0
  119. package/crates/tish_parser/src/parser.rs +2304 -0
  120. package/crates/tish_pg/Cargo.toml +34 -0
  121. package/crates/tish_pg/README.md +38 -0
  122. package/crates/tish_pg/src/error.rs +52 -0
  123. package/crates/tish_pg/src/lib.rs +955 -0
  124. package/crates/tish_resolve/Cargo.toml +13 -0
  125. package/crates/tish_resolve/src/lib.rs +3561 -0
  126. package/crates/tish_resolve/src/pos.rs +141 -0
  127. package/crates/tish_runtime/Cargo.toml +96 -0
  128. package/crates/tish_runtime/src/http.rs +1298 -0
  129. package/crates/tish_runtime/src/http_fetch.rs +471 -0
  130. package/crates/tish_runtime/src/http_hyper.rs +418 -0
  131. package/crates/tish_runtime/src/http_prefork.rs +189 -0
  132. package/crates/tish_runtime/src/lib.rs +1192 -0
  133. package/crates/tish_runtime/src/native_promise.rs +15 -0
  134. package/crates/tish_runtime/src/promise.rs +248 -0
  135. package/crates/tish_runtime/src/promise_io.rs +38 -0
  136. package/crates/tish_runtime/src/timers.rs +166 -0
  137. package/crates/tish_runtime/src/ws.rs +761 -0
  138. package/crates/tish_runtime/tests/fetch_readable_stream.rs +102 -0
  139. package/crates/tish_ui/Cargo.toml +17 -0
  140. package/crates/tish_ui/src/jsx.rs +682 -0
  141. package/crates/tish_ui/src/lib.rs +20 -0
  142. package/crates/tish_ui/src/runtime/hooks.rs +569 -0
  143. package/crates/tish_ui/src/runtime/mod.rs +180 -0
  144. package/crates/tish_vm/Cargo.toml +47 -0
  145. package/crates/tish_vm/src/lib.rs +39 -0
  146. package/crates/tish_vm/src/vm.rs +2192 -0
  147. package/crates/tish_vm/tests/fixtures/or_string_cmd.tish +2 -0
  148. package/crates/tish_vm/tests/lexical_scope_declare.rs +34 -0
  149. package/crates/tish_vm/tests/peephole_jump_chain_logical_or.rs +150 -0
  150. package/crates/tish_wasm/Cargo.toml +15 -0
  151. package/crates/tish_wasm/src/lib.rs +424 -0
  152. package/crates/tish_wasm_runtime/Cargo.toml +37 -0
  153. package/crates/tish_wasm_runtime/src/gpu.rs +413 -0
  154. package/crates/tish_wasm_runtime/src/lib.rs +42 -0
  155. package/crates/tishlang_cargo_bindgen/Cargo.toml +26 -0
  156. package/crates/tishlang_cargo_bindgen/src/classify.rs +263 -0
  157. package/crates/tishlang_cargo_bindgen/src/discover.rs +125 -0
  158. package/crates/tishlang_cargo_bindgen/src/infer.rs +382 -0
  159. package/crates/tishlang_cargo_bindgen/src/lib.rs +349 -0
  160. package/crates/tishlang_cargo_bindgen/src/main.rs +167 -0
  161. package/crates/tishlang_cargo_bindgen/src/metadata.rs +117 -0
  162. package/justfile +268 -0
  163. package/package.json +1 -1
  164. package/platform/darwin-arm64/tish-fmt +0 -0
@@ -0,0 +1,83 @@
1
+ //! ECMAScript-style `Symbol`, `Symbol.for`, `Symbol.keyFor`.
2
+
3
+ use std::collections::hash_map::Entry;
4
+ use std::sync::{Arc, Mutex, OnceLock};
5
+
6
+ use std::collections::HashMap;
7
+
8
+ use tishlang_core::{alloc_symbol_id, ObjectMap, TishSymbol, Value};
9
+
10
+ static SYMBOL_FOR_REGISTRY: OnceLock<Mutex<HashMap<Arc<str>, Arc<TishSymbol>>>> = OnceLock::new();
11
+
12
+ fn symbol_registry() -> &'static Mutex<HashMap<Arc<str>, Arc<TishSymbol>>> {
13
+ SYMBOL_FOR_REGISTRY.get_or_init(|| Mutex::new(HashMap::new()))
14
+ }
15
+
16
+ fn symbol_for_impl(key: &str) -> Value {
17
+ let k: Arc<str> = key.into();
18
+ let mut reg = symbol_registry().lock().unwrap();
19
+ let sym = match reg.entry(Arc::clone(&k)) {
20
+ Entry::Occupied(e) => e.get().clone(),
21
+ Entry::Vacant(v) => {
22
+ let id = alloc_symbol_id();
23
+ let sym = TishSymbol::new_registry(id, Arc::clone(&k), None);
24
+ v.insert(Arc::clone(&sym));
25
+ sym
26
+ }
27
+ };
28
+ Value::Symbol(sym)
29
+ }
30
+
31
+ fn symbol_new(args: &[Value]) -> Value {
32
+ let desc = args.first().and_then(|v| {
33
+ if matches!(v, Value::Null) {
34
+ None
35
+ } else {
36
+ Some(v.to_display_string().into())
37
+ }
38
+ });
39
+ Value::Symbol(TishSymbol::new_unique(desc))
40
+ }
41
+
42
+ fn symbol_key_for_impl(args: &[Value]) -> Value {
43
+ match args.first() {
44
+ Some(Value::Symbol(s)) => s
45
+ .registry_key
46
+ .as_ref()
47
+ .map(|k| Value::String(Arc::clone(k)))
48
+ .unwrap_or(Value::Null),
49
+ _ => Value::Null,
50
+ }
51
+ }
52
+
53
+ /// Global `Symbol`: `Symbol("desc")` via `__call` / `__construct`, `Symbol.for`, `Symbol.keyFor`.
54
+ pub fn symbol_object() -> Value {
55
+ let call = Value::native(symbol_new);
56
+ let for_fn = Value::native(|args: &[Value]| {
57
+ let key = args
58
+ .first()
59
+ .map(|v| v.to_display_string())
60
+ .unwrap_or_default();
61
+ symbol_for_impl(&key)
62
+ });
63
+ let key_for = Value::native(symbol_key_for_impl);
64
+ let mut m = ObjectMap::default();
65
+ m.insert(Arc::from("__call"), call.clone());
66
+ m.insert(Arc::from("__construct"), call);
67
+ m.insert(Arc::from("for"), for_fn);
68
+ m.insert(Arc::from("keyFor"), key_for);
69
+ Value::object(m)
70
+ }
71
+
72
+ #[cfg(test)]
73
+ mod tests {
74
+ use super::*;
75
+ use tishlang_core::value_call;
76
+
77
+ #[test]
78
+ fn symbol_global_value_call() {
79
+ let o = symbol_object();
80
+ let r = value_call(&o, &[Value::String("hi".into())]);
81
+ assert!(matches!(r, Value::Symbol(_)));
82
+ }
83
+ }
@@ -0,0 +1,17 @@
1
+ [package]
2
+ name = "tishlang_bytecode"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+ description = "Bytecode compiler for Tish (AST → bytecode)"
6
+
7
+ license-file = { workspace = true }
8
+ repository = { workspace = true }
9
+ [dependencies]
10
+ tishlang_ast = { path = "../tish_ast", version = ">=0.1" }
11
+ tishlang_core = { path = "../tish_core", version = ">=0.1" }
12
+
13
+ [dev-dependencies]
14
+ tishlang_compile = { path = "../tish_compile", version = ">=0.1" }
15
+ tishlang_parser = { path = "../tish_parser", version = ">=0.1" }
16
+ tishlang_opt = { path = "../tish_opt", version = ">=0.1" }
17
+ tishlang_vm = { path = "../tish_vm", version = ">=0.1" }
@@ -0,0 +1,96 @@
1
+ //! Bytecode chunk: instructions and constants.
2
+
3
+ use std::sync::Arc;
4
+ use tishlang_core::Value;
5
+
6
+ /// A constant in the constants table.
7
+ #[derive(Debug, Clone)]
8
+ pub enum Constant {
9
+ /// Primitive literals
10
+ Number(f64),
11
+ String(Arc<str>),
12
+ Bool(bool),
13
+ Null,
14
+ /// Nested function code (index into parent Chunk's nested chunks)
15
+ Closure(usize),
16
+ }
17
+
18
+ impl Constant {
19
+ pub fn to_value(&self) -> Value {
20
+ match self {
21
+ Constant::Number(n) => Value::Number(*n),
22
+ Constant::String(s) => Value::String(Arc::clone(s)),
23
+ Constant::Bool(b) => Value::Bool(*b),
24
+ Constant::Null => Value::Null,
25
+ Constant::Closure(_) => {
26
+ // Closures are converted to Value at runtime by the VM
27
+ unreachable!("Closure constant should be handled by VM")
28
+ }
29
+ }
30
+ }
31
+ }
32
+
33
+ /// A bytecode chunk: instructions and associated data.
34
+ #[derive(Debug, Clone)]
35
+ pub struct Chunk {
36
+ /// Raw bytecode. Instructions are variable-length.
37
+ pub code: Vec<u8>,
38
+ /// Constants (literals, nested function indices)
39
+ pub constants: Vec<Constant>,
40
+ /// Variable/property names (strings). First `param_count` are parameter names.
41
+ pub names: Vec<Arc<str>>,
42
+ /// Nested chunks (for function bodies)
43
+ pub nested: Vec<Chunk>,
44
+ /// Index into names for rest param, or NO_REST_PARAM if none.
45
+ pub rest_param_index: u16,
46
+ /// Number of leading names that are parameters (for proper closure arg binding).
47
+ pub param_count: u16,
48
+ }
49
+
50
+ impl Chunk {
51
+ pub fn new() -> Self {
52
+ Self {
53
+ code: Vec::new(),
54
+ constants: Vec::new(),
55
+ names: Vec::new(),
56
+ nested: Vec::new(),
57
+ rest_param_index: super::NO_REST_PARAM,
58
+ param_count: 0,
59
+ }
60
+ }
61
+
62
+ pub fn write_u8(&mut self, b: u8) {
63
+ self.code.push(b);
64
+ }
65
+
66
+ pub fn write_u16(&mut self, n: u16) {
67
+ self.code.extend_from_slice(&n.to_be_bytes());
68
+ }
69
+
70
+ pub fn add_constant(&mut self, c: Constant) -> u16 {
71
+ let idx = self.constants.len();
72
+ self.constants.push(c);
73
+ idx as u16
74
+ }
75
+
76
+ pub fn add_name(&mut self, name: Arc<str>) -> u16 {
77
+ if let Some(idx) = self.names.iter().position(|n| n.as_ref() == name.as_ref()) {
78
+ return idx as u16;
79
+ }
80
+ let idx = self.names.len();
81
+ self.names.push(name);
82
+ idx as u16
83
+ }
84
+
85
+ pub fn add_nested(&mut self, chunk: Chunk) -> usize {
86
+ let idx = self.nested.len();
87
+ self.nested.push(chunk);
88
+ idx
89
+ }
90
+ }
91
+
92
+ impl Default for Chunk {
93
+ fn default() -> Self {
94
+ Self::new()
95
+ }
96
+ }