Skip to content

Commit

Permalink
Fix an issue with TESTSET on the first line for stripped chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
tehtmi committed Mar 11, 2021
1 parent d9c083e commit 098d9e0
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/unluac/decompile/Decompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -598,13 +598,13 @@ private List<Operation> processLine(State state, int line) {
break;
case TEST50: {
if(getNoDebug() && A != B) {
operations.add(new RegisterSet(line, A, Expression.make(Expression.BinaryOperation.OR, r.getExpression(B, line - 1), r.getExpression(A, line - 1))));
operations.add(new RegisterSet(line, A, Expression.make(Expression.BinaryOperation.OR, r.getExpression(B, line), initialExpression(state, A, line))));
}
break;
}
case TESTSET: case TESTSET54: {
if(getNoDebug()) {
operations.add(new RegisterSet(line, A, Expression.make(Expression.BinaryOperation.OR, r.getExpression(B, line - 1), r.getExpression(A, line - 1))));
operations.add(new RegisterSet(line, A, Expression.make(Expression.BinaryOperation.OR, r.getExpression(B, line), initialExpression(state, A, line))));
}
break;
}
Expand Down Expand Up @@ -751,6 +751,15 @@ private List<Operation> processLine(State state, int line) {
return operations;
}

private Expression initialExpression(State state, int register, int line) {
if(line == 1) {
if(register < function.numParams) throw new IllegalStateException();
return ConstantExpression.createNil(line);
} else {
return state.r.getExpression(register, line - 1);
}
}

private Assignment processOperation(State state, Operation operation, int line, int nextLine, Block block) {
Registers r = state.r;
boolean[] skip = state.skip;
Expand Down

0 comments on commit 098d9e0

Please sign in to comment.