diff --git a/Cargo.lock b/Cargo.lock index ec5d268..ebd2a91 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -22,7 +22,7 @@ checksum = "b03f7fbd470aa8b3ad163c85cce8bccfc11cc9c44ef12da0a4eddd98bd307352" [[package]] name = "spl" -version = "0.1.4" +version = "0.1.5" dependencies = [ "multicall", "once_cell", diff --git a/Cargo.toml b/Cargo.toml index 24ededc..abc24ab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "spl" -version = "0.1.4" +version = "0.1.5" edition = "2021" description = "Stack Pogramming Language: A simple, concise scripting language." license = "MIT" diff --git a/README.md b/README.md index 30aa1db..494b8ae 100644 --- a/README.md +++ b/README.md @@ -230,3 +230,35 @@ func main { mega | with args ; as opposed to the main object stack. More of this tutorial to follow. + +## Embedding rust into SPL + +Because SPL does not nearly have a complete standard library, embedding rust is required for many tasks. +This can be done as follows + +``` +> cat rust-test.spl +func main { | + 1 rusty-test _str println + 0 +} +func rusty-test @rust !{ + println!("hii"); + let v = #pop:Mega#; + #push(v + 1)#; +} +> spl --build rust-test.spl demo +---snip--- +> ./spl-demo/target/release/spl-demo rust-test.spl +hii +2 +``` + +As you can see, it's relatively straight-forward to do; but there are some major limitations right now: + +- It's a new binary, and can't be linked into the currently running program +- No crates can be added automatically at the moment + +The second one is easy to fix, but I intend to fix the first one first. Sadly, fixing it requires +compiling the code as a dynamic library and also getting it to work with the program its running in. +If anyone knows how to do this properly, I'd REALLY appreciate a PR or issue explaining it. \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 2674e2a..ad9ed51 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,6 +12,9 @@ fn main() { let data = fs::read_to_string(file.clone()).expect("unable to read specified file"); println!("Building SPL with specified natives file..."); let mut builder = RustAppBuilder::new(); + if let Some(name) = args.next() { + builder.set_name(name); + } println!("Embedding source..."); builder.add_source(file, data.to_owned()); println!("Preparing rust code..."); diff --git a/src/oxidizer/splrs.rs b/src/oxidizer/splrs.rs index 25b45a2..0950212 100644 --- a/src/oxidizer/splrs.rs +++ b/src/oxidizer/splrs.rs @@ -20,7 +20,7 @@ fn parse_hash_expr(s: String, name: &str) -> String { return format!("{{ require_on_stack!(tmp, {s}, stack, {name:?}); tmp }}"); } if let Some(s) = readf1("push({})", &s) { - return format!("stack.push(({s}).spl())"); + return format!("stack.push(({s}).spl());"); } panic!("invalid #-expr - this error will be handled in the future") }