Skip to content

Commit

Permalink
fix clippy£
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanWoollett-Light committed Nov 24, 2023
1 parent f2a1a60 commit 13a5217
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 42 deletions.
36 changes: 19 additions & 17 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ extern crate test;
use std::io::Read;

mod ast;
use ast::*;
mod frontend;
use frontend::*;
mod middle;
Expand All @@ -31,7 +30,14 @@ fn main() {
let mut iter = reader.bytes().peekable();
let nodes = get_nodes(&mut iter).unwrap();
let roots = roots(nodes);
let path = explore(&roots);
let mut explorer = Explorer::new(&roots);
let path = loop {
match explorer.next() {
Explore::Current(_) => continue,
Explore::Finished(x) => break x,
}
};

let optimized_nodes = optimize(path);
// let nodes = optimize_nodes(&nodes);
let _assembly = assembly_from_node(optimized_nodes);
Expand All @@ -49,6 +55,7 @@ fn main() {
#[cfg(test)]
mod tests {
use super::*;
use crate::ast::*;
use std::collections::HashSet;
use std::fs::remove_file;
use std::fs::OpenOptions;
Expand Down Expand Up @@ -143,12 +150,7 @@ mod tests {
}
}

fn test_optimization(nodes: NonNull<NewStateNode>, expected: &[Statement]) -> NonNull<NewNode> {
let new_nodes = unsafe { optimize(nodes) };
match_nodes(new_nodes, expected);
new_nodes
}
fn test_optimization_new(
fn test_optimization(
nodes: NonNull<NewStateNode>,
expected_build: &[Statement],
expected_read: HashSet<Identifier>,
Expand Down Expand Up @@ -265,7 +267,7 @@ mod tests {
);

// Optimization
let optimized = test_optimization_new(
let optimized = test_optimization(
path,
&[Statement {
comptime: false,
Expand Down Expand Up @@ -317,7 +319,7 @@ mod tests {
);

// Optimization
let optimized = test_optimization_new(
let optimized = test_optimization(
path,
&[Statement {
comptime: false,
Expand Down Expand Up @@ -369,7 +371,7 @@ mod tests {
);

// Optimization
let optimized = test_optimization_new(
let optimized = test_optimization(
path,
&[Statement {
comptime: false,
Expand Down Expand Up @@ -428,7 +430,7 @@ mod tests {
);

// Optimization
let optimized = test_optimization_new(
let optimized = test_optimization(
path,
&[Statement {
comptime: false,
Expand Down Expand Up @@ -601,7 +603,7 @@ mod tests {
);

// Optimization
let optimized = test_optimization_new(
let optimized = test_optimization(
path,
&[
Statement {
Expand Down Expand Up @@ -781,7 +783,7 @@ mod tests {
);

// Optimization
let optimized = test_optimization_new(
let optimized = test_optimization(
path,
&[
Statement {
Expand Down Expand Up @@ -1005,7 +1007,7 @@ mod tests {
);

// Optimization
let optimized = test_optimization_new(
let optimized = test_optimization(
path,
&[
Statement {
Expand Down Expand Up @@ -1234,7 +1236,7 @@ mod tests {
);

// Optimization
let optimized = test_optimization_new(
let optimized = test_optimization(
path,
&[
Statement {
Expand Down Expand Up @@ -1463,7 +1465,7 @@ mod tests {
);

// Optimization
let optimized = test_optimization_new(
let optimized = test_optimization(
path,
&[
Statement {
Expand Down
26 changes: 1 addition & 25 deletions src/middle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ pub unsafe fn build_optimized_tree(
debug_assert_eq!(current.as_ref().statement, first_node);
first_node = next_state_node.as_ref().statement;
}
_ => unreachable!(),
}
alloc::dealloc(
current.as_ref().statement.as_ptr().cast(),
Expand Down Expand Up @@ -566,19 +565,6 @@ unsafe fn explore_if(
}
}

unsafe fn print_ast(nodes: NonNull<NewNode>) {
let mut stack = vec![(nodes, 0)];
while let Some((current, indent)) = stack.pop() {
println!("{}{:?}", " ".repeat(indent), current.as_ref().statement);
if let Some(next) = current.as_ref().next {
stack.push((next, indent));
}
if let Some(child) = current.as_ref().child {
stack.push((child, indent + 1));
}
}
}

pub unsafe fn roots(node: NonNull<NewNode>) -> Vec<NonNull<NewStateNode>> {
get_possible_states(&node.as_ref().statement, &TypeValueState::new())
.into_iter()
Expand Down Expand Up @@ -796,6 +782,7 @@ pub struct Explorer<'a> {
roots: &'a [NonNull<NewStateNode>],
stack: Vec<NonNull<NewStateNode>>,
}

impl<'a> Explorer<'a> {
pub unsafe fn new(roots: &'a [NonNull<NewStateNode>]) -> Self {
Self {
Expand All @@ -814,17 +801,6 @@ impl<'a> Explorer<'a> {
}
}

pub unsafe fn explore(roots: &[NonNull<NewStateNode>]) -> NonNull<NewStateNode> {
dbg!(&roots);

let mut stack = Vec::from(roots);
while let Some(current) = stack.pop() {
explore_node(current, &mut stack);
close_path(current);
}
pick_path(roots)
}

pub unsafe fn pick_path(roots: &[NonNull<NewStateNode>]) -> NonNull<NewStateNode> {
let mut iter = roots.iter().copied();
let mut best = iter.next().unwrap();
Expand Down

0 comments on commit 13a5217

Please sign in to comment.