Skip to content

Commit

Permalink
thirteen
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanWoollett-Light committed Dec 6, 2023
1 parent 6804cf3 commit 3092e4e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
21 changes: 16 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2393,11 +2393,22 @@ mod tests {
// Optimization
let optimized = test_optimization(
path,
&[Statement {
comptime: false,
op: Op::Syscall(Syscall::Exit),
arg: vec![Value::Literal(Literal::Integer(253))],
}],
&[
Statement {
comptime: false,
op: Op::Special(Special::Type),
arg: vec![
Value::Variable(Variable::new("x")),
Value::Type(Type::U8),
Value::Literal(Literal::Integer(1)),
],
},
Statement {
comptime: false,
op: Op::Syscall(Syscall::Exit),
arg: vec![Value::Literal(Literal::Integer(253))],
},
],
HashSet::from([]),
&[Statement {
comptime: false,
Expand Down
19 changes: 17 additions & 2 deletions src/middle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ pub unsafe fn build_optimized_tree(
first_node = next_state_node.as_ref().statement;
}
}
next_state_node.as_mut().statement.as_mut().preceding =
current.as_ref().statement.as_ref().preceding;

alloc::dealloc(
current.as_ref().statement.as_ptr().cast(),
alloc::Layout::new::<NewNode>(),
Expand Down Expand Up @@ -242,6 +245,9 @@ pub unsafe fn build_optimized_tree(
first_node = next_state_node.as_ref().statement;
}
}
next_state_node.as_mut().statement.as_mut().preceding =
current.as_ref().statement.as_ref().preceding;

alloc::dealloc(
current.as_ref().statement.as_ptr().cast(),
alloc::Layout::new::<NewNode>(),
Expand Down Expand Up @@ -308,7 +314,10 @@ pub unsafe fn build_optimized_tree(
// is both the 1st node and last node, thus removing it is an error.
first_node = next_state_node.as_ref().statement;
}
}
};
next_state_node.as_mut().statement.as_mut().preceding =
current.as_ref().statement.as_ref().preceding;

alloc::dealloc(
current.as_ref().statement.as_ptr().cast(),
alloc::Layout::new::<NewNode>(),
Expand Down Expand Up @@ -376,6 +385,9 @@ pub unsafe fn build_optimized_tree(
first_node = next_state_node.as_ref().statement;
}
}
next_state_node.as_mut().statement.as_mut().preceding =
current.as_ref().statement.as_ref().preceding;

alloc::dealloc(
current.as_ref().statement.as_ptr().cast(),
alloc::Layout::new::<NewNode>(),
Expand Down Expand Up @@ -437,6 +449,9 @@ pub unsafe fn build_optimized_tree(
first_node = next_state_node.as_ref().statement;
}
}
next_state_node.as_mut().statement.as_mut().preceding =
current.as_ref().statement.as_ref().preceding;

alloc::dealloc(
current.as_ref().statement.as_ptr().cast(),
alloc::Layout::new::<NewNode>(),
Expand Down Expand Up @@ -515,8 +530,8 @@ pub unsafe fn finish_optimized_tree(
identifier,
index: None,
}), Value::Type(_), Value::Literal(_)] => {
dbg!(&read);
if !read.contains(identifier) {
dbg!();
match current.as_ref().preceding {
Some(Preceding::Parent(mut parent)) => {
parent.as_mut().child = current.as_ref().next;
Expand Down

0 comments on commit 3092e4e

Please sign in to comment.