pick smore glyphs
bendn 2024-01-30
parent 86e9933 · commit c539116
-rw-r--r--Cargo.lock17
-rw-r--r--Cargo.toml2
-rw-r--r--src/array.rs17
-rw-r--r--src/lexer.rs26
-rw-r--r--src/main.rs2
-rw-r--r--stackd21
6 files changed, 70 insertions, 15 deletions
diff --git a/Cargo.lock b/Cargo.lock
index b7b788f..f21b5a7 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -61,8 +61,10 @@ dependencies = [
name = "kale"
version = "0.1.0"
dependencies = [
+ "beef",
"chumsky",
"logos",
+ "tinyvec",
]
[[package]]
@@ -139,6 +141,21 @@ dependencies = [
]
[[package]]
+name = "tinyvec"
+version = "1.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50"
+dependencies = [
+ "tinyvec_macros",
+]
+
+[[package]]
+name = "tinyvec_macros"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
+
+[[package]]
name = "unicode-ident"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index eb1c8c7..749a5cb 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -6,5 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
+beef = "0.5.2"
chumsky = { git = "https://github.com/zesterer/chumsky", version = "1.0.0-alpha.6", default-features = false, features = ["label", "nightly"] }
logos = "0.13.0"
+tinyvec = { version = "1.6.0", features = ["alloc"] }
diff --git a/src/array.rs b/src/array.rs
new file mode 100644
index 0000000..6297f6f
--- /dev/null
+++ b/src/array.rs
@@ -0,0 +1,17 @@
+use std::any::Any;
+use tinyvec::TinyVec;
+struct Array {
+ shape: Shape,
+ data: Vec<Box<dyn Any>>,
+}
+struct Shape {
+ dims: TinyVec<[usize; 3]>,
+}
+
+impl Shape {
+ pub fn scalar() -> Self {
+ Shape {
+ dims: TinyVec::new(),
+ }
+ }
+}
diff --git a/src/lexer.rs b/src/lexer.rs
index 3345887..faacab6 100644
--- a/src/lexer.rs
+++ b/src/lexer.rs
@@ -6,6 +6,7 @@ macro_rules! tokens {
($($z:literal $( | $y:literal)? => $v:ident,)+) => {
#[derive(Logos, Debug, PartialEq, Clone)]
#[logos(skip r"[\n\s]+")]
+ #[allow(dead_code)]
pub enum Token<'strings> {
#[regex("/[^\n/]+/", priority = 8)]
Comment(&'strings str),
@@ -38,11 +39,12 @@ macro_rules! tokens {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
match self {
$(Self::$v => write!(f, $z),)+
- Self::FnIdent(s) | Self::Ident(s) | Self::Comment(s) => write!(f, "{s}"),
Self::String(s) => write!(f, "{s}"),
Self::Float(n) => write!(f, "{n}"),
Self::Int(n) => write!(f, "{n}"),
Self::OpeningBracket(x) | Self::ClosingBracket(x) => write!(f,"{x}"),
+ Self::Comment(_) => write!(f, ""),
+ Self::Ident(x) => write!(f, "{x}"),
}
}
}
@@ -54,8 +56,11 @@ tokens! {
"←" => Place,
"→" => Ret,
"=" => Eq,
- "." => Dup,
- ":" => Flip,
+ "🐢" => Dup,
+ "🐘" => Both,
+ "🍴" => Fork,
+ "🐈" => Flip,
+ "↖" => Reverse,
"⤵️" => Pop,
"+" => Add,
"×" => Mul,
@@ -66,16 +71,21 @@ tokens! {
"≤" | "≯" => Le,
">" => Gt,
"≥" | "≮" => Ge,
- "«" => Shl,
- "»" => Shr,
+ "⏪" => Shl,
+ "⏩" => Shr,
"¯" => Neg,
- "&" => And,
- "|" => Or,
- "^" => Xor,
+ "∧" => And,
+ "∨" => Or,
+ "⊻" => Xor,
"÷" => Div,
"%" => Mod,
"🔎" => Keep,
"🚧" => Split,
+ "⬅" => First,
+ "➡" => Last,
+ "⏭️" => Each,
+ "➡️" => Reduce,
+ "↘️" => ReduceStack,
}
diff --git a/src/main.rs b/src/main.rs
index e7a11a9..77ae04f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,3 +1,5 @@
+mod array;
+mod lexer;
fn main() {
println!("Hello, world!");
}
diff --git a/stackd b/stackd
index ba2d864..8c48039 100644
--- a/stackd
+++ b/stackd
@@ -1,8 +1,15 @@
-push "1abc25hriwm4"
-
-line ← λ { str -> int } (
- 48>🔎57<🔎
- 57 -
- first 10 * swap last +
- dup call swap call
+"1abc25hriwm4"
+// { str → int }
+line ← λ (
+ '0'>🔎'9'<🔎
+ '9'-
+ // modifiers are placed in front
+ 🐘⬅➡
+ 10×+
)
+
+🐢≠'\n'🚧
+// run function on all values, pushing to the stack
+⏭️line
+// reduce the stack
+↘️+ \ No newline at end of file