From 7b3e0129f8ff0b4c22aac4bbddfc04145312f2b7 Mon Sep 17 00:00:00 2001 From: TudbuT Date: Fri, 6 Sep 2024 21:29:40 +0200 Subject: [PATCH] unbreak starting from embedded files --- Cargo.toml | 2 +- src/lib.rs | 11 +++++------ src/main.rs | 8 ++------ src/oxidizer/mod.rs | 8 ++++++-- std.spl | 3 ++- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cb3fc34..b13b477 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "spl" -version = "0.3.0" +version = "0.3.1" edition = "2021" description = "Stack Pogramming Language: A simple, concise scripting language." license = "MIT" diff --git a/src/lib.rs b/src/lib.rs index cd870b4..e0cdde5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -76,12 +76,11 @@ pub fn start_file_in_runtime(path: &str) -> Result { /// Include the standard library in a runtime-stack-pair, where the runtime has been .set(). pub fn add_std(stack: &mut Stack) -> OError { let f = find_in_splpath("std.spl"); - let words = f - .map_err(|x| stack.error(ErrorKind::LexError(format!("{x}")))) - .and_then(|f| { - lex(f.ends_with(".isbpl"), fs::read_to_string(f).unwrap()) - .map_err(|x| stack.error(ErrorKind::LexError(format!("{x:?}")))) - })?; + let words = match f { + Ok(f) => lex(f.ends_with(".isbpl"), fs::read_to_string(f).unwrap()), + Err(content) => lex(false, content), + } + .map_err(|x| stack.error(ErrorKind::LexError(format!("{x:?}"))))?; words.exec(stack) } diff --git a/src/main.rs b/src/main.rs index ae0e056..e7264a1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,15 +1,11 @@ -use spl::{ - find_in_splpath, lex, oxidizer::RustAppBuilder, start_file_in_runtime, Runtime, SetRuntime, -}; +use spl::{lex, oxidizer::RustAppBuilder, start_file_in_runtime, Runtime, SetRuntime}; use std::{env::args, fs}; fn main() { Runtime::new().set(); let mut args = args().skip(1); - let arg = &args - .next() - .unwrap_or_else(|| find_in_splpath("repl.spl").expect("no file to be run")); + let arg = &args.next().unwrap_or("#repl.spl".to_owned()); if arg == "--build" || arg == "--run" || arg == "--buildrun" { let file = args.next().unwrap(); let data = fs::read_to_string(file.clone()).expect("unable to read specified file"); diff --git a/src/oxidizer/mod.rs b/src/oxidizer/mod.rs index 567832a..1b03ac1 100644 --- a/src/oxidizer/mod.rs +++ b/src/oxidizer/mod.rs @@ -171,13 +171,17 @@ impl RustAppBuilder { if let Err(x) = start_file_in_runtime( &args() .nth(1) - .unwrap_or_else(|| find_in_splpath("default_file").expect("no file to be run")), + .unwrap_or("default_file".to_owned()), ) { println!("{x:?}"); } Runtime::reset(); } - }.to_owned().replace("default_file", &self.default_file).replace("runtime_init", &runtime_init) + &code, + } + .to_owned() + .replace("default_file", &self.default_file) + .replace("runtime_init", &runtime_init) + + &code, )?; Command::new("cargo") .arg("build") diff --git a/std.spl b/std.spl index 0dff490..73b3e6b 100644 --- a/std.spl +++ b/std.spl @@ -513,7 +513,8 @@ func _ { | func call-main-on-file { | with file ; catch { - "@" file concat import + "@" (0 (file _array):get 0 ("#" _array):get eq) if { pop "" } file concat + import update-types argv main exit } { with err ;