@tishlang/tish 1.13.2 → 2.0.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 +2 -0
- package/bin/tish +0 -0
- package/crates/js_to_tish/src/transform/expr.rs +1 -0
- package/crates/tish/Cargo.toml +11 -3
- package/crates/tish/build.rs +21 -0
- package/crates/tish/src/cli_help.rs +15 -4
- package/crates/tish/src/main.rs +93 -21
- package/crates/tish/src/repl_completion.rs +0 -1
- package/crates/tish/tests/error_source_location.rs +36 -0
- package/crates/tish/tests/fixtures/runtime_error_location.tish +5 -0
- package/crates/tish/tests/fixtures/trycatch_runtime_errors.tish +15 -0
- package/crates/tish/tests/fixtures/tty_capability.tish +9 -0
- package/crates/tish/tests/integration_test.rs +402 -91
- package/crates/tish/tests/trycatch_runtime_errors.rs +45 -0
- package/crates/tish/tests/tty_capability.rs +43 -0
- package/crates/tish_ast/src/ast.rs +37 -8
- package/crates/tish_builtins/Cargo.toml +2 -0
- package/crates/tish_builtins/src/array.rs +375 -13
- package/crates/tish_builtins/src/collections.rs +481 -0
- package/crates/tish_builtins/src/construct.rs +59 -19
- package/crates/tish_builtins/src/date.rs +538 -0
- package/crates/tish_builtins/src/globals.rs +86 -6
- package/crates/tish_builtins/src/iterator.rs +129 -0
- package/crates/tish_builtins/src/lib.rs +5 -0
- package/crates/tish_builtins/src/number.rs +96 -0
- package/crates/tish_builtins/src/object.rs +2 -2
- package/crates/tish_builtins/src/string.rs +19 -20
- package/crates/tish_builtins/src/symbol.rs +1 -1
- package/crates/tish_builtins/src/typedarrays.rs +298 -0
- package/crates/tish_bytecode/src/chunk.rs +69 -1
- package/crates/tish_bytecode/src/compiler.rs +933 -89
- package/crates/tish_bytecode/src/encoding.rs +2 -0
- package/crates/tish_bytecode/src/lib.rs +2 -1
- package/crates/tish_bytecode/src/opcode.rs +47 -4
- package/crates/tish_bytecode/src/serialize.rs +31 -1
- package/crates/tish_compile/Cargo.toml +1 -0
- package/crates/tish_compile/src/check.rs +774 -0
- package/crates/tish_compile/src/codegen.rs +2334 -349
- package/crates/tish_compile/src/infer.rs +1395 -6
- package/crates/tish_compile/src/lib.rs +50 -8
- package/crates/tish_compile/src/resolve.rs +584 -21
- package/crates/tish_compile/src/types.rs +106 -2
- package/crates/tish_compile_js/src/codegen.rs +67 -0
- package/crates/tish_compile_js/src/tests_jsx.rs +64 -0
- package/crates/tish_core/Cargo.toml +7 -1
- package/crates/tish_core/src/console_style.rs +11 -1
- package/crates/tish_core/src/json.rs +81 -38
- package/crates/tish_core/src/lib.rs +3 -0
- package/crates/tish_core/src/shape.rs +85 -0
- package/crates/tish_core/src/value.rs +679 -25
- package/crates/tish_core/src/vmref.rs +13 -8
- package/crates/tish_cranelift/src/link.rs +17 -4
- package/crates/tish_cranelift_runtime/Cargo.toml +1 -0
- package/crates/tish_eval/Cargo.toml +6 -0
- package/crates/tish_eval/src/eval.rs +665 -117
- package/crates/tish_eval/src/http.rs +4 -1
- package/crates/tish_eval/src/natives.rs +165 -13
- package/crates/tish_eval/src/value.rs +31 -13
- package/crates/tish_eval/src/value_convert.rs +10 -4
- package/crates/tish_ffi/Cargo.toml +26 -0
- package/crates/tish_ffi/src/lib.rs +518 -0
- package/crates/tish_ffi/tests/fixtures/testmod/Cargo.toml +18 -0
- package/crates/tish_ffi/tests/fixtures/testmod/src/lib.rs +46 -0
- package/crates/tish_ffi/tests/loader.rs +65 -0
- package/crates/tish_fmt/src/lib.rs +43 -5
- package/crates/tish_lexer/src/lib.rs +397 -9
- package/crates/tish_lexer/src/token.rs +7 -0
- package/crates/tish_lint/src/lib.rs +2 -10
- package/crates/tish_lsp/src/import_goto.rs +2 -0
- package/crates/tish_lsp/src/main.rs +439 -26
- package/crates/tish_native/src/build.rs +55 -1
- package/crates/tish_opt/src/lib.rs +126 -23
- package/crates/tish_parser/src/lib.rs +55 -1
- package/crates/tish_parser/src/parser.rs +456 -34
- package/crates/tish_pg/src/lib.rs +3 -3
- package/crates/tish_resolve/src/lib.rs +99 -59
- package/crates/tish_runtime/Cargo.toml +4 -0
- package/crates/tish_runtime/src/http.rs +66 -17
- package/crates/tish_runtime/src/http_fetch.rs +29 -8
- package/crates/tish_runtime/src/http_hyper.rs +25 -2
- package/crates/tish_runtime/src/lib.rs +299 -44
- package/crates/tish_runtime/src/promise.rs +328 -18
- package/crates/tish_runtime/src/timers.rs +13 -7
- package/crates/tish_runtime/src/tty.rs +226 -0
- package/crates/tish_runtime/src/ws.rs +35 -18
- package/crates/tish_runtime/tests/fetch_readable_stream.rs +2 -2
- package/crates/tish_ui/src/jsx.rs +10 -0
- package/crates/tish_ui/src/runtime/hooks.rs +19 -15
- package/crates/tish_ui/src/runtime/mod.rs +15 -12
- package/crates/tish_vm/Cargo.toml +14 -1
- package/crates/tish_vm/src/jit.rs +1050 -0
- package/crates/tish_vm/src/lib.rs +2 -0
- package/crates/tish_vm/src/vm.rs +1546 -202
- package/crates/tish_vm/tests/concurrent_shared_state.rs +140 -0
- package/crates/tish_wasm/src/lib.rs +6 -2
- package/crates/tish_wasm_runtime/src/gpu.rs +17 -1
- package/crates/tishlang_cargo_bindgen/src/classify.rs +1 -3
- package/crates/tishlang_cargo_bindgen/src/lib.rs +2 -2
- package/crates/tishlang_cargo_bindgen/src/metadata.rs +1 -1
- package/justfile +8 -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
|
@@ -2,11 +2,14 @@
|
|
|
2
2
|
//!
|
|
3
3
|
//! Emits Rust source that links to tishlang_runtime.
|
|
4
4
|
|
|
5
|
+
mod check;
|
|
5
6
|
mod codegen;
|
|
6
7
|
mod infer;
|
|
7
8
|
mod resolve;
|
|
8
9
|
mod types;
|
|
9
10
|
|
|
11
|
+
pub use check::{check_program, TypeDiagnostic};
|
|
12
|
+
|
|
10
13
|
/// How generated Rust is linked (desktop binary vs embedded iOS staticlib).
|
|
11
14
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
|
12
15
|
pub enum NativeEmitMode {
|
|
@@ -26,7 +29,8 @@ pub use resolve::{
|
|
|
26
29
|
cargo_export_fn_name, compute_native_build_artifacts, detect_cycles, ensure_tish_canvas_module,
|
|
27
30
|
export_name_to_rust_ident, extract_native_import_features, format_rust_dependencies_toml,
|
|
28
31
|
generate_native_wrapper_rs, has_external_native_imports, has_native_imports,
|
|
29
|
-
infer_native_module_exports, is_builtin_native_spec, is_cargo_native_spec,
|
|
32
|
+
ffi_native_specs, infer_native_module_exports, is_builtin_native_spec, is_cargo_native_spec,
|
|
33
|
+
is_ffi_native_spec, is_native_import,
|
|
30
34
|
merge_modules, normalize_builtin_spec, program_uses_document, read_project_tish_config,
|
|
31
35
|
resolve_bare_spec, resolve_native_modules, resolve_project, resolve_project_from_stdin,
|
|
32
36
|
MergedProgram, NativeBuildArtifacts, NativeModuleInit, ResolvedNativeModule,
|
|
@@ -40,9 +44,9 @@ mod tests {
|
|
|
40
44
|
|
|
41
45
|
#[test]
|
|
42
46
|
fn typed_assign_conversion() {
|
|
43
|
-
//
|
|
44
|
-
//
|
|
45
|
-
//
|
|
47
|
+
// Typed rest-param `...args: number[]` lowers to a native `Vec<f64>` (M3), so the ForOf
|
|
48
|
+
// element `n` is `f64`, `total = total + n` stays native, and `total` is NOT demoted — the
|
|
49
|
+
// whole reduction compiles to native f64 with the return wrapping `total` back to `Value`.
|
|
46
50
|
let src = r#"
|
|
47
51
|
fn sum(...args: number[]): number {
|
|
48
52
|
let total: number = 0
|
|
@@ -52,12 +56,33 @@ fn sum(...args: number[]): number {
|
|
|
52
56
|
"#;
|
|
53
57
|
let program = parse(src).unwrap();
|
|
54
58
|
let rust = compile(&program).unwrap();
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
59
|
+
assert!(
|
|
60
|
+
rust.contains("let mut total: f64"),
|
|
61
|
+
"typed rest-param `Vec<f64>` keeps `total` native f64 (no demotion)"
|
|
62
|
+
);
|
|
63
|
+
assert!(
|
|
64
|
+
rust.contains("Value::Number(total)"),
|
|
65
|
+
"f64 total is wrapped back to Value at the return boundary"
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
// When every reassignment is provably numeric, the `number` local stays native `f64` and
|
|
69
|
+
// is wrapped back to `Value` only at the return boundary.
|
|
70
|
+
let src_native = r#"
|
|
71
|
+
fn count(): number {
|
|
72
|
+
let total: number = 0
|
|
73
|
+
for (let i: number = 0; i < 10; i = i + 1) { total = total + i }
|
|
74
|
+
return total
|
|
75
|
+
}
|
|
76
|
+
"#;
|
|
77
|
+
let program = parse(src_native).unwrap();
|
|
78
|
+
let rust = compile(&program).unwrap();
|
|
79
|
+
assert!(
|
|
80
|
+
rust.contains("let mut total: f64"),
|
|
81
|
+
"numeric-only reassignment keeps `total` native f64"
|
|
82
|
+
);
|
|
58
83
|
assert!(
|
|
59
84
|
rust.contains("Value::Number(total)"),
|
|
60
|
-
"
|
|
85
|
+
"f64 total is wrapped back to Value at the return boundary"
|
|
61
86
|
);
|
|
62
87
|
}
|
|
63
88
|
|
|
@@ -162,3 +187,20 @@ fn factory() {
|
|
|
162
187
|
);
|
|
163
188
|
}
|
|
164
189
|
}
|
|
190
|
+
|
|
191
|
+
#[cfg(test)]
|
|
192
|
+
mod monomorphization_tests {
|
|
193
|
+
use super::*;
|
|
194
|
+
use tishlang_parser::parse;
|
|
195
|
+
|
|
196
|
+
/// `Box<number>` monomorphizes to a synthetic concrete alias whose field is a native `f64`,
|
|
197
|
+
/// not a boxed `Value` — generic structs participate in native lowering.
|
|
198
|
+
#[test]
|
|
199
|
+
fn generic_struct_is_native() {
|
|
200
|
+
let src = "type Box<T> = { value: T }\nlet b: Box<number> = { value: 42 }\nconsole.log(b.value + 1)";
|
|
201
|
+
let rust = compile(&parse(src).unwrap()).unwrap();
|
|
202
|
+
// Box<number> must monomorphize to a struct with a native f64 field (not Value).
|
|
203
|
+
assert!(rust.contains("value: f64"), "expected native f64 field; got:\n{}",
|
|
204
|
+
rust.lines().filter(|l| l.contains("struct") || l.contains("value")).take(6).collect::<Vec<_>>().join("\n"));
|
|
205
|
+
}
|
|
206
|
+
}
|