QOL improvement to push #-expr

This commit is contained in:
Daniella 2023-08-04 22:39:05 +02:00
parent 52d4964435
commit 18b8b89549
Signed by: TudbuT
GPG key ID: 7D63D5634B7C417F
5 changed files with 38 additions and 3 deletions

2
Cargo.lock generated
View file

@ -22,7 +22,7 @@ checksum = "b03f7fbd470aa8b3ad163c85cce8bccfc11cc9c44ef12da0a4eddd98bd307352"
[[package]] [[package]]
name = "spl" name = "spl"
version = "0.1.4" version = "0.1.5"
dependencies = [ dependencies = [
"multicall", "multicall",
"once_cell", "once_cell",

View file

@ -1,6 +1,6 @@
[package] [package]
name = "spl" name = "spl"
version = "0.1.4" version = "0.1.5"
edition = "2021" edition = "2021"
description = "Stack Pogramming Language: A simple, concise scripting language." description = "Stack Pogramming Language: A simple, concise scripting language."
license = "MIT" license = "MIT"

View file

@ -230,3 +230,35 @@ func main { mega | with args ;
as opposed to the main object stack. as opposed to the main object stack.
More of this tutorial to follow. 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.

View file

@ -12,6 +12,9 @@ fn main() {
let data = fs::read_to_string(file.clone()).expect("unable to read specified file"); let data = fs::read_to_string(file.clone()).expect("unable to read specified file");
println!("Building SPL with specified natives file..."); println!("Building SPL with specified natives file...");
let mut builder = RustAppBuilder::new(); let mut builder = RustAppBuilder::new();
if let Some(name) = args.next() {
builder.set_name(name);
}
println!("Embedding source..."); println!("Embedding source...");
builder.add_source(file, data.to_owned()); builder.add_source(file, data.to_owned());
println!("Preparing rust code..."); println!("Preparing rust code...");

View file

@ -20,7 +20,7 @@ fn parse_hash_expr(s: String, name: &str) -> String {
return format!("{{ require_on_stack!(tmp, {s}, stack, {name:?}); tmp }}"); return format!("{{ require_on_stack!(tmp, {s}, stack, {name:?}); tmp }}");
} }
if let Some(s) = readf1("push({})", &s) { 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") panic!("invalid #-expr - this error will be handled in the future")
} }