diff --git a/src/ast.rs b/src/ast.rs index 991c668..8b20c69 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -1,8 +1,8 @@ -use crate::types::{Expression, List, Number}; +use crate::types::{Expression, List, Number, Symbol}; #[derive(Debug, Eq, PartialEq, Clone)] pub enum Expr { - Symbol(String), + Sym(Symbol), Str(String), Num(Number), Comment, @@ -18,7 +18,7 @@ impl Expr { } pub fn make_symbol(v: String) -> Expr { - Expr::Symbol(v) + Expr::Sym(Symbol::new(v)) } pub fn make_string(v: String) -> Expr { diff --git a/src/compiler.rs b/src/compiler.rs index 0feb31f..f38eb2a 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -3,7 +3,7 @@ use inkwell::context::Context; use inkwell::module::Module; use inkwell::values::{BasicValue, BasicValueEnum, FloatValue, FunctionValue, PointerValue}; -use crate::expr::Expression; +use crate::types::Expression; use std::collections::HashMap; pub struct Compiler<'a, 'ctx> { diff --git a/src/reader.rs b/src/reader.rs index a917ca9..d1e6445 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -1,4 +1,5 @@ -use crate::ast::{Expr, Number}; +use crate::ast::Expr; +use crate::types::Number; use std::io::{BufReader, Read}; pub type ReadResult = Result; @@ -249,6 +250,9 @@ impl ExprReader { None => break, } } + + // TODO: Move this to ast module and use the `new` function on + // Number struct if is_double { Ok(Expr::make_number(Number::Float( string.parse::().unwrap(), diff --git a/src/types.rs b/src/types.rs index f9670d3..173f3da 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,7 +1,9 @@ pub mod core; pub mod list; pub mod number; +pub mod symbol; pub use self::core::Expression; pub use self::list::List; pub use self::number::Number; +pub use self::symbol::Symbol; diff --git a/src/types/number.rs b/src/types/number.rs index 3e69351..bd02496 100644 --- a/src/types/number.rs +++ b/src/types/number.rs @@ -14,6 +14,7 @@ pub enum Number { impl PartialEq for Number { fn eq(&self, other: &Self) -> bool { + // TODO: Eval other let comb = (&self, &other); match comb { diff --git a/src/types/symbol.rs b/src/types/symbol.rs new file mode 100644 index 0000000..2b170a1 --- /dev/null +++ b/src/types/symbol.rs @@ -0,0 +1,25 @@ +use crate::types::Expression; + +#[derive(Debug, Clone)] +pub struct Symbol { + name: String, +} + +impl PartialEq for Symbol { + fn eq(&self, other: &Self) -> bool { + self.name == other.name + } +} + +impl Eq for Symbol {} + +impl Expression for Symbol { + fn eval() {} + fn code_gen() {} +} + +impl Symbol { + pub fn new(name: String) -> Self { + Symbol { name } + } +}