Initial commit

* Parser, compiler, objects, and VM base implementations
* Stuff will print out, functions called, etc
* There are probably plenty of bugs but this is a good starting point to
  start committing changes into git

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2023-04-01 22:34:35 -07:00
commit bfe7ca33bd
26 changed files with 13853 additions and 0 deletions

72
src/syn/ast.rs Normal file
View File

@@ -0,0 +1,72 @@
use crate::syn::Spanned;
#[derive(Debug, Clone)]
pub enum Stmt {
Assign(AssignLhs, Expr),
Expr(SpExpr),
If {
if_true: SpCondExpr,
elseif: Vec<SpCondExpr>,
else_expr: Option<SpExpr>,
},
Def {
name: String,
params: Vec<SpParam>,
body: Vec<SpStmt>,
},
Import {
target: String,
from: Option<String>,
},
}
#[derive(Debug, Clone)]
pub enum AssignLhs {
/// A simple assignment.
///
/// `x = foo`
Name(String),
/// A more complex assignment.
///
/// `x().bar = foo`
Complex(SpExpr, String),
}
pub type SpStmt = Spanned<Stmt>;
#[derive(Debug, Clone)]
pub struct CondExpr {
pub cond: SpExpr,
pub expr: SpExpr,
}
pub type SpCondExpr = Spanned<CondExpr>;
#[derive(Debug, Clone)]
pub struct Param {
pub name: String,
pub ty: Option<SpExpr>,
}
pub type SpParam = Spanned<Param>;
#[derive(Debug, Clone)]
pub enum Expr {
Call(Box<SpExpr>, Vec<SpExpr>),
Get(Box<SpExpr>, String),
Atom(SpAtom),
}
pub type SpExpr = Spanned<Expr>;
#[derive(Debug, Clone)]
pub enum Atom {
Int(i64),
Float(f64),
Str(String),
Sym(String),
Name(String),
}
pub type SpAtom = Spanned<Atom>;