@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,180 @@
|
|
|
1
|
+
//! UI runtime: `h`, `Fragment`, vnode shapes compatible with Lattish, minimal hooks, and [`Host`].
|
|
2
|
+
|
|
3
|
+
mod hooks;
|
|
4
|
+
|
|
5
|
+
use std::sync::Arc;
|
|
6
|
+
|
|
7
|
+
pub use hooks::{
|
|
8
|
+
alloc_root_id, current_root_id, drop_host_for_root, install_host_for_root,
|
|
9
|
+
install_thread_local_host, native_create_root,
|
|
10
|
+
native_use_effect, native_use_layout_effect, native_use_memo, native_use_ref,
|
|
11
|
+
native_use_state, run_with_current_root,
|
|
12
|
+
schedule_flush,
|
|
13
|
+
unregister_root, unregister_root_hooks_and_effects, with_host_for_root,
|
|
14
|
+
with_thread_local_host, HookState, RootId, LEGACY_ROOT_ID,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
use tishlang_core::{ObjectMap, Value, VmRef};
|
|
18
|
+
|
|
19
|
+
/// Sentinel string for `Fragment` (native). Full runtimes may also use `Symbol.for("tish.fragment")`
|
|
20
|
+
/// when the global `Symbol` is present; [`is_fragment_tag`] accepts both that registry symbol and
|
|
21
|
+
/// this string for compatibility.
|
|
22
|
+
pub const FRAGMENT_SENTINEL: &str = "__tish_ui_Fragment__";
|
|
23
|
+
|
|
24
|
+
/// `Fragment` marker value for `h(Fragment, null, children)`.
|
|
25
|
+
pub fn fragment_value() -> Value {
|
|
26
|
+
Value::String(FRAGMENT_SENTINEL.into())
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/// Returns true if `tag` refers to [`fragment_value`].
|
|
30
|
+
pub fn is_fragment_tag(tag: &Value) -> bool {
|
|
31
|
+
match tag {
|
|
32
|
+
Value::String(s) => s.as_ref() == FRAGMENT_SENTINEL,
|
|
33
|
+
Value::Symbol(s) => s.registry_key.as_deref() == Some("tish.fragment"),
|
|
34
|
+
_ => false,
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/// `text(s)` helper — returns string as `Value::String` for JSX text nodes.
|
|
39
|
+
pub fn ui_text(args: &[Value]) -> Value {
|
|
40
|
+
let s = args
|
|
41
|
+
.first()
|
|
42
|
+
.map(|v| v.to_display_string())
|
|
43
|
+
.unwrap_or_default();
|
|
44
|
+
Value::String(s.into())
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/// Vnode factory: `h(tag, props, children)` (Lattish-compatible shape).
|
|
48
|
+
pub fn ui_h(args: &[Value]) -> Value {
|
|
49
|
+
let tag = args.get(0).cloned().unwrap_or(Value::Null);
|
|
50
|
+
let props = args.get(1).cloned().unwrap_or(Value::Null);
|
|
51
|
+
let children_arg = args.get(2).cloned().unwrap_or(Value::Null);
|
|
52
|
+
|
|
53
|
+
let children_vec = normalize_children_list(children_arg);
|
|
54
|
+
|
|
55
|
+
if let Value::Function(f) = &tag {
|
|
56
|
+
let mut merged = if matches!(props, Value::Null) {
|
|
57
|
+
ObjectMap::default()
|
|
58
|
+
} else if let Value::Object(obj) = props {
|
|
59
|
+
obj.borrow().strings.clone()
|
|
60
|
+
} else {
|
|
61
|
+
ObjectMap::default()
|
|
62
|
+
};
|
|
63
|
+
if !children_vec.is_empty() {
|
|
64
|
+
merged.insert(
|
|
65
|
+
Arc::from("children"),
|
|
66
|
+
Value::Array(VmRef::new(children_vec.clone())),
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
return f(&[Value::object(merged)]);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if is_fragment_tag(&tag) {
|
|
73
|
+
return vnode_fragment(children_vec);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
let tag_str: Arc<str> = match tag {
|
|
77
|
+
Value::String(s) => s,
|
|
78
|
+
_ => return Value::Null,
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
vnode_element(tag_str, props, children_vec)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
fn normalize_children_list(children_arg: Value) -> Vec<Value> {
|
|
85
|
+
match children_arg {
|
|
86
|
+
Value::Null => vec![],
|
|
87
|
+
Value::Array(a) => flatten_vnode_children(&a.borrow()),
|
|
88
|
+
other => vec![other],
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/// JSX often passes `{items.map(...)}` as one slot in the children array. Treat nested `Value::Array`
|
|
93
|
+
/// like React: splice them into the parent list so hosts never see a raw array vnode.
|
|
94
|
+
fn flatten_vnode_children(items: &[Value]) -> Vec<Value> {
|
|
95
|
+
let mut out = Vec::new();
|
|
96
|
+
for c in items {
|
|
97
|
+
match c {
|
|
98
|
+
Value::Array(inner) => out.extend(flatten_vnode_children(&inner.borrow())),
|
|
99
|
+
Value::Null => {}
|
|
100
|
+
_ => out.push(c.clone()),
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
out
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
fn vnode_element(tag: Arc<str>, props: Value, children: Vec<Value>) -> Value {
|
|
107
|
+
let mut m = ObjectMap::default();
|
|
108
|
+
m.insert(Arc::from("tag"), Value::String(tag));
|
|
109
|
+
m.insert(
|
|
110
|
+
Arc::from("props"),
|
|
111
|
+
if matches!(props, Value::Null) {
|
|
112
|
+
Value::Null
|
|
113
|
+
} else {
|
|
114
|
+
props
|
|
115
|
+
},
|
|
116
|
+
);
|
|
117
|
+
m.insert(Arc::from("children"), Value::Array(VmRef::new(children)));
|
|
118
|
+
m.insert(Arc::from("_el"), Value::Null);
|
|
119
|
+
Value::object(m)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
fn vnode_fragment(children: Vec<Value>) -> Value {
|
|
123
|
+
let mut m = ObjectMap::default();
|
|
124
|
+
m.insert(Arc::from("tag"), fragment_value());
|
|
125
|
+
m.insert(Arc::from("props"), Value::Null);
|
|
126
|
+
m.insert(Arc::from("children"), Value::Array(VmRef::new(children)));
|
|
127
|
+
m.insert(Arc::from("_el"), Value::Null);
|
|
128
|
+
Value::object(m)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/// Pluggable UI backend (Floem, DOM, SwiftUI, …). Main-thread / single-threaded by default.
|
|
132
|
+
pub trait Host {
|
|
133
|
+
/// Apply a new root vnode (after each render flush).
|
|
134
|
+
fn commit_root(&mut self, vnode: &Value);
|
|
135
|
+
/// Content area width changed (e.g. window resize); default no-op.
|
|
136
|
+
fn content_width_changed(&mut self, _width: f64) {}
|
|
137
|
+
/// Called once from the main queue shortly after the window is ordered on-screen. Split /
|
|
138
|
+
/// sidebar hosts can use this to re-layout when pane bounds were still provisional during the
|
|
139
|
+
/// first commit.
|
|
140
|
+
fn after_window_shown(&mut self) {}
|
|
141
|
+
/// Clear native control target/action (and similar) before the host is dropped — e.g. window close.
|
|
142
|
+
fn detach_native_actions(&mut self) {}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/// No-op / test host that only stores the last committed tree.
|
|
146
|
+
pub struct HeadlessHost {
|
|
147
|
+
pub last: Option<Value>,
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
impl Default for HeadlessHost {
|
|
151
|
+
fn default() -> Self {
|
|
152
|
+
Self { last: None }
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
impl Host for HeadlessHost {
|
|
157
|
+
fn commit_root(&mut self, vnode: &Value) {
|
|
158
|
+
self.last = Some(vnode.clone());
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/// Tag registry hook for future host-specific intrinsic mapping (HTML tag → component kind).
|
|
163
|
+
#[derive(Default)]
|
|
164
|
+
pub struct TagRegistry;
|
|
165
|
+
|
|
166
|
+
impl TagRegistry {
|
|
167
|
+
pub fn new() -> Self {
|
|
168
|
+
Self
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/// Placeholder for subset CSS / style object interpretation.
|
|
173
|
+
#[derive(Default)]
|
|
174
|
+
pub struct StyleInterpreter;
|
|
175
|
+
|
|
176
|
+
impl StyleInterpreter {
|
|
177
|
+
pub fn new() -> Self {
|
|
178
|
+
Self
|
|
179
|
+
}
|
|
180
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "tishlang_vm"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
edition = "2021"
|
|
5
|
+
description = "Bytecode VM for Tish"
|
|
6
|
+
|
|
7
|
+
license-file = { workspace = true }
|
|
8
|
+
repository = { workspace = true }
|
|
9
|
+
[features]
|
|
10
|
+
default = []
|
|
11
|
+
regex = ["tishlang_core/regex"]
|
|
12
|
+
# Propagate `send-values` so that every native-function closure we build
|
|
13
|
+
# in the VM (array / string / object methods) picks up the right
|
|
14
|
+
# `Rc<dyn Fn>` vs `Arc<dyn Fn + Send + Sync>` wrapper at compile time.
|
|
15
|
+
send-values = ["tishlang_core/send-values", "tishlang_builtins/send-values"]
|
|
16
|
+
# For wasm32 target: use web_sys console for output
|
|
17
|
+
wasm = ["dep:wasm-bindgen"]
|
|
18
|
+
# Built-in modules: fs, http, process (for bytecode LoadNativeExport).
|
|
19
|
+
# `dep:tishlang_runtime` is required so enabling e.g. `http` always activates the optional runtime crate
|
|
20
|
+
# (some Cargo/cache combinations only saw `tishlang_runtime/http` and built VM stubs without http).
|
|
21
|
+
fs = ["dep:tishlang_runtime", "tishlang_runtime/fs"]
|
|
22
|
+
process = ["dep:tishlang_runtime", "tishlang_runtime/process"]
|
|
23
|
+
# Timer globals + `tish:timers` LoadNativeExport (uses tishlang_runtime TLS timer registry).
|
|
24
|
+
timers = ["dep:tishlang_runtime"]
|
|
25
|
+
# Any HTTP build needs Send-safe values so handlers can be dispatched
|
|
26
|
+
# across worker threads or processes. HTTP implies timers (fetch/Promise often pair with setTimeout).
|
|
27
|
+
http = ["dep:tishlang_runtime", "tishlang_runtime/http", "send-values", "timers"]
|
|
28
|
+
# Promise + `tish:http.await` / `Promise` export without the full HTTP client stack (e.g. wasm32-wasip1).
|
|
29
|
+
promise = ["dep:tishlang_runtime", "tishlang_runtime/promise", "send-values"]
|
|
30
|
+
ws = ["dep:tishlang_runtime", "tishlang_runtime/ws"]
|
|
31
|
+
|
|
32
|
+
[dependencies]
|
|
33
|
+
tishlang_ast = { path = "../tish_ast", version = ">=0.1" }
|
|
34
|
+
tishlang_builtins = { path = "../tish_builtins", version = ">=0.1" }
|
|
35
|
+
tishlang_bytecode = { path = "../tish_bytecode", version = ">=0.1" }
|
|
36
|
+
tishlang_core = { path = "../tish_core", version = ">=0.1" }
|
|
37
|
+
tishlang_runtime = { path = "../tish_runtime", version = ">=0.1", optional = true }
|
|
38
|
+
rand = "0.10"
|
|
39
|
+
wasm-bindgen = { version = "0.2", optional = true }
|
|
40
|
+
|
|
41
|
+
[dev-dependencies]
|
|
42
|
+
tishlang_compile = { path = "../tish_compile", version = ">=0.1" }
|
|
43
|
+
tishlang_parser = { path = "../tish_parser", version = ">=0.1" }
|
|
44
|
+
tishlang_opt = { path = "../tish_opt", version = ">=0.1" }
|
|
45
|
+
|
|
46
|
+
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
|
47
|
+
getrandom = { version = "0.4", features = ["wasm_js"] }
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//! Bytecode VM for Tish execution.
|
|
2
|
+
|
|
3
|
+
mod vm;
|
|
4
|
+
|
|
5
|
+
pub use vm::{all_compiled_capabilities, run, run_with_options, Vm, VmRunOptions};
|
|
6
|
+
|
|
7
|
+
#[cfg(test)]
|
|
8
|
+
mod tests {
|
|
9
|
+
use super::*;
|
|
10
|
+
|
|
11
|
+
#[test]
|
|
12
|
+
fn bytecode_for_of_break_continue_switch_try() {
|
|
13
|
+
let src = r#"
|
|
14
|
+
let sum = 0;
|
|
15
|
+
for (let x of [1, 2, 3]) { sum = sum + x; }
|
|
16
|
+
console.log(sum);
|
|
17
|
+
let n = 0;
|
|
18
|
+
do { n = n + 1; } while (n < 3);
|
|
19
|
+
console.log(n);
|
|
20
|
+
const k = 2;
|
|
21
|
+
switch (k) {
|
|
22
|
+
case 1: console.log(1); break;
|
|
23
|
+
case 2: console.log(2); break;
|
|
24
|
+
default: console.log(0);
|
|
25
|
+
}
|
|
26
|
+
try { throw "ok"; } catch (e) { console.log(e); }
|
|
27
|
+
let x = 10;
|
|
28
|
+
x++;
|
|
29
|
+
++x;
|
|
30
|
+
x += 3;
|
|
31
|
+
console.log(x);
|
|
32
|
+
fn f(a, b, ...rest) { return rest.length; }
|
|
33
|
+
console.log(f(1,2,3,4));
|
|
34
|
+
"#;
|
|
35
|
+
let program = tishlang_parser::parse(src).expect("parse");
|
|
36
|
+
let chunk = tishlang_bytecode::compile(&program).expect("compile");
|
|
37
|
+
let _ = run(&chunk).expect("run");
|
|
38
|
+
}
|
|
39
|
+
}
|