@tishlang/tish 2.1.0 → 2.2.3
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/bin/tish +0 -0
- package/crates/tish/Cargo.toml +1 -1
- package/crates/tish/src/main.rs +26 -8
- package/crates/tish/tests/fixtures/read_file_bytes.tish +10 -0
- package/crates/tish/tests/fs_read_file_bytes.rs +45 -0
- package/crates/tish_ast/src/ast.rs +5 -0
- package/crates/tish_compile/src/codegen.rs +23 -1
- package/crates/tish_eval/src/eval.rs +4 -0
- package/crates/tish_eval/src/natives.rs +16 -0
- package/crates/tish_fmt/src/lib.rs +156 -75
- package/crates/tish_lsp/src/import_goto.rs +25 -3
- package/crates/tish_lsp/src/main.rs +250 -5
- package/crates/tish_parser/src/parser.rs +20 -8
- package/crates/tish_resolve/src/lib.rs +775 -55
- package/crates/tish_runtime/src/lib.rs +17 -0
- package/crates/tish_vm/src/vm.rs +3 -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
|
@@ -666,6 +666,23 @@ pub fn read_file(args: &[Value]) -> Value {
|
|
|
666
666
|
}
|
|
667
667
|
}
|
|
668
668
|
|
|
669
|
+
/// Read a file as raw bytes — an array of numbers 0–255 — for binary data that `read_file`
|
|
670
|
+
/// (UTF-8 only) can't handle (images, fonts, archives). Lets pure-Tish decoders work on local
|
|
671
|
+
/// files. See issue #120.
|
|
672
|
+
#[cfg(feature = "fs")]
|
|
673
|
+
pub fn read_file_bytes(args: &[Value]) -> Value {
|
|
674
|
+
let path = args
|
|
675
|
+
.first()
|
|
676
|
+
.map(|v| v.to_display_string())
|
|
677
|
+
.unwrap_or_default();
|
|
678
|
+
match std::fs::read(&path) {
|
|
679
|
+
Ok(bytes) => Value::Array(VmRef::new(
|
|
680
|
+
bytes.into_iter().map(|b| Value::Number(b as f64)).collect(),
|
|
681
|
+
)),
|
|
682
|
+
Err(e) => make_error_value(e),
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
|
|
669
686
|
#[cfg(feature = "fs")]
|
|
670
687
|
pub fn write_file(args: &[Value]) -> Value {
|
|
671
688
|
let path = args
|
package/crates/tish_vm/src/vm.rs
CHANGED
|
@@ -169,6 +169,9 @@ fn get_builtin_export(enabled: &HashSet<String>, spec: &str, export_name: &str)
|
|
|
169
169
|
"mkdir" => Some(Value::native(|args: &[Value]| {
|
|
170
170
|
tishlang_runtime::mkdir(args)
|
|
171
171
|
})),
|
|
172
|
+
"readFileBytes" => Some(Value::native(|args: &[Value]| {
|
|
173
|
+
tishlang_runtime::read_file_bytes(args)
|
|
174
|
+
})),
|
|
172
175
|
_ => None,
|
|
173
176
|
};
|
|
174
177
|
}
|
package/package.json
CHANGED
|
Binary file
|
package/platform/darwin-x64/tish
CHANGED
|
Binary file
|
|
Binary file
|
package/platform/linux-x64/tish
CHANGED
|
Binary file
|
|
Binary file
|