basic scaffolding
This commit is contained in:
parent
8fa28c6ced
commit
c5ca55124e
7 changed files with 68 additions and 1 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
29
src/ast.rs
Normal file
29
src/ast.rs
Normal file
|
|
@ -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<Ast>),
|
||||
/// fn ([a b] [c d]) ( ... )
|
||||
Fn {
|
||||
inputs: Vec<Symbol>,
|
||||
outputs: Vec<Symbol>,
|
||||
body: Vec<Ast>,
|
||||
},
|
||||
/// `{x, y: z}`
|
||||
Map(Map<Ast>),
|
||||
/// `f x`
|
||||
App(Box<Ast>, Box<Ast>),
|
||||
/// `x + y` (only builtins, sorry)
|
||||
BinOp(Box<Ast>, fn(Val, Val) -> Val, Box<Ast>),
|
||||
}
|
||||
|
|
@ -1,3 +1,9 @@
|
|||
mod ast;
|
||||
mod map;
|
||||
mod parser;
|
||||
mod symbol;
|
||||
mod val;
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
|
|
|
|||
5
src/map.rs
Normal file
5
src/map.rs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use crate::symbol::Symbol;
|
||||
|
||||
pub type Map<V> = HashMap<Symbol, V>;
|
||||
0
src/parser.rs
Normal file
0
src/parser.rs
Normal file
2
src/symbol.rs
Normal file
2
src/symbol.rs
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
// TODO: intern lol
|
||||
pub type Symbol = String;
|
||||
25
src/val.rs
Normal file
25
src/val.rs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
use std::fmt;
|
||||
|
||||
use crate::{map::Map, symbol::Symbol};
|
||||
|
||||
pub enum Val {
|
||||
Number(f64),
|
||||
Function {
|
||||
inputs: Vec<Symbol>,
|
||||
outputs: Vec<Symbol>,
|
||||
run: Box<dyn FnMut(Map<Val>) -> Val>,
|
||||
},
|
||||
Map(Map<Val>),
|
||||
}
|
||||
|
||||
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:?}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue