@tishlang/tish 1.0.28 → 1.0.33
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 +1 -0
- package/crates/js_to_tish/src/transform/expr.rs +15 -6
- package/crates/tish/Cargo.toml +1 -1
- package/crates/tish/src/main.rs +8 -55
- package/crates/tish/tests/integration_test.rs +4 -3
- package/crates/tish_ast/src/ast.rs +65 -2
- package/crates/tish_build_utils/src/lib.rs +10 -2
- package/crates/tish_builtins/src/construct.rs +177 -0
- package/crates/tish_builtins/src/globals.rs +3 -5
- package/crates/tish_builtins/src/helpers.rs +2 -3
- package/crates/tish_builtins/src/lib.rs +1 -0
- package/crates/tish_builtins/src/object.rs +3 -4
- package/crates/tish_bytecode/src/compiler.rs +85 -11
- package/crates/tish_bytecode/src/opcode.rs +7 -3
- package/crates/tish_compile/Cargo.toml +1 -0
- package/crates/tish_compile/src/codegen.rs +233 -71
- package/crates/tish_compile/src/lib.rs +35 -0
- package/crates/tish_compile_js/Cargo.toml +1 -1
- package/crates/tish_compile_js/src/codegen.rs +43 -147
- package/crates/tish_compile_js/src/lib.rs +4 -7
- package/crates/tish_compile_js/src/tests_jsx.rs +89 -19
- package/crates/tish_compiler_wasm/src/lib.rs +2 -3
- package/crates/tish_core/Cargo.toml +4 -0
- package/crates/tish_core/src/console_style.rs +7 -1
- package/crates/tish_core/src/json.rs +1 -2
- package/crates/tish_core/src/macros.rs +2 -3
- package/crates/tish_core/src/value.rs +10 -5
- package/crates/tish_eval/Cargo.toml +2 -0
- package/crates/tish_eval/src/eval.rs +149 -72
- package/crates/tish_eval/src/http.rs +3 -4
- package/crates/tish_eval/src/regex.rs +3 -2
- package/crates/tish_eval/src/value.rs +11 -13
- package/crates/tish_eval/src/value_convert.rs +4 -8
- package/crates/tish_fmt/src/lib.rs +49 -10
- package/crates/tish_jsx_web/Cargo.toml +1 -1
- package/crates/tish_jsx_web/README.md +3 -16
- package/crates/tish_jsx_web/src/lib.rs +2 -157
- package/crates/tish_lexer/src/token.rs +2 -0
- package/crates/tish_lint/src/lib.rs +9 -0
- package/crates/tish_lsp/README.md +1 -1
- package/crates/tish_native/src/build.rs +16 -2
- package/crates/tish_opt/src/lib.rs +15 -0
- package/crates/tish_parser/src/lib.rs +101 -1
- package/crates/tish_parser/src/parser.rs +161 -50
- package/crates/tish_runtime/src/http.rs +4 -5
- package/crates/tish_runtime/src/http_fetch.rs +9 -10
- package/crates/tish_runtime/src/lib.rs +9 -2
- package/crates/tish_runtime/src/promise.rs +2 -3
- package/crates/tish_runtime/src/promise_io.rs +2 -3
- package/crates/tish_runtime/src/ws.rs +7 -7
- package/crates/tish_ui/Cargo.toml +17 -0
- package/crates/tish_ui/src/jsx.rs +390 -0
- package/crates/tish_ui/src/lib.rs +16 -0
- package/crates/tish_ui/src/runtime/hooks.rs +122 -0
- package/crates/tish_ui/src/runtime/mod.rs +173 -0
- package/crates/tish_vm/src/vm.rs +121 -27
- package/justfile +3 -3
- 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
- package/crates/tish_compile_js/src/js_intrinsics.rs +0 -82
- package/crates/tish_jsx_web/vendor/Lattish.tish +0 -362
|
@@ -5,7 +5,8 @@ use std::sync::Arc;
|
|
|
5
5
|
|
|
6
6
|
use tishlang_ast::{
|
|
7
7
|
ArrayElement, ArrowBody, BinOp, CallArg, DestructElement, DestructPattern, Expr,
|
|
8
|
-
JsxAttrValue, JsxChild, JsxProp, Literal, MemberProp, ObjectProp, Program, Span,
|
|
8
|
+
FunParam, JsxAttrValue, JsxChild, JsxProp, Literal, MemberProp, ObjectProp, Program, Span,
|
|
9
|
+
Statement,
|
|
9
10
|
};
|
|
10
11
|
|
|
11
12
|
use crate::chunk::{Chunk, Constant};
|
|
@@ -137,8 +138,14 @@ impl<'a> Compiler<'a> {
|
|
|
137
138
|
if params.len() != 2 {
|
|
138
139
|
return None;
|
|
139
140
|
}
|
|
140
|
-
let param_a = params[0]
|
|
141
|
-
|
|
141
|
+
let (param_a, param_b) = match (¶ms[0], ¶ms[1]) {
|
|
142
|
+
(FunParam::Simple(a), FunParam::Simple(b))
|
|
143
|
+
if a.default.is_none() && b.default.is_none() =>
|
|
144
|
+
{
|
|
145
|
+
(a.name.as_ref(), b.name.as_ref())
|
|
146
|
+
}
|
|
147
|
+
_ => return None,
|
|
148
|
+
};
|
|
142
149
|
let body_expr = match body {
|
|
143
150
|
ArrowBody::Expr(e) => e.as_ref(),
|
|
144
151
|
ArrowBody::Block(stmt) => {
|
|
@@ -184,8 +191,14 @@ impl<'a> Compiler<'a> {
|
|
|
184
191
|
if params.len() != 2 {
|
|
185
192
|
return None;
|
|
186
193
|
}
|
|
187
|
-
let param_a = params[0]
|
|
188
|
-
|
|
194
|
+
let (param_a, param_b) = match (¶ms[0], ¶ms[1]) {
|
|
195
|
+
(FunParam::Simple(a), FunParam::Simple(b))
|
|
196
|
+
if a.default.is_none() && b.default.is_none() =>
|
|
197
|
+
{
|
|
198
|
+
(a.name.as_ref(), b.name.as_ref())
|
|
199
|
+
}
|
|
200
|
+
_ => return None,
|
|
201
|
+
};
|
|
189
202
|
let body_expr = match body {
|
|
190
203
|
ArrowBody::Expr(e) => e.as_ref(),
|
|
191
204
|
ArrowBody::Block(stmt) => {
|
|
@@ -228,7 +241,10 @@ impl<'a> Compiler<'a> {
|
|
|
228
241
|
if params.len() != 1 {
|
|
229
242
|
return None;
|
|
230
243
|
}
|
|
231
|
-
let param_name = params[0]
|
|
244
|
+
let param_name = match ¶ms[0] {
|
|
245
|
+
FunParam::Simple(tp) if tp.default.is_none() => tp.name.as_ref(),
|
|
246
|
+
_ => return None,
|
|
247
|
+
};
|
|
232
248
|
let expr_ref: &Expr = match body {
|
|
233
249
|
ArrowBody::Expr(e) => e.as_ref(),
|
|
234
250
|
ArrowBody::Block(stmt) => {
|
|
@@ -277,7 +293,10 @@ impl<'a> Compiler<'a> {
|
|
|
277
293
|
if params.len() != 1 {
|
|
278
294
|
return None;
|
|
279
295
|
}
|
|
280
|
-
let param_name = params[0]
|
|
296
|
+
let param_name = match ¶ms[0] {
|
|
297
|
+
FunParam::Simple(tp) if tp.default.is_none() => tp.name.as_ref(),
|
|
298
|
+
_ => return None,
|
|
299
|
+
};
|
|
281
300
|
let expr_ref: &Expr = match body {
|
|
282
301
|
ArrowBody::Expr(e) => e.as_ref(),
|
|
283
302
|
ArrowBody::Block(stmt) => {
|
|
@@ -550,9 +569,22 @@ impl<'a> Compiler<'a> {
|
|
|
550
569
|
async_: _,
|
|
551
570
|
..
|
|
552
571
|
} => {
|
|
572
|
+
for p in params {
|
|
573
|
+
if matches!(p, FunParam::Destructure { .. }) {
|
|
574
|
+
return Err(CompileError {
|
|
575
|
+
message: "Destructuring parameters are not supported in bytecode"
|
|
576
|
+
.to_string(),
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
}
|
|
553
580
|
let mut inner = Chunk::new();
|
|
554
|
-
let mut param_names: Vec<Arc<str>> =
|
|
555
|
-
|
|
581
|
+
let mut param_names: Vec<Arc<str>> = params
|
|
582
|
+
.iter()
|
|
583
|
+
.map(|p| match p {
|
|
584
|
+
FunParam::Simple(tp) => Arc::clone(&tp.name),
|
|
585
|
+
_ => unreachable!(),
|
|
586
|
+
})
|
|
587
|
+
.collect();
|
|
556
588
|
if let Some(rp) = rest_param {
|
|
557
589
|
param_names.push(rp.name.clone());
|
|
558
590
|
inner.rest_param_index = (param_names.len() as u16).saturating_sub(1);
|
|
@@ -1061,9 +1093,22 @@ impl<'a> Compiler<'a> {
|
|
|
1061
1093
|
self.emit_u16(Opcode::Call, 1);
|
|
1062
1094
|
}
|
|
1063
1095
|
Expr::ArrowFunction { params, body, .. } => {
|
|
1096
|
+
for p in params {
|
|
1097
|
+
if matches!(p, FunParam::Destructure { .. }) {
|
|
1098
|
+
return Err(CompileError {
|
|
1099
|
+
message: "Destructuring parameters are not supported in bytecode"
|
|
1100
|
+
.to_string(),
|
|
1101
|
+
});
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1064
1104
|
let mut inner = Chunk::new();
|
|
1065
|
-
let param_names: Vec<Arc<str>> =
|
|
1066
|
-
|
|
1105
|
+
let param_names: Vec<Arc<str>> = params
|
|
1106
|
+
.iter()
|
|
1107
|
+
.map(|p| match p {
|
|
1108
|
+
FunParam::Simple(tp) => Arc::clone(&tp.name),
|
|
1109
|
+
_ => unreachable!(),
|
|
1110
|
+
})
|
|
1111
|
+
.collect();
|
|
1067
1112
|
for p in ¶m_names {
|
|
1068
1113
|
inner.add_name(Arc::clone(p));
|
|
1069
1114
|
}
|
|
@@ -1205,6 +1250,35 @@ impl<'a> Compiler<'a> {
|
|
|
1205
1250
|
message: "Logical assignment (&&=, ||=, ??=) not yet supported in bytecode".to_string(),
|
|
1206
1251
|
});
|
|
1207
1252
|
}
|
|
1253
|
+
Expr::New { callee, args, .. } => {
|
|
1254
|
+
let has_spread = args.iter().any(|a| matches!(a, CallArg::Spread(_)));
|
|
1255
|
+
if has_spread {
|
|
1256
|
+
self.emit_u16(Opcode::NewArray, 0);
|
|
1257
|
+
for arg in args {
|
|
1258
|
+
match arg {
|
|
1259
|
+
CallArg::Expr(e) => {
|
|
1260
|
+
self.compile_expr(e)?;
|
|
1261
|
+
self.emit_u16(Opcode::NewArray, 1);
|
|
1262
|
+
self.emit(Opcode::ConcatArray);
|
|
1263
|
+
}
|
|
1264
|
+
CallArg::Spread(expr) => {
|
|
1265
|
+
self.compile_expr(expr)?;
|
|
1266
|
+
self.emit(Opcode::ConcatArray);
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
self.compile_expr(callee)?;
|
|
1271
|
+
self.emit(Opcode::ConstructSpread);
|
|
1272
|
+
} else {
|
|
1273
|
+
self.compile_expr(callee)?;
|
|
1274
|
+
for arg in args {
|
|
1275
|
+
if let CallArg::Expr(e) = arg {
|
|
1276
|
+
self.compile_expr(e)?;
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
self.emit_u16(Opcode::Construct, args.len() as u16);
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1208
1282
|
}
|
|
1209
1283
|
Ok(())
|
|
1210
1284
|
}
|
|
@@ -80,13 +80,17 @@ pub enum Opcode {
|
|
|
80
80
|
ArrayFilterBinOp = 35,
|
|
81
81
|
/// Load built-in module export. Operands: u16 spec_const_idx, u16 export_name_const_idx. Pushes Value.
|
|
82
82
|
LoadNativeExport = 36,
|
|
83
|
+
/// `new callee(...args)` (operand: u16 arg count). Stack: callee, then args — same as Call.
|
|
84
|
+
Construct = 37,
|
|
85
|
+
/// `new callee(...spread)` — stack: args array, then callee (same order as CallSpread).
|
|
86
|
+
ConstructSpread = 38,
|
|
83
87
|
}
|
|
84
88
|
|
|
85
89
|
impl Opcode {
|
|
86
|
-
/// Decode byte to opcode. Safe for b in 0..=
|
|
90
|
+
/// Decode byte to opcode. Safe for b in 0..=38 (matches #[repr(u8)] discriminants).
|
|
87
91
|
#[inline]
|
|
88
92
|
pub fn from_u8(b: u8) -> Option<Opcode> {
|
|
89
|
-
if b <=
|
|
93
|
+
if b <= 38 {
|
|
90
94
|
Some(unsafe { std::mem::transmute(b) })
|
|
91
95
|
} else {
|
|
92
96
|
None
|
|
@@ -97,7 +101,7 @@ impl Opcode {
|
|
|
97
101
|
pub fn instruction_size(self, code: &[u8], ip: usize) -> Option<usize> {
|
|
98
102
|
let size = match self {
|
|
99
103
|
Opcode::Nop | Opcode::Pop | Opcode::Dup | Opcode::Return | Opcode::ExitTry
|
|
100
|
-
| Opcode::ArrayMapIdentity => 1,
|
|
104
|
+
| Opcode::ArrayMapIdentity | Opcode::CallSpread | Opcode::ConstructSpread => 1,
|
|
101
105
|
Opcode::ArraySortByProperty | Opcode::ArrayMapBinOp | Opcode::ArrayFilterBinOp
|
|
102
106
|
| Opcode::LoadNativeExport => 5,
|
|
103
107
|
_ => 3,
|
|
@@ -18,6 +18,7 @@ ws = []
|
|
|
18
18
|
tishlang_ast = { path = "../tish_ast", version = ">=0.1" }
|
|
19
19
|
tishlang_opt = { path = "../tish_opt", version = ">=0.1" }
|
|
20
20
|
tishlang_parser = { path = "../tish_parser", version = ">=0.1" }
|
|
21
|
+
tishlang_ui = { path = "../tish_ui", default-features = false, features = ["compiler"] }
|
|
21
22
|
serde_json = "1.0"
|
|
22
23
|
|
|
23
24
|
[dev-dependencies]
|