Skip to content

Commit

Permalink
Formatting and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Gui-Yom committed Jul 19, 2022
1 parent bfec8a7 commit 778bb79
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
5 changes: 3 additions & 2 deletions src/decompiler/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl Display for FormatOptions {
}
}

fn to_haxe_type(ty: &Type, ctx: &Bytecode) -> impl Display {
fn to_haxe_type<'a>(ty: &Type, ctx: &'a Bytecode) -> impl Display + 'a {
use crate::Type::*;
match ty {
Void => "Void",
Expand All @@ -52,6 +52,7 @@ fn to_haxe_type(ty: &Type, ctx: &Bytecode) -> impl Display {
Bytes => "hl.Bytes",
Dyn => "Dynamic",
Fun(_) => "Function",
Obj(obj) => obj.name.resolve(&ctx.strings),
_ => "other",
}
}
Expand Down Expand Up @@ -91,7 +92,7 @@ impl Method {
} else {
"\n"
for stmt in &self.statements {
{opts}{stmt.display(&new_opts, ctx, fun)}"\n"
{new_opts}{stmt.display(&new_opts, ctx, fun)}"\n"
}
{opts}"}"
}
Expand Down
41 changes: 20 additions & 21 deletions src/decompiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,11 @@ pub fn decompile_function(code: &Bytecode, f: &Function) -> Vec<Statement> {

// Initialize register state with the function arguments
for i in start..f.ty(code).args.len() {
reg_state.insert(
Reg(i as u32),
Expr::Variable(
Reg(i as u32),
f.arg_name(code, i - start).map(ToOwned::to_owned),
),
);
let name = f.arg_name(code, i - start).map(ToOwned::to_owned);
reg_state.insert(Reg(i as u32), Expr::Variable(Reg(i as u32), name.clone()));
if let Some(name) = name {
seen.insert(name);
}
}

macro_rules! push_stmt {
Expand Down Expand Up @@ -518,17 +516,19 @@ pub fn decompile_function(code: &Bytecode, f: &Function) -> Vec<Statement> {
))
);
}
} else if fun.resolve_as_fn(code).unwrap().ty(code).ret.is_void() {
push_stmt!(Statement::Call(Call::new_fun(
*fun,
args.iter().map(|x| expr!(x)).collect::<Vec<_>>(),
)));
} else {
push_expr!(
i,
*dst,
call_fun(*fun, args.iter().map(|x| expr!(x)).collect::<Vec<_>>())
);
if fun.ty(code).ret.is_void() {
push_stmt!(Statement::Call(Call::new_fun(
*fun,
args.iter().map(|x| expr!(x)).collect::<Vec<_>>(),
)));
} else {
push_expr!(
i,
*dst,
call_fun(*fun, args.iter().map(|x| expr!(x)).collect::<Vec<_>>())
);
}
}
}
Opcode::CallMethod { dst, field, args } => {
Expand Down Expand Up @@ -578,9 +578,8 @@ pub fn decompile_function(code: &Bytecode, f: &Function) -> Vec<Statement> {
);
if f.regtype(*fun)
.resolve_as_fun(&code.types)
.unwrap()
.ret
.is_void()
.map(|ty| ty.ret.is_void())
.unwrap_or(false)
{
push_stmt!(Statement::Call(call));
} else {
Expand Down Expand Up @@ -746,7 +745,7 @@ pub fn decompile_function(code: &Bytecode, f: &Function) -> Vec<Statement> {
}
&Opcode::JAlways { offset } => {
if offset < 0 {
println!("opcode {i}");
//println!("opcode {i}");
// It's either the jump backward of a loop or a continue statement
let loop_ = scopes.last_loop().unwrap();
// Scan the next instructions in order to find another jump to the same place
Expand Down

0 comments on commit 778bb79

Please sign in to comment.