@tishlang/tish 1.0.13 → 1.0.15
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/crates/js_to_tish/Cargo.toml +4 -2
- package/crates/js_to_tish/src/span_util.rs +1 -1
- package/crates/js_to_tish/src/transform/expr.rs +15 -15
- package/crates/js_to_tish/src/transform/stmt.rs +7 -7
- package/crates/js_to_tish/src/transform.rs +1 -1
- package/crates/tish/Cargo.toml +22 -22
- package/crates/tish/src/main.rs +46 -46
- package/crates/tish/src/repl_completion.rs +4 -4
- package/crates/tish/tests/integration_test.rs +28 -28
- package/crates/tish_ast/Cargo.toml +3 -1
- package/crates/tish_ast/src/ast.rs +1 -1
- package/crates/tish_build_utils/Cargo.toml +3 -1
- package/crates/tish_build_utils/src/lib.rs +18 -6
- package/crates/tish_builtins/Cargo.toml +5 -3
- package/crates/tish_builtins/src/array.rs +2 -2
- package/crates/tish_builtins/src/globals.rs +3 -3
- package/crates/tish_builtins/src/helpers.rs +1 -1
- package/crates/tish_builtins/src/lib.rs +3 -3
- package/crates/tish_builtins/src/math.rs +1 -1
- package/crates/tish_builtins/src/object.rs +2 -2
- package/crates/tish_builtins/src/string.rs +1 -1
- package/crates/tish_bytecode/Cargo.toml +9 -7
- package/crates/tish_bytecode/src/chunk.rs +1 -1
- package/crates/tish_bytecode/src/compiler.rs +1 -1
- package/crates/tish_bytecode/src/encoding.rs +6 -6
- package/crates/tish_bytecode/tests/constant_folding.rs +7 -7
- package/crates/tish_bytecode/tests/shortcircuit.rs +11 -11
- package/crates/tish_bytecode/tests/sort_optimization.rs +3 -3
- package/crates/tish_compile/Cargo.toml +6 -4
- package/crates/tish_compile/src/codegen.rs +96 -96
- package/crates/tish_compile/src/lib.rs +2 -2
- package/crates/tish_compile/src/resolve.rs +7 -7
- package/crates/tish_compile/src/types.rs +1 -1
- package/crates/tish_compile_js/Cargo.toml +8 -6
- package/crates/tish_compile_js/src/codegen.rs +12 -12
- package/crates/tish_compile_js/src/js_intrinsics.rs +1 -1
- package/crates/tish_compile_js/src/lib.rs +2 -2
- package/crates/tish_compile_js/src/tests_jsx.rs +2 -2
- package/crates/tish_compiler_wasm/Cargo.toml +8 -6
- package/crates/tish_compiler_wasm/src/lib.rs +12 -12
- package/crates/tish_compiler_wasm/src/resolve_virtual.rs +3 -3
- package/crates/tish_core/Cargo.toml +3 -1
- package/crates/tish_core/src/lib.rs +1 -1
- package/crates/tish_core/src/macros.rs +1 -1
- package/crates/tish_core/src/value.rs +1 -1
- package/crates/tish_cranelift/Cargo.toml +6 -4
- package/crates/tish_cranelift/src/lib.rs +2 -2
- package/crates/tish_cranelift/src/link.rs +11 -11
- package/crates/tish_cranelift/src/lower.rs +3 -3
- package/crates/tish_cranelift_runtime/Cargo.toml +9 -7
- package/crates/tish_cranelift_runtime/src/lib.rs +2 -2
- package/crates/tish_eval/Cargo.toml +10 -8
- package/crates/tish_eval/src/eval.rs +35 -35
- package/crates/tish_eval/src/http.rs +1 -1
- package/crates/tish_eval/src/lib.rs +3 -3
- package/crates/tish_eval/src/natives.rs +2 -2
- package/crates/tish_eval/src/regex.rs +2 -2
- package/crates/tish_eval/src/value.rs +7 -7
- package/crates/tish_eval/src/value_convert.rs +3 -3
- package/crates/tish_fmt/Cargo.toml +3 -3
- package/crates/tish_fmt/src/bin/tish-fmt.rs +1 -1
- package/crates/tish_fmt/src/lib.rs +3 -3
- package/crates/tish_jsx_web/Cargo.toml +3 -1
- package/crates/tish_lexer/Cargo.toml +3 -1
- package/crates/tish_lint/Cargo.toml +3 -3
- package/crates/tish_lint/src/bin/tish-lint.rs +3 -3
- package/crates/tish_lint/src/lib.rs +15 -15
- package/crates/tish_llvm/Cargo.toml +7 -5
- package/crates/tish_llvm/src/lib.rs +10 -10
- package/crates/tish_lsp/Cargo.toml +5 -5
- package/crates/tish_lsp/src/main.rs +35 -35
- package/crates/tish_native/Cargo.toml +10 -8
- package/crates/tish_native/src/build.rs +8 -8
- package/crates/tish_native/src/lib.rs +39 -39
- package/crates/tish_opt/Cargo.toml +5 -3
- package/crates/tish_opt/src/lib.rs +27 -27
- package/crates/tish_parser/Cargo.toml +5 -3
- package/crates/tish_parser/src/lib.rs +4 -4
- package/crates/tish_parser/src/parser.rs +2 -2
- package/crates/tish_runtime/Cargo.toml +7 -5
- package/crates/tish_runtime/src/http.rs +1 -1
- package/crates/tish_runtime/src/http_fetch.rs +2 -2
- package/crates/tish_runtime/src/lib.rs +21 -21
- package/crates/tish_runtime/src/native_promise.rs +1 -1
- package/crates/tish_runtime/src/promise.rs +2 -2
- package/crates/tish_runtime/src/promise_io.rs +1 -1
- package/crates/tish_runtime/src/timers.rs +1 -1
- package/crates/tish_runtime/src/ws.rs +1 -1
- package/crates/tish_runtime/tests/fetch_readable_stream.rs +2 -2
- package/crates/tish_vm/Cargo.toml +14 -12
- package/crates/tish_vm/src/lib.rs +2 -2
- package/crates/tish_vm/src/vm.rs +42 -42
- package/crates/tish_wasm/Cargo.toml +8 -6
- package/crates/tish_wasm/src/lib.rs +17 -17
- package/crates/tish_wasm_runtime/Cargo.toml +9 -7
- package/crates/tish_wasm_runtime/src/lib.rs +4 -4
- package/justfile +4 -4
- 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,14 +2,14 @@
|
|
|
2
2
|
//!
|
|
3
3
|
//! Compiles Tish bytecode to native binary using clang (LLVM toolchain).
|
|
4
4
|
//! Emits a C file with embedded bytecode, compiles with clang to object code,
|
|
5
|
-
//! then links with
|
|
5
|
+
//! then links with tishlang_cranelift_runtime.
|
|
6
6
|
|
|
7
7
|
use std::fs;
|
|
8
8
|
use std::path::Path;
|
|
9
9
|
use std::process::Command;
|
|
10
10
|
|
|
11
|
-
use
|
|
12
|
-
use
|
|
11
|
+
use tishlang_bytecode::{serialize, Chunk};
|
|
12
|
+
use tishlang_compile::{detect_cycles, merge_modules, resolve_project};
|
|
13
13
|
|
|
14
14
|
/// Compile a Tish program to a native binary via clang/LLVM.
|
|
15
15
|
pub fn compile_to_native(
|
|
@@ -21,16 +21,16 @@ pub fn compile_to_native(
|
|
|
21
21
|
.map_err(|e| LlvmError { message: e.to_string() })?;
|
|
22
22
|
detect_cycles(&modules).map_err(|e| LlvmError { message: e.to_string() })?;
|
|
23
23
|
let program = merge_modules(modules).map_err(|e| LlvmError { message: e.to_string() })?;
|
|
24
|
-
let chunk =
|
|
24
|
+
let chunk = tishlang_bytecode::compile(&program).map_err(|e| LlvmError {
|
|
25
25
|
message: e.to_string(),
|
|
26
26
|
})?;
|
|
27
27
|
|
|
28
|
-
let features =
|
|
28
|
+
let features = tishlang_compile::extract_native_import_features(&program);
|
|
29
29
|
compile_chunk_to_native(&chunk, output_path, &features)
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
/// Compile a bytecode chunk to a native binary.
|
|
33
|
-
/// `features` are passed to
|
|
33
|
+
/// `features` are passed to tishlang_cranelift_runtime (e.g. fs, process, http for built-in modules).
|
|
34
34
|
pub fn compile_chunk_to_native(
|
|
35
35
|
chunk: &Chunk,
|
|
36
36
|
output_path: &Path,
|
|
@@ -41,13 +41,13 @@ pub fn compile_chunk_to_native(
|
|
|
41
41
|
.file_stem()
|
|
42
42
|
.and_then(|s| s.to_str())
|
|
43
43
|
.unwrap_or("tish_out");
|
|
44
|
-
let build_dir =
|
|
44
|
+
let build_dir = tishlang_build_utils::create_build_dir("tishlang_llvm_build", out_name)
|
|
45
45
|
.map_err(|e| LlvmError { message: e })?;
|
|
46
46
|
|
|
47
47
|
// Generate C source with embedded bytecode (data only; main comes from Rust link step)
|
|
48
48
|
let bytes_str: Vec<String> = chunk_bytes.iter().map(|b| b.to_string()).collect();
|
|
49
49
|
let chunk_c = format!(
|
|
50
|
-
r#"/* Generated by
|
|
50
|
+
r#"/* Generated by tishlang_llvm - do not edit */
|
|
51
51
|
#include <stddef.h>
|
|
52
52
|
#include <stdint.h>
|
|
53
53
|
|
|
@@ -80,11 +80,11 @@ const uint64_t tish_chunk_len = sizeof(tish_chunk_data);
|
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
// Link using the same infrastructure as Cranelift (links .o with
|
|
83
|
+
// Link using the same infrastructure as Cranelift (links .o with tishlang_cranelift_runtime)
|
|
84
84
|
let object_path_canonical = object_path.canonicalize().map_err(|e| LlvmError {
|
|
85
85
|
message: format!("Cannot canonicalize object path: {}", e),
|
|
86
86
|
})?;
|
|
87
|
-
|
|
87
|
+
tishlang_cranelift::link_to_binary(&object_path_canonical, output_path, features).map_err(|e| LlvmError {
|
|
88
88
|
message: e.message,
|
|
89
89
|
})?;
|
|
90
90
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
[package]
|
|
2
|
-
name = "
|
|
2
|
+
name = "tishlang_lsp"
|
|
3
3
|
version = "0.1.0"
|
|
4
4
|
edition = "2021"
|
|
5
5
|
description = "Language Server Protocol implementation for Tish"
|
|
@@ -11,10 +11,10 @@ name = "tish-lsp"
|
|
|
11
11
|
path = "src/main.rs"
|
|
12
12
|
|
|
13
13
|
[dependencies]
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
tishlang_ast = { path = "../tish_ast" }
|
|
15
|
+
tishlang_parser = { path = "../tish_parser" }
|
|
16
|
+
tishlang_fmt = { path = "../tish_fmt" }
|
|
17
|
+
tishlang_lint = { path = "../tish_lint" }
|
|
18
18
|
tower-lsp = "0.20"
|
|
19
19
|
tokio = { version = "1", features = ["rt-multi-thread", "macros", "io-std"] }
|
|
20
20
|
serde_json = "1"
|
|
@@ -68,12 +68,12 @@ fn diag_range(line: u32, col: u32, text: &str) -> Range {
|
|
|
68
68
|
|
|
69
69
|
fn publish_parse_and_lint(client: &Client, uri: Url, text: &str) {
|
|
70
70
|
let mut diags = Vec::new();
|
|
71
|
-
match
|
|
71
|
+
match tishlang_parser::parse(text) {
|
|
72
72
|
Ok(program) => {
|
|
73
|
-
for d in
|
|
73
|
+
for d in tishlang_lint::lint_program(&program) {
|
|
74
74
|
let sev = match d.severity {
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
tishlang_lint::Severity::Error => DiagnosticSeverity::ERROR,
|
|
76
|
+
tishlang_lint::Severity::Warning => DiagnosticSeverity::WARNING,
|
|
77
77
|
};
|
|
78
78
|
diags.push(Diagnostic {
|
|
79
79
|
range: diag_range(d.line.saturating_sub(1), d.col.saturating_sub(1), text),
|
|
@@ -200,17 +200,17 @@ impl LanguageServer for Backend {
|
|
|
200
200
|
})
|
|
201
201
|
.collect();
|
|
202
202
|
|
|
203
|
-
if let Ok(program) =
|
|
203
|
+
if let Ok(program) = tishlang_parser::parse(&text) {
|
|
204
204
|
for s in &program.statements {
|
|
205
205
|
match s {
|
|
206
|
-
|
|
206
|
+
tishlang_ast::Statement::FunDecl { name, .. } => {
|
|
207
207
|
items.push(CompletionItem {
|
|
208
208
|
label: name.to_string(),
|
|
209
209
|
kind: Some(CompletionItemKind::FUNCTION),
|
|
210
210
|
..Default::default()
|
|
211
211
|
});
|
|
212
212
|
}
|
|
213
|
-
|
|
213
|
+
tishlang_ast::Statement::VarDecl { name, .. } => {
|
|
214
214
|
items.push(CompletionItem {
|
|
215
215
|
label: name.to_string(),
|
|
216
216
|
kind: Some(CompletionItemKind::VARIABLE),
|
|
@@ -247,7 +247,7 @@ impl LanguageServer for Backend {
|
|
|
247
247
|
let Some(text) = text else {
|
|
248
248
|
return Ok(None);
|
|
249
249
|
};
|
|
250
|
-
let Ok(program) =
|
|
250
|
+
let Ok(program) = tishlang_parser::parse(&text) else {
|
|
251
251
|
return Ok(None);
|
|
252
252
|
};
|
|
253
253
|
|
|
@@ -274,7 +274,7 @@ impl LanguageServer for Backend {
|
|
|
274
274
|
let Some(text) = text else {
|
|
275
275
|
return Ok(None);
|
|
276
276
|
};
|
|
277
|
-
let Ok(program) =
|
|
277
|
+
let Ok(program) = tishlang_parser::parse(&text) else {
|
|
278
278
|
return Ok(None);
|
|
279
279
|
};
|
|
280
280
|
|
|
@@ -293,7 +293,7 @@ impl LanguageServer for Backend {
|
|
|
293
293
|
|
|
294
294
|
if let Some(ref base) = path {
|
|
295
295
|
for s in &program.statements {
|
|
296
|
-
if let
|
|
296
|
+
if let tishlang_ast::Statement::Import {
|
|
297
297
|
specifiers,
|
|
298
298
|
from,
|
|
299
299
|
..
|
|
@@ -301,10 +301,10 @@ impl LanguageServer for Backend {
|
|
|
301
301
|
{
|
|
302
302
|
for sp in specifiers {
|
|
303
303
|
let (imported, local) = match sp {
|
|
304
|
-
|
|
304
|
+
tishlang_ast::ImportSpecifier::Named { name, alias } => {
|
|
305
305
|
(name.as_ref(), alias.as_ref().map(|a| a.as_ref()).unwrap_or(name.as_ref()))
|
|
306
306
|
}
|
|
307
|
-
|
|
307
|
+
tishlang_ast::ImportSpecifier::Default(n) => (n.as_ref(), n.as_ref()),
|
|
308
308
|
_ => continue,
|
|
309
309
|
};
|
|
310
310
|
if local != word.as_str() {
|
|
@@ -324,7 +324,7 @@ impl LanguageServer for Backend {
|
|
|
324
324
|
if let Ok(can) = target.canonicalize() {
|
|
325
325
|
if let Ok(u) = Url::from_file_path(&can) {
|
|
326
326
|
if let Ok(src) = std::fs::read_to_string(&can) {
|
|
327
|
-
if let Ok(prog) =
|
|
327
|
+
if let Ok(prog) = tishlang_parser::parse(&src) {
|
|
328
328
|
if let Some(loc) =
|
|
329
329
|
find_export(&prog, imported, &u, &src)
|
|
330
330
|
{
|
|
@@ -351,7 +351,7 @@ impl LanguageServer for Backend {
|
|
|
351
351
|
let Some(text) = text else {
|
|
352
352
|
return Ok(None);
|
|
353
353
|
};
|
|
354
|
-
match
|
|
354
|
+
match tishlang_fmt::format_source(&text) {
|
|
355
355
|
Ok(formatted) => {
|
|
356
356
|
let lines = text.lines().count() as u32;
|
|
357
357
|
let last_line = text.lines().last().map(|l| l.len() as u32).unwrap_or(0);
|
|
@@ -396,7 +396,7 @@ impl LanguageServer for Backend {
|
|
|
396
396
|
let Ok(src) = std::fs::read_to_string(path) else {
|
|
397
397
|
continue;
|
|
398
398
|
};
|
|
399
|
-
let Ok(program) =
|
|
399
|
+
let Ok(program) = tishlang_parser::parse(&src) else {
|
|
400
400
|
continue;
|
|
401
401
|
};
|
|
402
402
|
let Ok(uri) = Url::from_file_path(path) else {
|
|
@@ -412,14 +412,14 @@ impl LanguageServer for Backend {
|
|
|
412
412
|
}
|
|
413
413
|
|
|
414
414
|
fn collect_workspace_syms(
|
|
415
|
-
s: &
|
|
415
|
+
s: &tishlang_ast::Statement,
|
|
416
416
|
text: &str,
|
|
417
417
|
uri: &Url,
|
|
418
418
|
query: &str,
|
|
419
419
|
out: &mut Vec<SymbolInformation>,
|
|
420
420
|
) {
|
|
421
421
|
match s {
|
|
422
|
-
|
|
422
|
+
tishlang_ast::Statement::FunDecl { name, span, .. } => {
|
|
423
423
|
if name.to_lowercase().contains(query) {
|
|
424
424
|
out.push(SymbolInformation {
|
|
425
425
|
name: name.to_string(),
|
|
@@ -434,7 +434,7 @@ fn collect_workspace_syms(
|
|
|
434
434
|
});
|
|
435
435
|
}
|
|
436
436
|
}
|
|
437
|
-
|
|
437
|
+
tishlang_ast::Statement::VarDecl { name, span, .. } => {
|
|
438
438
|
if name.to_lowercase().contains(query) {
|
|
439
439
|
out.push(SymbolInformation {
|
|
440
440
|
name: name.to_string(),
|
|
@@ -449,7 +449,7 @@ fn collect_workspace_syms(
|
|
|
449
449
|
});
|
|
450
450
|
}
|
|
451
451
|
}
|
|
452
|
-
|
|
452
|
+
tishlang_ast::Statement::Block { statements, .. } => {
|
|
453
453
|
for x in statements {
|
|
454
454
|
collect_workspace_syms(x, text, uri, query, out);
|
|
455
455
|
}
|
|
@@ -459,27 +459,27 @@ fn collect_workspace_syms(
|
|
|
459
459
|
}
|
|
460
460
|
|
|
461
461
|
fn find_export(
|
|
462
|
-
program: &
|
|
462
|
+
program: &tishlang_ast::Program,
|
|
463
463
|
name: &str,
|
|
464
464
|
uri: &Url,
|
|
465
465
|
text: &str,
|
|
466
466
|
) -> Option<Location> {
|
|
467
467
|
for s in &program.statements {
|
|
468
468
|
match s {
|
|
469
|
-
|
|
469
|
+
tishlang_ast::Statement::FunDecl { name: n, span, .. } if n.as_ref() == name => {
|
|
470
470
|
return Some(Location {
|
|
471
471
|
uri: uri.clone(),
|
|
472
472
|
range: span_to_range(span, text),
|
|
473
473
|
});
|
|
474
474
|
}
|
|
475
|
-
|
|
475
|
+
tishlang_ast::Statement::VarDecl { name: n, span, .. } if n.as_ref() == name => {
|
|
476
476
|
return Some(Location {
|
|
477
477
|
uri: uri.clone(),
|
|
478
478
|
range: span_to_range(span, text),
|
|
479
479
|
});
|
|
480
480
|
}
|
|
481
|
-
|
|
482
|
-
|
|
481
|
+
tishlang_ast::Statement::Export { declaration, .. } => match declaration.as_ref() {
|
|
482
|
+
tishlang_ast::ExportDeclaration::Named(inner) => {
|
|
483
483
|
if let Some(loc) = find_decl_in_stmt(inner, name, uri, text) {
|
|
484
484
|
return Some(loc);
|
|
485
485
|
}
|
|
@@ -493,21 +493,21 @@ fn find_export(
|
|
|
493
493
|
}
|
|
494
494
|
|
|
495
495
|
fn find_decl_in_stmt(
|
|
496
|
-
s: &
|
|
496
|
+
s: &tishlang_ast::Statement,
|
|
497
497
|
word: &str,
|
|
498
498
|
uri: &Url,
|
|
499
499
|
text: &str,
|
|
500
500
|
) -> Option<Location> {
|
|
501
501
|
match s {
|
|
502
|
-
|
|
502
|
+
tishlang_ast::Statement::FunDecl { name, span, .. } if name.as_ref() == word => Some(Location {
|
|
503
503
|
uri: uri.clone(),
|
|
504
504
|
range: span_to_range(span, text),
|
|
505
505
|
}),
|
|
506
|
-
|
|
506
|
+
tishlang_ast::Statement::VarDecl { name, span, .. } if name.as_ref() == word => Some(Location {
|
|
507
507
|
uri: uri.clone(),
|
|
508
508
|
range: span_to_range(span, text),
|
|
509
509
|
}),
|
|
510
|
-
|
|
510
|
+
tishlang_ast::Statement::Block { statements, .. } => {
|
|
511
511
|
for x in statements {
|
|
512
512
|
if let Some(l) = find_decl_in_stmt(x, word, uri, text) {
|
|
513
513
|
return Some(l);
|
|
@@ -519,7 +519,7 @@ fn find_decl_in_stmt(
|
|
|
519
519
|
}
|
|
520
520
|
}
|
|
521
521
|
|
|
522
|
-
fn span_to_range(span: &
|
|
522
|
+
fn span_to_range(span: &tishlang_ast::Span, _text: &str) -> Range {
|
|
523
523
|
Range {
|
|
524
524
|
start: pos(span.start.0.saturating_sub(1) as u32, span.start.1.saturating_sub(1) as u32),
|
|
525
525
|
end: pos(span.end.0.saturating_sub(1) as u32, span.end.1.saturating_sub(1) as u32),
|
|
@@ -550,12 +550,12 @@ fn is_ident_char(c: char) -> bool {
|
|
|
550
550
|
}
|
|
551
551
|
|
|
552
552
|
fn doc_symbol_stmt(
|
|
553
|
-
s: &
|
|
553
|
+
s: &tishlang_ast::Statement,
|
|
554
554
|
text: &str,
|
|
555
555
|
out: &mut Vec<tower_lsp::lsp_types::DocumentSymbol>,
|
|
556
556
|
) {
|
|
557
557
|
match s {
|
|
558
|
-
|
|
558
|
+
tishlang_ast::Statement::FunDecl {
|
|
559
559
|
name,
|
|
560
560
|
span,
|
|
561
561
|
body,
|
|
@@ -578,7 +578,7 @@ fn doc_symbol_stmt(
|
|
|
578
578
|
},
|
|
579
579
|
});
|
|
580
580
|
}
|
|
581
|
-
|
|
581
|
+
tishlang_ast::Statement::VarDecl { name, span, .. } => {
|
|
582
582
|
out.push(tower_lsp::lsp_types::DocumentSymbol {
|
|
583
583
|
name: name.to_string(),
|
|
584
584
|
detail: None,
|
|
@@ -590,7 +590,7 @@ fn doc_symbol_stmt(
|
|
|
590
590
|
children: None,
|
|
591
591
|
});
|
|
592
592
|
}
|
|
593
|
-
|
|
593
|
+
tishlang_ast::Statement::Block { statements, .. } => {
|
|
594
594
|
for x in statements {
|
|
595
595
|
doc_symbol_stmt(x, text, out);
|
|
596
596
|
}
|
|
@@ -600,12 +600,12 @@ fn doc_symbol_stmt(
|
|
|
600
600
|
}
|
|
601
601
|
|
|
602
602
|
fn collect_child_syms(
|
|
603
|
-
s: &
|
|
603
|
+
s: &tishlang_ast::Statement,
|
|
604
604
|
text: &str,
|
|
605
605
|
out: &mut Vec<tower_lsp::lsp_types::DocumentSymbol>,
|
|
606
606
|
) {
|
|
607
607
|
match s {
|
|
608
|
-
|
|
608
|
+
tishlang_ast::Statement::Block { statements, .. } => {
|
|
609
609
|
for x in statements {
|
|
610
610
|
doc_symbol_stmt(x, text, out);
|
|
611
611
|
}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
[package]
|
|
2
|
-
name = "
|
|
2
|
+
name = "tishlang_native"
|
|
3
3
|
version = "0.1.0"
|
|
4
4
|
edition = "2021"
|
|
5
5
|
description = "Native code generation backend for Tish (Cranelift / direct compile)"
|
|
6
6
|
|
|
7
|
+
license-file = { workspace = true }
|
|
8
|
+
repository = { workspace = true }
|
|
7
9
|
[dependencies]
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
tishlang_build_utils = { path = "../tish_build_utils" }
|
|
11
|
+
tishlang_ast = { path = "../tish_ast" }
|
|
12
|
+
tishlang_bytecode = { path = "../tish_bytecode" }
|
|
13
|
+
tishlang_compile = { path = "../tish_compile" }
|
|
14
|
+
tishlang_cranelift = { path = "../tish_cranelift" }
|
|
15
|
+
tishlang_llvm = { path = "../tish_llvm" }
|
|
16
|
+
tishlang_opt = { path = "../tish_opt" }
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
use std::fs;
|
|
4
4
|
use std::path::Path;
|
|
5
5
|
|
|
6
|
-
use
|
|
6
|
+
use tishlang_compile::ResolvedNativeModule;
|
|
7
7
|
|
|
8
8
|
pub fn build_via_cargo(
|
|
9
9
|
rust_code: &str,
|
|
@@ -15,9 +15,9 @@ pub fn build_via_cargo(
|
|
|
15
15
|
.file_stem()
|
|
16
16
|
.and_then(|s| s.to_str())
|
|
17
17
|
.unwrap_or("tish_out");
|
|
18
|
-
let build_dir =
|
|
18
|
+
let build_dir = tishlang_build_utils::create_build_dir("tish_build", out_name)?;
|
|
19
19
|
|
|
20
|
-
let runtime_path =
|
|
20
|
+
let runtime_path = tishlang_build_utils::find_runtime_path()?;
|
|
21
21
|
|
|
22
22
|
let runtime_features: Vec<&str> = features
|
|
23
23
|
.iter()
|
|
@@ -63,7 +63,7 @@ codegen-units = 1
|
|
|
63
63
|
lto = "thin"
|
|
64
64
|
|
|
65
65
|
[dependencies]
|
|
66
|
-
|
|
66
|
+
tishlang_runtime = {{ path = {:?}{} }}{}{}
|
|
67
67
|
"#,
|
|
68
68
|
out_name,
|
|
69
69
|
runtime_path,
|
|
@@ -91,11 +91,11 @@ tish_runtime = {{ path = {:?}{} }}{}{}
|
|
|
91
91
|
.map(|t| t.join("release"))
|
|
92
92
|
.unwrap_or_else(|| build_dir.join("target").join("release"));
|
|
93
93
|
|
|
94
|
-
|
|
94
|
+
tishlang_build_utils::run_cargo_build(&build_dir, target_dir.as_deref())?;
|
|
95
95
|
|
|
96
|
-
let binary =
|
|
97
|
-
let target =
|
|
98
|
-
|
|
96
|
+
let binary = tishlang_build_utils::find_release_binary(&binary_dir, out_name)?;
|
|
97
|
+
let target = tishlang_build_utils::resolve_output_path(output_path, out_name);
|
|
98
|
+
tishlang_build_utils::copy_binary_to_output(&binary, &target)?;
|
|
99
99
|
|
|
100
100
|
Ok(())
|
|
101
101
|
}
|
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
//!
|
|
3
3
|
//! Target architecture (per plan):
|
|
4
4
|
//! - Phase 2: Bytecode -> Cranelift IR -> .o -> link with minimal runtime
|
|
5
|
-
//! - Current: Delegates to
|
|
5
|
+
//! - Current: Delegates to tishlang_compile (Rust codegen) + cargo build as interim path
|
|
6
6
|
//!
|
|
7
7
|
//! Once Cranelift backend is implemented, this crate will:
|
|
8
8
|
//! 1. Take Chunk (bytecode) as input
|
|
9
9
|
//! 2. Lower to Cranelift IR
|
|
10
10
|
//! 3. Emit .o via cranelift-object
|
|
11
|
-
//! 4. Link against prebuilt
|
|
11
|
+
//! 4. Link against prebuilt tishlang_runtime staticlib
|
|
12
12
|
|
|
13
13
|
mod build;
|
|
14
14
|
|
|
15
15
|
use std::path::Path;
|
|
16
|
-
use
|
|
16
|
+
use tishlang_ast::Program;
|
|
17
17
|
|
|
18
18
|
/// Error from native compilation.
|
|
19
19
|
#[derive(Debug)]
|
|
@@ -58,7 +58,7 @@ pub fn compile_to_native(
|
|
|
58
58
|
|
|
59
59
|
match backend {
|
|
60
60
|
Backend::Rust => {
|
|
61
|
-
let (rust_code, native_modules) =
|
|
61
|
+
let (rust_code, native_modules) = tishlang_compile::compile_project_full(
|
|
62
62
|
entry_path,
|
|
63
63
|
project_root,
|
|
64
64
|
features,
|
|
@@ -72,82 +72,82 @@ pub fn compile_to_native(
|
|
|
72
72
|
.map_err(|e| NativeError { message: e })
|
|
73
73
|
}
|
|
74
74
|
Backend::Cranelift => {
|
|
75
|
-
let modules =
|
|
75
|
+
let modules = tishlang_compile::resolve_project(entry_path, project_root)
|
|
76
76
|
.map_err(|e| NativeError {
|
|
77
77
|
message: e.to_string(),
|
|
78
78
|
})?;
|
|
79
|
-
|
|
79
|
+
tishlang_compile::detect_cycles(&modules).map_err(|e| NativeError {
|
|
80
80
|
message: e.to_string(),
|
|
81
81
|
})?;
|
|
82
82
|
let program = {
|
|
83
|
-
let prog =
|
|
83
|
+
let prog = tishlang_compile::merge_modules(modules).map_err(|e| NativeError {
|
|
84
84
|
message: e.to_string(),
|
|
85
85
|
})?;
|
|
86
86
|
if optimize {
|
|
87
|
-
|
|
87
|
+
tishlang_opt::optimize(&prog)
|
|
88
88
|
} else {
|
|
89
89
|
prog
|
|
90
90
|
}
|
|
91
91
|
};
|
|
92
92
|
|
|
93
|
-
if
|
|
93
|
+
if tishlang_compile::has_external_native_imports(&program) {
|
|
94
94
|
return Err(NativeError {
|
|
95
95
|
message: "Cranelift backend does not support external native imports (tish:egui, @scope/pkg). Built-in tish:fs, tish:http, tish:process are supported. Use --native-backend rust for external modules.".to_string(),
|
|
96
96
|
});
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
let chunk = if optimize {
|
|
100
|
-
|
|
100
|
+
tishlang_bytecode::compile(&program).map_err(|e| NativeError {
|
|
101
101
|
message: e.to_string(),
|
|
102
102
|
})?
|
|
103
103
|
} else {
|
|
104
|
-
|
|
104
|
+
tishlang_bytecode::compile_unoptimized(&program).map_err(|e| NativeError {
|
|
105
105
|
message: e.to_string(),
|
|
106
106
|
})?
|
|
107
107
|
};
|
|
108
108
|
|
|
109
|
-
let cranelift_features =
|
|
110
|
-
|
|
109
|
+
let cranelift_features = tishlang_compile::extract_native_import_features(&program);
|
|
110
|
+
tishlang_cranelift::compile_chunk_to_native(&chunk, output_path, &cranelift_features)
|
|
111
111
|
.map_err(|e| NativeError {
|
|
112
112
|
message: e.to_string(),
|
|
113
113
|
})
|
|
114
114
|
}
|
|
115
115
|
Backend::Llvm => {
|
|
116
|
-
let modules =
|
|
116
|
+
let modules = tishlang_compile::resolve_project(entry_path, project_root)
|
|
117
117
|
.map_err(|e| NativeError { message: e.to_string() })?;
|
|
118
|
-
|
|
118
|
+
tishlang_compile::detect_cycles(&modules).map_err(|e| NativeError { message: e.to_string() })?;
|
|
119
119
|
let program = {
|
|
120
|
-
let prog =
|
|
120
|
+
let prog = tishlang_compile::merge_modules(modules).map_err(|e| NativeError {
|
|
121
121
|
message: e.to_string(),
|
|
122
122
|
})?;
|
|
123
123
|
if optimize {
|
|
124
|
-
|
|
124
|
+
tishlang_opt::optimize(&prog)
|
|
125
125
|
} else {
|
|
126
126
|
prog
|
|
127
127
|
}
|
|
128
128
|
};
|
|
129
|
-
if
|
|
129
|
+
if tishlang_compile::has_external_native_imports(&program) {
|
|
130
130
|
return Err(NativeError {
|
|
131
131
|
message: "LLVM backend does not support external native imports. Built-in tish:fs, tish:http, tish:process are supported.".to_string(),
|
|
132
132
|
});
|
|
133
133
|
}
|
|
134
134
|
let chunk = if optimize {
|
|
135
|
-
|
|
135
|
+
tishlang_bytecode::compile(&program).map_err(|e| NativeError {
|
|
136
136
|
message: e.to_string(),
|
|
137
137
|
})?
|
|
138
138
|
} else {
|
|
139
|
-
|
|
139
|
+
tishlang_bytecode::compile_unoptimized(&program).map_err(|e| NativeError {
|
|
140
140
|
message: e.to_string(),
|
|
141
141
|
})?
|
|
142
142
|
};
|
|
143
|
-
let llvm_features =
|
|
144
|
-
|
|
143
|
+
let llvm_features = tishlang_compile::extract_native_import_features(&program);
|
|
144
|
+
tishlang_llvm::compile_chunk_to_native(&chunk, output_path, &llvm_features)
|
|
145
145
|
.map_err(|e| NativeError { message: e.message })
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
-
/// Compile a single Program (e.g. from
|
|
150
|
+
/// Compile a single Program (e.g. from tishlang_js_to_tish) to native.
|
|
151
151
|
pub fn compile_program_to_native(
|
|
152
152
|
program: &Program,
|
|
153
153
|
project_root: Option<&Path>,
|
|
@@ -172,17 +172,17 @@ pub fn compile_program_to_native(
|
|
|
172
172
|
|
|
173
173
|
match backend {
|
|
174
174
|
Backend::Rust => {
|
|
175
|
-
let program = if optimize {
|
|
175
|
+
let program = if optimize { tishlang_opt::optimize(program) } else { program.clone() };
|
|
176
176
|
let root = project_root.unwrap_or_else(|| Path::new("."));
|
|
177
|
-
let native_modules =
|
|
177
|
+
let native_modules = tishlang_compile::resolve_native_modules(&program, root)
|
|
178
178
|
.map_err(|e| NativeError { message: e })?;
|
|
179
179
|
let mut all_features = features.to_vec();
|
|
180
|
-
for f in
|
|
180
|
+
for f in tishlang_compile::extract_native_import_features(&program) {
|
|
181
181
|
if !all_features.contains(&f) {
|
|
182
182
|
all_features.push(f);
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
|
-
let rust_code =
|
|
185
|
+
let rust_code = tishlang_compile::compile_with_native_modules(
|
|
186
186
|
&program,
|
|
187
187
|
project_root,
|
|
188
188
|
&all_features,
|
|
@@ -196,35 +196,35 @@ pub fn compile_program_to_native(
|
|
|
196
196
|
.map_err(|e| NativeError { message: e })
|
|
197
197
|
}
|
|
198
198
|
Backend::Cranelift => {
|
|
199
|
-
if
|
|
199
|
+
if tishlang_compile::has_external_native_imports(program) {
|
|
200
200
|
return Err(NativeError {
|
|
201
201
|
message: "Cranelift backend does not support external native imports. Built-in tish:fs, tish:http, tish:process are supported.".to_string(),
|
|
202
202
|
});
|
|
203
203
|
}
|
|
204
|
-
let program = if optimize {
|
|
204
|
+
let program = if optimize { tishlang_opt::optimize(program) } else { program.clone() };
|
|
205
205
|
let chunk = if optimize {
|
|
206
|
-
|
|
206
|
+
tishlang_bytecode::compile(&program).map_err(|e| NativeError { message: e.to_string() })?
|
|
207
207
|
} else {
|
|
208
|
-
|
|
208
|
+
tishlang_bytecode::compile_unoptimized(&program).map_err(|e| NativeError { message: e.to_string() })?
|
|
209
209
|
};
|
|
210
|
-
let cranelift_features =
|
|
211
|
-
|
|
210
|
+
let cranelift_features = tishlang_compile::extract_native_import_features(&program);
|
|
211
|
+
tishlang_cranelift::compile_chunk_to_native(&chunk, output_path, &cranelift_features)
|
|
212
212
|
.map_err(|e| NativeError { message: e.to_string() })
|
|
213
213
|
}
|
|
214
214
|
Backend::Llvm => {
|
|
215
|
-
if
|
|
215
|
+
if tishlang_compile::has_external_native_imports(program) {
|
|
216
216
|
return Err(NativeError {
|
|
217
217
|
message: "LLVM backend does not support external native imports.".to_string(),
|
|
218
218
|
});
|
|
219
219
|
}
|
|
220
|
-
let program = if optimize {
|
|
220
|
+
let program = if optimize { tishlang_opt::optimize(program) } else { program.clone() };
|
|
221
221
|
let chunk = if optimize {
|
|
222
|
-
|
|
222
|
+
tishlang_bytecode::compile(&program).map_err(|e| NativeError { message: e.to_string() })?
|
|
223
223
|
} else {
|
|
224
|
-
|
|
224
|
+
tishlang_bytecode::compile_unoptimized(&program).map_err(|e| NativeError { message: e.to_string() })?
|
|
225
225
|
};
|
|
226
|
-
let llvm_features =
|
|
227
|
-
|
|
226
|
+
let llvm_features = tishlang_compile::extract_native_import_features(&program);
|
|
227
|
+
tishlang_llvm::compile_chunk_to_native(&chunk, output_path, &llvm_features)
|
|
228
228
|
.map_err(|e| NativeError { message: e.message })
|
|
229
229
|
}
|
|
230
230
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
[package]
|
|
2
|
-
name = "
|
|
2
|
+
name = "tishlang_opt"
|
|
3
3
|
version = "0.1.0"
|
|
4
4
|
edition = "2021"
|
|
5
5
|
description = "AST optimization pass for Tish (constant folding, short-circuit, etc.)"
|
|
6
6
|
|
|
7
|
+
license-file = { workspace = true }
|
|
8
|
+
repository = { workspace = true }
|
|
7
9
|
[dependencies]
|
|
8
|
-
|
|
10
|
+
tishlang_ast = { path = "../tish_ast" }
|
|
9
11
|
|
|
10
12
|
[dev-dependencies]
|
|
11
|
-
|
|
13
|
+
tishlang_parser = { path = "../tish_parser" }
|