Skip to content

Commit

Permalink
Merge pull request #6 from binary-banter/while
Browse files Browse the repository at this point in the history
While & mutation
  • Loading branch information
Vlamonster authored Oct 29, 2023
2 parents d03e43a + e3af184 commit d54e4ae
Show file tree
Hide file tree
Showing 78 changed files with 4,842 additions and 3,508 deletions.
22 changes: 22 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ members = [
default-members = [
"compiler"
]

[profile.release]
opt-level = 3
lto = true
2 changes: 1 addition & 1 deletion bencher/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use clap::Parser;
use compiler::elf::ElfFile;
use compiler::interpreter::x86var::IStats;
use compiler::interpreter::{TestIO, IO};
use compiler::passes::parse::parse_program;
use compiler::passes::parse::parse::parse_program;
use compiler::utils::split_test::split_test_raw;
use git2::{Commit, Repository};
use mongodb::bson;
Expand Down
6 changes: 4 additions & 2 deletions compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ itertools = "0.11.0"
serde = { version = "1.0.189", features = ["derive"] }
clap = { version = "4.4.6", features = ["derive"] }
miette = { version = "5.10.0", features = ["fancy"] }
zerocopy = {version = "0.7.11", features = ["derive"] }
lalrpop-util = { version = "0.20.1", features = ["lexer", "unicode"] }
zerocopy = { version = "0.7.11", features = ["derive"] }
lalrpop-util = { version = "0.20", features = ["lexer", "unicode"] }
derive_more = "0.99.17"
functor_derive = "0.2.2"

[dev-dependencies]
test_each_file = "0.1.0"
Expand Down
1 change: 0 additions & 1 deletion compiler/src/elf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use std::io::Write;
use std::mem::size_of;
use zerocopy::AsBytes;

#[allow(clippy::module_inception)]
mod header;
mod program;
mod section;
Expand Down
172 changes: 0 additions & 172 deletions compiler/src/interpreter/lvar.rs

This file was deleted.

4 changes: 1 addition & 3 deletions compiler/src/interpreter/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
pub mod cvar;
pub mod lvar;
pub mod value;
pub mod x86var;

use crate::language::lvar::Lit;
use crate::passes::parse::Lit;
use std::io::stdin;
use std::vec::IntoIter;

Expand Down
47 changes: 26 additions & 21 deletions compiler/src/interpreter/value.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
use crate::language::lvar::Lit;
use std::fmt::{Display, Formatter};
use crate::passes::parse::Lit;
use derive_more::Display;
use std::fmt::Display;
use std::hash::Hash;
use std::str::FromStr;

#[derive(Eq, PartialEq, Copy, Clone, Debug)]
pub enum Val<A: Copy + Hash + Eq> {
#[derive(Eq, PartialEq, Copy, Clone, Debug, Display)]
pub enum Val<A: Copy + Hash + Eq + Display> {
#[display(fmt = "{val}")]
Int { val: i64 },
#[display(fmt = "{}", r#"if *val { "true" } else { "false" }"#)]
Bool { val: bool },
#[display(fmt = "unit")]
Unit,
#[display(fmt = "fn pointer `{sym}`")]
Function { sym: A },
}

impl<A: Copy + Hash + Eq> Val<A> {
impl<A: Copy + Hash + Eq + Display> From<Lit> for Val<A> {
fn from(value: Lit) -> Self {
match value {
Lit::Int { val } => Val::Int { val },
Lit::Bool { val } => Val::Bool { val },
Lit::Unit => Val::Unit,
}
}
}

impl<A: Copy + Hash + Eq + Display> Val<A> {
pub fn int(self) -> i64 {
match self {
Val::Int { val } => val,
Val::Bool { .. } => panic!(),
Val::Function { .. } => panic!(),
Val::Unit => panic!(),
}
}

Expand All @@ -24,6 +41,7 @@ impl<A: Copy + Hash + Eq> Val<A> {
Val::Int { .. } => panic!(),
Val::Bool { val } => val,
Val::Function { .. } => panic!(),
Val::Unit => panic!(),
}
}

Expand All @@ -32,6 +50,7 @@ impl<A: Copy + Hash + Eq> Val<A> {
Val::Int { .. } => panic!(),
Val::Bool { .. } => panic!(),
Val::Function { sym } => sym,
Val::Unit => panic!(),
}
}
}
Expand All @@ -41,6 +60,7 @@ impl From<Lit> for i64 {
match value {
Lit::Int { val } => val,
Lit::Bool { val } => val as i64,
Lit::Unit => 0,
}
}
}
Expand All @@ -52,25 +72,10 @@ impl FromStr for Lit {
Ok(match s {
"false" => Lit::Bool { val: false },
"true" => Lit::Bool { val: true },
"unit" => Lit::Unit,
s => Lit::Int {
val: s.parse().map_err(|_| ())?,
},
})
}
}

impl<A: Copy + Hash + Eq + Display> Display for Val<A> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Val::Int { val } => write!(f, "{val}"),
Val::Bool { val } => {
if *val {
write!(f, "t")
} else {
write!(f, "f")
}
}
Val::Function { sym, .. } => write!(f, "pointer to `{sym}``"),
}
}
}
7 changes: 4 additions & 3 deletions compiler/src/interpreter/x86var.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use crate::interpreter::IO;
use crate::language::lvar::Lit;
use crate::language::x86var::{
Block, Cnd, Instr, Reg, VarArg, X86Concluded, X86Selected, CALLEE_SAVED, CALLER_SAVED,
};
use crate::passes::uniquify::UniqueSym;
use crate::passes::parse::Lit;
use crate::utils::gen_sym::UniqueSym;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::fmt::Debug;
use std::mem;
use zerocopy::AsBytes;

Expand Down Expand Up @@ -61,7 +62,7 @@ impl<'p> X86Concluded<'p> {
.blocks
.clone()
.into_iter()
.map(|(sym, block)| (sym, block.into()))
.map(|(sym, block)| (sym, block.fmap(Into::into)))
.collect(),
io,
regs,
Expand Down
Loading

0 comments on commit d54e4ae

Please sign in to comment.