diff --git a/Cargo.lock b/Cargo.lock index 150e4f6..58f57e3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -38,6 +38,12 @@ version = "1.0.54" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7bbb73db36c1246e9034e307d0fba23f9a2e251faa47ade70c1bd252220c8311" +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + [[package]] name = "clap" version = "3.0.0-beta.1" @@ -71,6 +77,21 @@ dependencies = [ "syn", ] +[[package]] +name = "cloudabi" +version = "0.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "either" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" + [[package]] name = "heck" version = "0.3.1" @@ -98,6 +119,30 @@ dependencies = [ "autocfg", ] +[[package]] +name = "inkwell" +version = "0.1.0" +source = "git+https://github.com/TheDan64/inkwell?branch=llvm10-0#84b9666c72ae9f286bfee559d13ac71ec8d1fce9" +dependencies = [ + "either", + "inkwell_internals", + "libc", + "llvm-sys", + "once_cell", + "parking_lot", + "regex", +] + +[[package]] +name = "inkwell_internals" +version = "0.2.0" +source = "git+https://github.com/TheDan64/inkwell?branch=llvm10-0#84b9666c72ae9f286bfee559d13ac71ec8d1fce9" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -129,18 +174,57 @@ dependencies = [ "semver", ] +[[package]] +name = "lock_api" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4da24a77a3d8a6d4862d95f72e6fdb9c09a643ecdb402d754004a557f2bec75" +dependencies = [ + "scopeguard", +] + [[package]] name = "memchr" version = "2.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" +[[package]] +name = "once_cell" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d" + [[package]] name = "os_str_bytes" version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06de47b848347d8c4c94219ad8ecd35eb90231704b067e67e6ae2e36ee023510" +[[package]] +name = "parking_lot" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3a704eb390aafdc107b0e392f56a82b668e3a71366993b5340f5833fd62505e" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d58c7c768d4ba344e3e8d72518ac13e259d7c7ade24167003b8488e10b6740a3" +dependencies = [ + "cfg-if", + "cloudabi", + "libc", + "redox_syscall", + "smallvec", + "winapi", +] + [[package]] name = "proc-macro-error" version = "0.4.12" @@ -185,6 +269,12 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "redox_syscall" +version = "0.1.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" + [[package]] name = "regex" version = "1.3.9" @@ -203,6 +293,12 @@ version = "0.6.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8" +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + [[package]] name = "semver" version = "0.9.0" @@ -223,9 +319,15 @@ name = "serene" version = "0.1.0" dependencies = [ "clap", - "llvm-sys", + "inkwell", ] +[[package]] +name = "smallvec" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7cb5678e1615754284ec264d9bb5b4c27d2018577fd90ac0ceb578591ed5ee4" + [[package]] name = "strsim" version = "0.10.0" diff --git a/Cargo.toml b/Cargo.toml index e4846e4..7009113 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,5 +7,5 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -llvm-sys = "100" -clap = { version = "3.0.0-beta.1", features = ["yaml"] } \ No newline at end of file +clap = { version = "3.0.0-beta.1", features = ["yaml"] } +inkwell = { git = "https://github.com/TheDan64/inkwell", branch = "llvm10-0" } \ No newline at end of file diff --git a/src/ast.rs b/src/ast.rs index fc43833..991c668 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -1,50 +1,20 @@ -use crate::collections::list; -use crate::expr::Expression; - -// Note: I kept the number implementation simple for now -// but we need to decide on our approach to numbers, are -// we going to only support the 64bit variants? or should -// try to be smart and support 32 and 64 and switch between -// them ? -// What about usize and isize ? -#[derive(Debug, Clone)] -pub enum Number { - Integer(i64), - Float(f64), -} - -impl PartialEq for Number { - fn eq(&self, other: &Self) -> bool { - let comb = (&self, &other); - - match comb { - (Number::Integer(x), Number::Integer(y)) => *x == *y, - (Number::Float(x), Number::Float(y)) => *x == *y, - (Number::Integer(x), Number::Float(y)) => *x as f64 == *y, - (Number::Float(x), Number::Integer(y)) => *x == *y as f64, - } - } -} - -impl Eq for Number {} +use crate::types::{Expression, List, Number}; #[derive(Debug, Eq, PartialEq, Clone)] pub enum Expr { - //List(list::List), Symbol(String), Str(String), Num(Number), Comment, Error(String), - // Cons(Box, Box), - Cons(list::List), + Cons(List), Nil, NoMatch, } impl Expr { pub fn make_list(first: Expr, rest: Expr) -> Expr { - Expr::Cons(list::List::::new(Box::new(first), Box::new(rest))) + Expr::Cons(List::::new(Box::new(first), Box::new(rest))) } pub fn make_symbol(v: String) -> Expr { diff --git a/src/collections.rs b/src/collections.rs deleted file mode 100644 index d17e233..0000000 --- a/src/collections.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod list; diff --git a/src/compiler.rs b/src/compiler.rs new file mode 100644 index 0000000..0feb31f --- /dev/null +++ b/src/compiler.rs @@ -0,0 +1,18 @@ +use inkwell::builder::Builder; +use inkwell::context::Context; +use inkwell::module::Module; +use inkwell::values::{BasicValue, BasicValueEnum, FloatValue, FunctionValue, PointerValue}; + +use crate::expr::Expression; +use std::collections::HashMap; + +pub struct Compiler<'a, 'ctx> { + context: &'ctx Context, + builder: &'a Builder<'ctx>, + module: &'a Module<'ctx>, + scope: HashMap>, +} + +impl<'a, 'ctx> Compiler<'a, 'ctx> { + pub fn compile(exprs: &impl Expression) {} +} diff --git a/src/core.rs b/src/core.rs deleted file mode 100644 index 6f72261..0000000 --- a/src/core.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub trait Expression { - fn gen_code(&self); -} diff --git a/src/main.rs b/src/main.rs index 768b529..ea31790 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -extern crate llvm_sys; +extern crate inkwell; use clap::{load_yaml, App}; use std::fs::File; @@ -7,9 +7,9 @@ use std::io::prelude::*; use std::string::String; pub mod ast; -pub mod collections; -pub mod expr; +pub mod compiler; pub mod reader; +pub mod types; fn main() -> io::Result<()> { let yaml = load_yaml!("cli.yml"); diff --git a/src/types.rs b/src/types.rs new file mode 100644 index 0000000..f9670d3 --- /dev/null +++ b/src/types.rs @@ -0,0 +1,7 @@ +pub mod core; +pub mod list; +pub mod number; + +pub use self::core::Expression; +pub use self::list::List; +pub use self::number::Number; diff --git a/src/expr.rs b/src/types/core.rs similarity index 100% rename from src/expr.rs rename to src/types/core.rs diff --git a/src/collections/list.rs b/src/types/list.rs similarity index 90% rename from src/collections/list.rs rename to src/types/list.rs index 07b438f..c485e6e 100644 --- a/src/collections/list.rs +++ b/src/types/list.rs @@ -1,4 +1,4 @@ -use crate::expr::Expression; +use crate::types::core::Expression; #[derive(Debug, Eq, PartialEq, Clone)] pub struct List { diff --git a/src/types/number.rs b/src/types/number.rs new file mode 100644 index 0000000..3e69351 --- /dev/null +++ b/src/types/number.rs @@ -0,0 +1,33 @@ +use crate::types::Expression; + +// Note: I kept the number implementation simple for now +// but we need to decide on our approach to numbers, are +// we going to only support the 64bit variants? or should +// try to be smart and support 32 and 64 and switch between +// them ? +// What about usize and isize ? +#[derive(Debug, Clone)] +pub enum Number { + Integer(i64), + Float(f64), +} + +impl PartialEq for Number { + fn eq(&self, other: &Self) -> bool { + let comb = (&self, &other); + + match comb { + (Number::Integer(x), Number::Integer(y)) => *x == *y, + (Number::Float(x), Number::Float(y)) => *x == *y, + (Number::Integer(x), Number::Float(y)) => *x as f64 == *y, + (Number::Float(x), Number::Integer(y)) => *x == *y as f64, + } + } +} + +impl Eq for Number {} + +impl Expression for Number { + fn eval() {} + fn code_gen() {} +}