diff --git a/README.md b/README.md index 5d56fe0..ed0942a 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # puyo 3 (this time it's nameful) ## semantics -single-threaded, dynamically-typed (because lol), multiple named returns by default +single-threaded, dynamically-typed (because lol), multiple named returns by default, pass-by-value functions take and return a map ALWAYS diff --git a/src/ast.rs b/src/ast.rs new file mode 100644 index 0000000..173d0f2 --- /dev/null +++ b/src/ast.rs @@ -0,0 +1,29 @@ +use crate::{map::Map, symbol::Symbol, val::Val}; + +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub enum Ident { + /// `x` + Local(Symbol), + /// `^x` + Return(Symbol), +} + +#[derive(Debug, Clone)] +pub enum Ast { + /// `x`, `^x` + Var(Ident), + /// `x = y; => y` + Set(Ident, Box), + /// fn ([a b] [c d]) ( ... ) + Fn { + inputs: Vec, + outputs: Vec, + body: Vec, + }, + /// `{x, y: z}` + Map(Map), + /// `f x` + App(Box, Box), + /// `x + y` (only builtins, sorry) + BinOp(Box, fn(Val, Val) -> Val, Box), +} diff --git a/src/main.rs b/src/main.rs index e7a11a9..eff9d54 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,9 @@ +mod ast; +mod map; +mod parser; +mod symbol; +mod val; + fn main() { println!("Hello, world!"); } diff --git a/src/map.rs b/src/map.rs new file mode 100644 index 0000000..826a9dd --- /dev/null +++ b/src/map.rs @@ -0,0 +1,5 @@ +use std::collections::HashMap; + +use crate::symbol::Symbol; + +pub type Map = HashMap; diff --git a/src/parser.rs b/src/parser.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/symbol.rs b/src/symbol.rs new file mode 100644 index 0000000..33e0bd4 --- /dev/null +++ b/src/symbol.rs @@ -0,0 +1,2 @@ +// TODO: intern lol +pub type Symbol = String; diff --git a/src/val.rs b/src/val.rs new file mode 100644 index 0000000..c478b95 --- /dev/null +++ b/src/val.rs @@ -0,0 +1,25 @@ +use std::fmt; + +use crate::{map::Map, symbol::Symbol}; + +pub enum Val { + Number(f64), + Function { + inputs: Vec, + outputs: Vec, + run: Box) -> Val>, + }, + Map(Map), +} + +impl fmt::Debug for Val { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::Number(n) => write!(f, "{n:?}"), + Self::Function { + inputs, outputs, .. + } => write!(f, "fn([{}], [{}]", inputs.join(" "), outputs.join(" ")), + Self::Map(map) => write!(f, "{map:?}"), + } + } +}