Add Symbol struct to represent symbols
This commit is contained in:
parent
3454a44f65
commit
08a651019f
|
@ -1,8 +1,8 @@
|
||||||
use crate::types::{Expression, List, Number};
|
use crate::types::{Expression, List, Number, Symbol};
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
#[derive(Debug, Eq, PartialEq, Clone)]
|
||||||
pub enum Expr {
|
pub enum Expr {
|
||||||
Symbol(String),
|
Sym(Symbol),
|
||||||
Str(String),
|
Str(String),
|
||||||
Num(Number),
|
Num(Number),
|
||||||
Comment,
|
Comment,
|
||||||
|
@ -18,7 +18,7 @@ impl Expr {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn make_symbol(v: String) -> Expr {
|
pub fn make_symbol(v: String) -> Expr {
|
||||||
Expr::Symbol(v)
|
Expr::Sym(Symbol::new(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn make_string(v: String) -> Expr {
|
pub fn make_string(v: String) -> Expr {
|
||||||
|
|
|
@ -3,7 +3,7 @@ use inkwell::context::Context;
|
||||||
use inkwell::module::Module;
|
use inkwell::module::Module;
|
||||||
use inkwell::values::{BasicValue, BasicValueEnum, FloatValue, FunctionValue, PointerValue};
|
use inkwell::values::{BasicValue, BasicValueEnum, FloatValue, FunctionValue, PointerValue};
|
||||||
|
|
||||||
use crate::expr::Expression;
|
use crate::types::Expression;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
pub struct Compiler<'a, 'ctx> {
|
pub struct Compiler<'a, 'ctx> {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use crate::ast::{Expr, Number};
|
use crate::ast::Expr;
|
||||||
|
use crate::types::Number;
|
||||||
use std::io::{BufReader, Read};
|
use std::io::{BufReader, Read};
|
||||||
|
|
||||||
pub type ReadResult = Result<Expr, String>;
|
pub type ReadResult = Result<Expr, String>;
|
||||||
|
@ -249,6 +250,9 @@ impl ExprReader {
|
||||||
None => break,
|
None => break,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Move this to ast module and use the `new` function on
|
||||||
|
// Number struct
|
||||||
if is_double {
|
if is_double {
|
||||||
Ok(Expr::make_number(Number::Float(
|
Ok(Expr::make_number(Number::Float(
|
||||||
string.parse::<f64>().unwrap(),
|
string.parse::<f64>().unwrap(),
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
pub mod core;
|
pub mod core;
|
||||||
pub mod list;
|
pub mod list;
|
||||||
pub mod number;
|
pub mod number;
|
||||||
|
pub mod symbol;
|
||||||
|
|
||||||
pub use self::core::Expression;
|
pub use self::core::Expression;
|
||||||
pub use self::list::List;
|
pub use self::list::List;
|
||||||
pub use self::number::Number;
|
pub use self::number::Number;
|
||||||
|
pub use self::symbol::Symbol;
|
||||||
|
|
|
@ -14,6 +14,7 @@ pub enum Number {
|
||||||
|
|
||||||
impl PartialEq for Number {
|
impl PartialEq for Number {
|
||||||
fn eq(&self, other: &Self) -> bool {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
|
// TODO: Eval other
|
||||||
let comb = (&self, &other);
|
let comb = (&self, &other);
|
||||||
|
|
||||||
match comb {
|
match comb {
|
||||||
|
|
|
@ -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 }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue