From d7b3c0d43068c919d1af7a196d86cd81ac4ae831 Mon Sep 17 00:00:00 2001 From: TudbuT Date: Fri, 4 Aug 2023 23:40:02 +0200 Subject: [PATCH] allow calling SPL from rust --- Cargo.toml | 2 +- rust-test.spl | 7 ++++++- src/oxidizer/splrs.rs | 3 +++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5e48b28..ad9906a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "spl" -version = "0.1.6" +version = "0.1.7" edition = "2021" description = "Stack Pogramming Language: A simple, concise scripting language." license = "MIT" diff --git a/rust-test.spl b/rust-test.spl index 820b8be..8252eab 100644 --- a/rust-test.spl +++ b/rust-test.spl @@ -2,9 +2,14 @@ func main { | 1 rusty-test _str println 0 } +func sply-test { mega | + 1 +} func rusty-test @rust !{ println!("hii"); let v = #pop:Mega#; - #push(v + 1)#; + #call(sply-test)# + let v2 = #pop:Mega#; + #push(v + v2)# } diff --git a/src/oxidizer/splrs.rs b/src/oxidizer/splrs.rs index 0950212..dce495f 100644 --- a/src/oxidizer/splrs.rs +++ b/src/oxidizer/splrs.rs @@ -22,6 +22,9 @@ fn parse_hash_expr(s: String, name: &str) -> String { if let Some(s) = readf1("push({})", &s) { return format!("stack.push(({s}).spl());"); } + if let Some(s) = readf1("call({})", &s) { + return format!("stack.call(&stack.get_func({s:?}.to_owned())?)?;"); + } panic!("invalid #-expr - this error will be handled in the future") }