Skip to content

Commit

Permalink
Merge pull request #7 from binary-banter/fixes
Browse files Browse the repository at this point in the history
Fixes
  • Loading branch information
JonathanBrouwer authored Oct 30, 2023
2 parents d54e4ae + 1293661 commit 755ded8
Show file tree
Hide file tree
Showing 57 changed files with 3,426 additions and 2,420 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,25 @@ Run with specified input path and specified output path:
```sh
cargo run -- input.jj -o output && ./output ; echo $?
```

# Fixes
* [ ] Updated README, with 3 new colors!
* [ ] Add documentation where necessary.
* [ ] Improve error handling for parsing pass.
* [ ] Improve error handling for type checking pass.
* [ ] Improve algorithm for colouring the interference graph.
* [ ] Add read and write functionality to the bencher to update locally.
* [x] Lots, and lots, of refactoring!

# Upcoming Language Features
* [ ] Implement comments in code.
* [ ] Algebraic Data Types (Enums and Structs).
* [ ] First-class functions.

# Upcoming Optimizations
* [ ] Dead code.
* [ ] Constant folding.
* [ ] And probably more...

# Lofty Goals
* [ ] Make the compiler suggest hints.
8 changes: 2 additions & 6 deletions bencher/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use clap::Parser;
use compiler::elf::ElfFile;
use compiler::interpreter::x86var::IStats;
use compiler::interpreter::{TestIO, IO};
use compiler::passes::parse::parse::parse_program;
use compiler::passes::select::interpreter::IStats;
use compiler::utils::split_test::split_test_raw;
use git2::{Commit, Repository};
use mongodb::bson;
Expand Down Expand Up @@ -277,11 +276,8 @@ impl Stats {

let (_, interpreter_stats) = prg_concluded.interpret_with_stats(io);

let (entry, program) = prg_concluded.emit();

let elf = ElfFile::new(entry, &program);
let mut file = File::create(&output).unwrap();
elf.write(&mut file);
prg_concluded.emit().write(&mut file);

let bencher_stats = BStats::new(&output);

Expand Down
83 changes: 57 additions & 26 deletions compiler/src/interpreter/value.rs → compiler/src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,63 @@ use crate::passes::parse::Lit;
use derive_more::Display;
use std::fmt::Display;
use std::hash::Hash;
use std::str::FromStr;
use std::io::stdin;
use std::vec::IntoIter;

pub trait IO {
fn read(&mut self) -> Lit;
fn print(&mut self, v: Lit);
}

struct StdIO {}

impl IO for StdIO {
fn read(&mut self) -> Lit {
print!("> ");
let mut input = String::new();
stdin()
.read_line(&mut input)
.expect("IO error or something");
input
.trim_end()
.parse()
.expect("Provided input was not a valid i64")
}

fn print(&mut self, v: Lit) {
println!("{v}");
}
}

pub struct TestIO {
inputs: IntoIter<Lit>,
outputs: Vec<Lit>,
}

impl TestIO {
pub fn new(inputs: Vec<Lit>) -> Self {
Self {
inputs: inputs.into_iter(),
outputs: Vec::new(),
}
}

pub fn outputs(&self) -> &Vec<Lit> {
&self.outputs
}
}

impl IO for TestIO {
fn read(&mut self) -> Lit {
self.inputs
.next()
.expect("Test tried to read more input than were available.")
}

fn print(&mut self, v: Lit) {
self.outputs.push(v);
}
}

#[derive(Eq, PartialEq, Copy, Clone, Debug, Display)]
pub enum Val<A: Copy + Hash + Eq + Display> {
Expand Down Expand Up @@ -54,28 +110,3 @@ impl<A: Copy + Hash + Eq + Display> Val<A> {
}
}
}

impl From<Lit> for i64 {
fn from(value: Lit) -> Self {
match value {
Lit::Int { val } => val,
Lit::Bool { val } => val as i64,
Lit::Unit => 0,
}
}
}

impl FromStr for Lit {
type Err = ();

fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s {
"false" => Lit::Bool { val: false },
"true" => Lit::Bool { val: true },
"unit" => Lit::Unit,
s => Lit::Int {
val: s.parse().map_err(|_| ())?,
},
})
}
}
61 changes: 0 additions & 61 deletions compiler/src/interpreter/mod.rs

This file was deleted.

1 change: 0 additions & 1 deletion compiler/src/language/mod.rs

This file was deleted.

Loading

0 comments on commit 755ded8

Please sign in to comment.