@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.
- package/Cargo.toml +49 -0
- package/LICENSE +13 -0
- package/README.md +138 -0
- package/bin/tish-format +0 -0
- package/crates/js_to_tish/Cargo.toml +11 -0
- package/crates/js_to_tish/README.md +18 -0
- package/crates/js_to_tish/src/error.rs +55 -0
- package/crates/js_to_tish/src/lib.rs +11 -0
- package/crates/js_to_tish/src/span_util.rs +35 -0
- package/crates/js_to_tish/src/transform/expr.rs +610 -0
- package/crates/js_to_tish/src/transform/stmt.rs +503 -0
- package/crates/js_to_tish/src/transform.rs +60 -0
- package/crates/tish/Cargo.toml +54 -0
- package/crates/tish/src/cargo_native_registry.rs +32 -0
- package/crates/tish/src/cli_help.rs +565 -0
- package/crates/tish/src/main.rs +781 -0
- package/crates/tish/src/repl_completion.rs +200 -0
- package/crates/tish/tests/cargo_example_compile.rs +67 -0
- package/crates/tish/tests/fixtures/cargo_example_project/Cargo.toml +3 -0
- package/crates/tish/tests/fixtures/cargo_example_project/crates/demo-shim/Cargo.toml +11 -0
- package/crates/tish/tests/fixtures/cargo_example_project/crates/demo-shim/src/lib.rs +12 -0
- package/crates/tish/tests/fixtures/cargo_example_project/package.json +10 -0
- package/crates/tish/tests/fixtures/cargo_example_project/src/main.tish +3 -0
- package/crates/tish/tests/integration_test.rs +1095 -0
- package/crates/tish/tests/run_optimize_stdout_parity.rs +50 -0
- package/crates/tish/tests/shortcircuit.rs +65 -0
- package/crates/tish_ast/Cargo.toml +9 -0
- package/crates/tish_ast/src/ast.rs +620 -0
- package/crates/tish_ast/src/lib.rs +5 -0
- package/crates/tish_build_utils/Cargo.toml +11 -0
- package/crates/tish_build_utils/src/lib.rs +577 -0
- package/crates/tish_builtins/Cargo.toml +20 -0
- package/crates/tish_builtins/src/array.rs +441 -0
- package/crates/tish_builtins/src/construct.rs +159 -0
- package/crates/tish_builtins/src/globals.rs +213 -0
- package/crates/tish_builtins/src/helpers.rs +35 -0
- package/crates/tish_builtins/src/lib.rs +16 -0
- package/crates/tish_builtins/src/math.rs +89 -0
- package/crates/tish_builtins/src/object.rs +36 -0
- package/crates/tish_builtins/src/string.rs +647 -0
- package/crates/tish_builtins/src/symbol.rs +83 -0
- package/crates/tish_bytecode/Cargo.toml +17 -0
- package/crates/tish_bytecode/src/chunk.rs +96 -0
- package/crates/tish_bytecode/src/compiler.rs +1760 -0
- package/crates/tish_bytecode/src/encoding.rs +100 -0
- package/crates/tish_bytecode/src/lib.rs +19 -0
- package/crates/tish_bytecode/src/opcode.rs +142 -0
- package/crates/tish_bytecode/src/peephole.rs +189 -0
- package/crates/tish_bytecode/src/serialize.rs +163 -0
- package/crates/tish_bytecode/tests/break_continue_bytecode.rs +44 -0
- package/crates/tish_bytecode/tests/constant_folding.rs +84 -0
- package/crates/tish_bytecode/tests/sort_optimization.rs +31 -0
- package/crates/tish_compile/Cargo.toml +26 -0
- package/crates/tish_compile/src/codegen.rs +5332 -0
- package/crates/tish_compile/src/infer.rs +292 -0
- package/crates/tish_compile/src/lib.rs +164 -0
- package/crates/tish_compile/src/resolve.rs +1388 -0
- package/crates/tish_compile/src/types.rs +501 -0
- package/crates/tish_compile_js/Cargo.toml +18 -0
- package/crates/tish_compile_js/examples/jsx_vdom_smoke.tish +8 -0
- package/crates/tish_compile_js/src/codegen.rs +871 -0
- package/crates/tish_compile_js/src/error.rs +20 -0
- package/crates/tish_compile_js/src/lib.rs +26 -0
- package/crates/tish_compile_js/src/tests_jsx.rs +350 -0
- package/crates/tish_compiler_wasm/Cargo.toml +21 -0
- package/crates/tish_compiler_wasm/src/lib.rs +57 -0
- package/crates/tish_compiler_wasm/src/resolve_virtual.rs +473 -0
- package/crates/tish_core/Cargo.toml +26 -0
- package/crates/tish_core/src/console_style.rs +160 -0
- package/crates/tish_core/src/json.rs +387 -0
- package/crates/tish_core/src/lib.rs +17 -0
- package/crates/tish_core/src/macros.rs +36 -0
- package/crates/tish_core/src/uri.rs +118 -0
- package/crates/tish_core/src/value.rs +696 -0
- package/crates/tish_core/src/vmref.rs +178 -0
- package/crates/tish_cranelift/Cargo.toml +19 -0
- package/crates/tish_cranelift/src/lib.rs +43 -0
- package/crates/tish_cranelift/src/link.rs +117 -0
- package/crates/tish_cranelift/src/lower.rs +85 -0
- package/crates/tish_cranelift_runtime/Cargo.toml +25 -0
- package/crates/tish_cranelift_runtime/src/lib.rs +45 -0
- package/crates/tish_eval/Cargo.toml +45 -0
- package/crates/tish_eval/src/eval.rs +3717 -0
- package/crates/tish_eval/src/http.rs +188 -0
- package/crates/tish_eval/src/lib.rs +99 -0
- package/crates/tish_eval/src/natives.rs +399 -0
- package/crates/tish_eval/src/promise.rs +179 -0
- package/crates/tish_eval/src/regex.rs +299 -0
- package/crates/tish_eval/src/timers.rs +120 -0
- package/crates/tish_eval/src/value.rs +318 -0
- package/crates/tish_eval/src/value_convert.rs +111 -0
- package/crates/tish_fmt/Cargo.toml +16 -0
- package/crates/tish_fmt/src/bin/tish-fmt.rs +41 -0
- package/crates/tish_fmt/src/lib.rs +2101 -0
- package/crates/tish_jsx_web/Cargo.toml +9 -0
- package/crates/tish_jsx_web/README.md +5 -0
- package/crates/tish_jsx_web/src/lib.rs +2 -0
- package/crates/tish_lexer/Cargo.toml +9 -0
- package/crates/tish_lexer/src/lib.rs +716 -0
- package/crates/tish_lexer/src/token.rs +163 -0
- package/crates/tish_lint/Cargo.toml +18 -0
- package/crates/tish_lint/src/bin/tish-lint.rs +195 -0
- package/crates/tish_lint/src/lib.rs +289 -0
- package/crates/tish_llvm/Cargo.toml +13 -0
- package/crates/tish_llvm/src/lib.rs +115 -0
- package/crates/tish_lsp/Cargo.toml +25 -0
- package/crates/tish_lsp/README.md +26 -0
- package/crates/tish_lsp/src/builtin_goto.rs +362 -0
- package/crates/tish_lsp/src/import_goto.rs +562 -0
- package/crates/tish_lsp/src/main.rs +1046 -0
- package/crates/tish_native/Cargo.toml +16 -0
- package/crates/tish_native/src/build.rs +427 -0
- package/crates/tish_native/src/config.rs +48 -0
- package/crates/tish_native/src/lib.rs +416 -0
- package/crates/tish_opt/Cargo.toml +13 -0
- package/crates/tish_opt/src/lib.rs +943 -0
- package/crates/tish_parser/Cargo.toml +11 -0
- package/crates/tish_parser/src/lib.rs +332 -0
- package/crates/tish_parser/src/parser.rs +2304 -0
- package/crates/tish_pg/Cargo.toml +34 -0
- package/crates/tish_pg/README.md +38 -0
- package/crates/tish_pg/src/error.rs +52 -0
- package/crates/tish_pg/src/lib.rs +955 -0
- package/crates/tish_resolve/Cargo.toml +13 -0
- package/crates/tish_resolve/src/lib.rs +3561 -0
- package/crates/tish_resolve/src/pos.rs +141 -0
- package/crates/tish_runtime/Cargo.toml +96 -0
- package/crates/tish_runtime/src/http.rs +1298 -0
- package/crates/tish_runtime/src/http_fetch.rs +471 -0
- package/crates/tish_runtime/src/http_hyper.rs +418 -0
- package/crates/tish_runtime/src/http_prefork.rs +189 -0
- package/crates/tish_runtime/src/lib.rs +1192 -0
- package/crates/tish_runtime/src/native_promise.rs +15 -0
- package/crates/tish_runtime/src/promise.rs +248 -0
- package/crates/tish_runtime/src/promise_io.rs +38 -0
- package/crates/tish_runtime/src/timers.rs +166 -0
- package/crates/tish_runtime/src/ws.rs +761 -0
- package/crates/tish_runtime/tests/fetch_readable_stream.rs +102 -0
- package/crates/tish_ui/Cargo.toml +17 -0
- package/crates/tish_ui/src/jsx.rs +682 -0
- package/crates/tish_ui/src/lib.rs +20 -0
- package/crates/tish_ui/src/runtime/hooks.rs +569 -0
- package/crates/tish_ui/src/runtime/mod.rs +180 -0
- package/crates/tish_vm/Cargo.toml +47 -0
- package/crates/tish_vm/src/lib.rs +39 -0
- package/crates/tish_vm/src/vm.rs +2192 -0
- package/crates/tish_vm/tests/fixtures/or_string_cmd.tish +2 -0
- package/crates/tish_vm/tests/lexical_scope_declare.rs +34 -0
- package/crates/tish_vm/tests/peephole_jump_chain_logical_or.rs +150 -0
- package/crates/tish_wasm/Cargo.toml +15 -0
- package/crates/tish_wasm/src/lib.rs +424 -0
- package/crates/tish_wasm_runtime/Cargo.toml +37 -0
- package/crates/tish_wasm_runtime/src/gpu.rs +413 -0
- package/crates/tish_wasm_runtime/src/lib.rs +42 -0
- package/crates/tishlang_cargo_bindgen/Cargo.toml +26 -0
- package/crates/tishlang_cargo_bindgen/src/classify.rs +263 -0
- package/crates/tishlang_cargo_bindgen/src/discover.rs +125 -0
- package/crates/tishlang_cargo_bindgen/src/infer.rs +382 -0
- package/crates/tishlang_cargo_bindgen/src/lib.rs +349 -0
- package/crates/tishlang_cargo_bindgen/src/main.rs +167 -0
- package/crates/tishlang_cargo_bindgen/src/metadata.rs +117 -0
- package/justfile +268 -0
- package/package.json +1 -1
- package/platform/darwin-arm64/tish-fmt +0 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
//! Verify AST optimization (constant folding) yields expected bytecode.
|
|
2
|
+
//! Uses tishlang_opt::optimize before compile to match the pipeline used by run/compile.
|
|
3
|
+
|
|
4
|
+
use tishlang_bytecode::{compile, Chunk, Opcode};
|
|
5
|
+
use tishlang_parser::parse;
|
|
6
|
+
|
|
7
|
+
fn chunk_contains_opcode(chunk: &Chunk, op: u8) -> bool {
|
|
8
|
+
if chunk.code.contains(&op) {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
for nested in &chunk.nested {
|
|
12
|
+
if chunk_contains_opcode(nested, op) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
false
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/// 1 + 2 should fold to constant 3; no BinOp in bytecode.
|
|
20
|
+
#[test]
|
|
21
|
+
fn constant_fold_binary_no_binop() {
|
|
22
|
+
let source = "1 + 2";
|
|
23
|
+
let program = parse(source).expect("parse");
|
|
24
|
+
let optimized = tishlang_opt::optimize(&program);
|
|
25
|
+
let chunk = compile(&optimized).expect("compile");
|
|
26
|
+
assert!(
|
|
27
|
+
!chunk_contains_opcode(&chunk, Opcode::BinOp as u8),
|
|
28
|
+
"Expected no BinOp for 1+2 after constant folding"
|
|
29
|
+
);
|
|
30
|
+
assert!(
|
|
31
|
+
chunk.constants.iter().any(|c| matches!(c, tishlang_bytecode::Constant::Number(n) if (*n - 3.0).abs() < f64::EPSILON)),
|
|
32
|
+
"Expected constant 3 in chunk"
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/// Peephole: Dup+Pop should be removed (replaced with Nop Nop).
|
|
37
|
+
/// Compile a program that may emit Dup+Pop; verify it runs and chunk has no consecutive Dup,Pop.
|
|
38
|
+
fn chunk_has_dup_pop_sequence(code: &[u8]) -> bool {
|
|
39
|
+
let dup = Opcode::Dup as u8;
|
|
40
|
+
let pop = Opcode::Pop as u8;
|
|
41
|
+
for i in 0..code.len().saturating_sub(1) {
|
|
42
|
+
if code[i] == dup && code[i + 1] == pop {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
false
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
fn chunk_contains_dup_pop(chunk: &Chunk) -> bool {
|
|
50
|
+
if chunk_has_dup_pop_sequence(&chunk.code) {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
for nested in &chunk.nested {
|
|
54
|
+
if chunk_contains_dup_pop(nested) {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
false
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
#[test]
|
|
62
|
+
fn peephole_remove_dup_pop() {
|
|
63
|
+
let source = "let o = {a:1}; o?.a";
|
|
64
|
+
let program = parse(source).expect("parse");
|
|
65
|
+
let optimized = tishlang_opt::optimize(&program);
|
|
66
|
+
let chunk = compile(&optimized).expect("compile");
|
|
67
|
+
assert!(
|
|
68
|
+
!chunk_contains_dup_pop(&chunk),
|
|
69
|
+
"Peephole should remove Dup+Pop sequences"
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/// -42 should fold to constant -42; no UnaryOp in bytecode.
|
|
74
|
+
#[test]
|
|
75
|
+
fn constant_fold_unary_no_unaryop() {
|
|
76
|
+
let source = "-42";
|
|
77
|
+
let program = parse(source).expect("parse");
|
|
78
|
+
let optimized = tishlang_opt::optimize(&program);
|
|
79
|
+
let chunk = compile(&optimized).expect("compile");
|
|
80
|
+
assert!(
|
|
81
|
+
!chunk_contains_opcode(&chunk, Opcode::UnaryOp as u8),
|
|
82
|
+
"Expected no UnaryOp for -42 after constant folding"
|
|
83
|
+
);
|
|
84
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//! Verify arr.sort((a,b)=>a-b) compiles to ArraySortNumeric (opcode 31).
|
|
2
|
+
|
|
3
|
+
use tishlang_bytecode::{compile, Opcode};
|
|
4
|
+
use tishlang_parser::parse;
|
|
5
|
+
|
|
6
|
+
fn chunk_contains_opcode(chunk: &tishlang_bytecode::Chunk, op: u8) -> bool {
|
|
7
|
+
if chunk.code.contains(&op) {
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
for nested in &chunk.nested {
|
|
11
|
+
if chunk_contains_opcode(nested, op) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
false
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
#[test]
|
|
19
|
+
fn test_numeric_sort_uses_array_sort_numeric() {
|
|
20
|
+
let source = r#"
|
|
21
|
+
let x = [3, 1, 2];
|
|
22
|
+
x.sort((a, b) => a - b);
|
|
23
|
+
console.log(x);
|
|
24
|
+
"#;
|
|
25
|
+
let program = parse(source).expect("parse");
|
|
26
|
+
let chunk = compile(&program).expect("compile");
|
|
27
|
+
assert!(
|
|
28
|
+
chunk_contains_opcode(&chunk, Opcode::ArraySortNumeric as u8),
|
|
29
|
+
"Expected ArraySortNumeric (31) in bytecode for x.sort((a,b)=>a-b)"
|
|
30
|
+
);
|
|
31
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "tishlang_compile"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
edition = "2021"
|
|
5
|
+
description = "Tish native compiler backend"
|
|
6
|
+
|
|
7
|
+
license-file = { workspace = true }
|
|
8
|
+
repository = { workspace = true }
|
|
9
|
+
[features]
|
|
10
|
+
default = []
|
|
11
|
+
http = []
|
|
12
|
+
timers = []
|
|
13
|
+
fs = []
|
|
14
|
+
process = []
|
|
15
|
+
regex = []
|
|
16
|
+
ws = []
|
|
17
|
+
|
|
18
|
+
[dependencies]
|
|
19
|
+
tishlang_ast = { path = "../tish_ast", version = ">=0.1" }
|
|
20
|
+
tishlang_opt = { path = "../tish_opt", version = ">=0.1" }
|
|
21
|
+
tishlang_parser = { path = "../tish_parser", version = ">=0.1" }
|
|
22
|
+
tishlang_ui = { path = "../tish_ui", version = ">=0.1", default-features = false, features = ["compiler"] }
|
|
23
|
+
serde_json = "1.0"
|
|
24
|
+
|
|
25
|
+
[dev-dependencies]
|
|
26
|
+
tempfile = "3"
|