-rw-r--r--.gitignore1
-rw-r--r--Cargo.toml22
-rw-r--r--LICENSE21
-rw-r--r--README.md3
-rw-r--r--src/lib.rs7
-rw-r--r--src/run.rs35
6 files changed, 89 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ffa3bbd
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+Cargo.lock \ No newline at end of file
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644
index 0000000..52122a1
--- /dev/null
+++ b/Cargo.toml
@@ -0,0 +1,22 @@
+[package]
+name = "muiua"
+version = "0.1.0"
+edition = "2024"
+authors = ["bend-n <[email protected]>"]
+license = "MIT"
+description = "inline uiua"
+
+[dependencies]
+proc-macro2 = "1.0.101"
+quote = "1.0.40"
+uiua = { default-features = false, features = [
+ "native_sys",
+], git = "https://github.com/uiua-lang/uiua" }
+
+[lib]
+proc-macro = true
+
+
+# [profile.dev.package.uiua]
+# opt-level = 3
+# debug-assertions = false
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..bf3f588
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2025 bendn
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..e0cbc12
--- /dev/null
+++ b/README.md
@@ -0,0 +1,3 @@
+# `muiua`
+
+inline uiua
diff --git a/src/lib.rs b/src/lib.rs
new file mode 100644
index 0000000..7e147b0
--- /dev/null
+++ b/src/lib.rs
@@ -0,0 +1,7 @@
+mod run;
+use proc_macro::TokenStream;
+
+#[proc_macro]
+pub fn i(i: TokenStream) -> TokenStream {
+ run::exec(&i.to_string()).into()
+}
diff --git a/src/run.rs b/src/run.rs
new file mode 100644
index 0000000..2b084d6
--- /dev/null
+++ b/src/run.rs
@@ -0,0 +1,35 @@
+use proc_macro::TokenStream;
+use quote::quote;
+use uiua::SafeSys;
+use uiua::Uiua;
+
+pub fn exec(x: &str) -> TokenStream {
+ let mut weewa = Uiua::with_safe_sys().with_recursion_limit(100);
+ let x = x.trim_start_matches('r').trim_matches('#');
+ let x = x.strip_prefix('"').unwrap_or(x);
+ let x = x.strip_suffix('"').unwrap_or(x);
+ match weewa.run_str(x) {
+ Err(e) => {
+ weewa.print_reports();
+ let e = e.to_string();
+ quote! { compile_error!(#e) }.into()
+ }
+ Ok(_) => {
+ match weewa
+ .stack()
+ .get(0)
+ .map(|x| x.to_string())
+ .unwrap_or_else(|| {
+ String::from_utf8_lossy(
+ &weewa.downcast_backend::<SafeSys>().unwrap().take_stdout(),
+ )
+ .into_owned()
+ })
+ .parse::<TokenStream>()
+ {
+ Ok(x) => x,
+ Err(_) => quote! { compile_error!("lexer error") }.into(),
+ }
+ }
+ }
+}