Skip to content

Commit

Permalink
Extract constants later so that simplify has more information
Browse files Browse the repository at this point in the history
  • Loading branch information
voltrevo committed Jul 1, 2023
1 parent 530c025 commit dada0cb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
6 changes: 5 additions & 1 deletion valuescript_compiler/src/optimization/optimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ use super::simplify::simplify;

pub fn optimize(module: &mut Module, pointer_allocator: &mut NameAllocator) {
collapse_pointers_of_pointers(module);
extract_constants(module, pointer_allocator);
shake_tree(module);
simplify(module);
remove_noops(module);
remove_meta_lines(module);
extract_constants(module, pointer_allocator);

// After possibly repeated optimization, this ensures that the pointers are ordered correctly.
// TODO: Consider a dedicated step that's only about pointer ordering and not tree shaking.
shake_tree(module);
}
20 changes: 14 additions & 6 deletions valuescript_vm/src/bytecode_stack_frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,12 +561,20 @@ impl StackFrameTrait for BytecodeStackFrame {
}

Cat => {
assert!(
self.decoder.decode_type() == BytecodeType::Array,
"TODO: cat non-inline arrays"
);

let cat_frame = CatStackFrame::from_args(self.decoder.decode_vec_val(&mut self.registers));
let cat_frame = match self.decoder.peek_type() {
BytecodeType::Array => {
self.decoder.decode_type();
CatStackFrame::from_vec_val(self.decoder.decode_vec_val(&mut self.registers))
}
_ => match self.decoder.decode_val(&mut self.registers) {
Val::Array(array) => CatStackFrame::from_vec_val(array.elements.clone()),
_ => {
return Err(
"TODO: cat instruction on non-array (usually type error)".to_internal_error(),
)
}
},
};

self.this_target = None;
self.return_target = self.decoder.decode_register_index();
Expand Down
2 changes: 1 addition & 1 deletion valuescript_vm/src/cat_stack_frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub enum CatFrameState {
}

impl CatStackFrame {
pub fn from_args(args: Vec<Val>) -> Self {
pub fn from_vec_val(args: Vec<Val>) -> Self {
Self {
state: CatFrameState::ReadNext,
iter_result: None,
Expand Down

0 comments on commit dada0cb

Please sign in to comment.