Skip to content

Commit

Permalink
format code
Browse files Browse the repository at this point in the history
  • Loading branch information
pufferfish101007 committed Aug 22, 2023
1 parent b348667 commit 74694fb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
21 changes: 14 additions & 7 deletions src/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl From<Sb3Project> for IrProject {
})
.collect(),
);

let mut steps: BTreeMap<String, Step> = Default::default();
let mut threads: Vec<Thread> = vec![];
for (target_index, target) in sb3.targets.iter().enumerate() {
Expand All @@ -58,7 +58,8 @@ impl From<Sb3Project> for IrProject {
}),
vars: Rc::clone(&vars),
});
let thread = Thread::from_hat(block.clone(), target.blocks.clone(), context, &mut steps);
let thread =
Thread::from_hat(block.clone(), target.blocks.clone(), context, &mut steps);
threads.push(thread);
}
}
Expand Down Expand Up @@ -769,10 +770,7 @@ pub fn step_from_top_block<'a>(

impl Thread {
pub fn new(start: ThreadStart, first_step: String) -> Thread {
Thread {
start,
first_step,
}
Thread { start, first_step }
}
pub fn start(&self) -> &ThreadStart {
&self.start
Expand All @@ -788,7 +786,16 @@ impl Thread {
) -> Thread {
let (first_step_id, _first_step) = if let Block::Normal { block_info, .. } = &hat {
if let Some(next_id) = &block_info.next {
(next_id.clone(), step_from_top_block(next_id.clone(), vec![], &blocks, Rc::clone(&context), steps))
(
next_id.clone(),
step_from_top_block(
next_id.clone(),
vec![],
&blocks,
Rc::clone(&context),
steps,
),
)
} else {
unreachable!();
}
Expand Down
21 changes: 15 additions & 6 deletions src/targets/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ fn instructions(
} => {
if let Some(next_step_id) = step {
let next_step = steps.get(next_step_id).unwrap();
let next_step_index = (next_step_id, next_step).compile_wasm(step_funcs, string_consts, steps);
let next_step_index =
(next_step_id, next_step).compile_wasm(step_funcs, string_consts, steps);
let thread_indices: u64 = byte_offset::THREADS
.try_into()
.expect("THREAD_INDICES out of bounds (E018)");
Expand Down Expand Up @@ -275,7 +276,8 @@ fn instructions(
} => {
if let Some(next_step_id) = step {
let next_step = steps.get(next_step_id).unwrap();
let next_step_index = (next_step_id, next_step).compile_wasm(step_funcs, string_consts, steps);
let next_step_index =
(next_step_id, next_step).compile_wasm(step_funcs, string_consts, steps);
vec![
LocalGet(step_func_locals::MEM_LOCATION),
I32Const(
Expand Down Expand Up @@ -350,7 +352,8 @@ fn instructions(
} => {
if let Some(next_step_id) = step {
let next_step = steps.get(next_step_id).unwrap();
let next_step_index = (next_step_id, next_step).compile_wasm(step_funcs, string_consts, steps);
let next_step_index =
(next_step_id, next_step).compile_wasm(step_funcs, string_consts, steps);
let thread_indices: u64 = byte_offset::THREADS
.try_into()
.expect("THREAD_INDICES out of bounds (E018)");
Expand Down Expand Up @@ -436,7 +439,8 @@ fn instructions(
} => {
if let Some(next_step_id) = step {
let next_step = steps.get(next_step_id).unwrap();
let next_step_index = (next_step_id, next_step).compile_wasm(step_funcs, string_consts, steps);
let next_step_index =
(next_step_id, next_step).compile_wasm(step_funcs, string_consts, steps);
vec![
I32WrapI64,
If(WasmBlockType::Empty), //WasmBlockType::FunctionType(types::NOPARAM_I32)),
Expand Down Expand Up @@ -573,7 +577,11 @@ impl CompileToWasm for Thread {
string_consts: &mut Vec<String>,
steps: &BTreeMap<String, Step>,
) -> u32 {
(self.first_step(), steps.get(self.first_step()).unwrap()).compile_wasm(step_funcs, string_consts, steps)
(self.first_step(), steps.get(self.first_step()).unwrap()).compile_wasm(
step_funcs,
string_consts,
steps,
)
}
}

Expand Down Expand Up @@ -1109,7 +1117,8 @@ impl From<IrProject> for WebWasmFile {
step_funcs.insert(None, noop_func);

for thread in project.threads {
let first_idx = thread.compile_wasm(&mut step_funcs, &mut string_consts, &project.steps);
let first_idx =
thread.compile_wasm(&mut step_funcs, &mut string_consts, &project.steps);
thread_indices.push((thread.start().clone(), first_idx));
}

Expand Down

0 comments on commit 74694fb

Please sign in to comment.