diff --git a/src/lang/flybytes/Decompiler.rsc b/src/lang/flybytes/Decompiler.rsc index 9a91527..01945b8 100644 --- a/src/lang/flybytes/Decompiler.rsc +++ b/src/lang/flybytes/Decompiler.rsc @@ -371,12 +371,16 @@ list[Instruction] stmts([*Instruction pre, GOTO(str cond), LABEL(str body), *Ins list[Instruction] stmts([*Instruction pre, LABEL(str body), *Instruction c, stat(\if(Exp co, [asm([GOTO(body)])])), *Instruction post]) = stmts([*pre, stat(\doWhile([asm(stmts(c))], co)), *post]); -list[Instruction] stmts([*Instruction pre, stat(first:store(str name,_)), stat(\while(c, [asm([*Instruction b, stat(next:/store|incr/(name,_))])])), *Instruction post]) - = stmts([*pre, stat(\for([first], c, [next], [asm(stmts(b))])), *post]); +list[Instruction] stmts([*Instruction pre, stat(first:store(str name,_)), stat(\while(c, [asm([*Instruction b, stat(next)])])), *Instruction post]) + = stmts([*pre, stat(\for([first], c, [next], [asm(stmts(b))])), *post]) + when store(name,_) := next || do(inc(name, _)) := next + ; // fold in multiple inits and nexts in for loop -list[Instruction] stmts([*Instruction pre, stat(first:store(str name, _)), stat(\for(firsts, c, nexts, [asm([*Instruction b, stat(next:/store|incr/(name,_))])])), *Instruction post]) - = stmts([*pre, stat(\for([first,*firsts], c, [next, *nexts], [asm(stmts(b))])), *post]); +list[Instruction] stmts([*Instruction pre, stat(first:store(str name, _)), stat(\for(firsts, c, nexts, [asm([*Instruction b, stat(next)])])), *Instruction post]) + = stmts([*pre, stat(\for([first,*firsts], c, [next, *nexts], [asm(stmts(b))])), *post]) + when store(name,_) := next || do(inc(name, _)) := next + ; default list[Instruction] stmts(list[Instruction] st) = st; @@ -398,7 +402,7 @@ list[Instruction] exprs([*Instruction pre, tc:TRYCATCH(_, _, _, handler), *Inst = exprs([*pre, tc, *other, LABEL(handler), exp(load(name)) /* temporary */, *mid, lv, *post]); list[Instruction] exprs([*Instruction pre, IINC(int var, int i), *Instruction mid, Instruction lv:LOCALVARIABLE(str name, _, _, _, var), *Instruction post]) - = exprs([*pre, stat(incr(name, i)), *mid, lv, *post]); + = exprs([*pre, exp(inc(name, i)), *mid, lv, *post]); list[Instruction] exprs([*Instruction pre, /[AIFLD]LOAD/(int var), *Instruction mid, Instruction lv:LOCALVARIABLE(str name, _, _, _, var), *Instruction post]) = exprs([*pre, exp(load(name)), *mid, lv, *post]); diff --git a/src/lang/flybytes/Syntax.rsc b/src/lang/flybytes/Syntax.rsc index e532c61..8d11cd5 100644 --- a/src/lang/flybytes/Syntax.rsc +++ b/src/lang/flybytes/Syntax.rsc @@ -155,7 +155,6 @@ data Stat(loc src = |unknown:///|) | \decl(Type \type, str name, Exp init = defVal(\type)) | \astore(Exp array, Exp index, Exp arg) | \do(Exp exp) - | \incr(str name, int inc) | \return() | \return(Exp arg) | \putField(Type class, Exp receiver, Type \type, str name, Exp arg) @@ -455,6 +454,8 @@ Exp defVal(string()) = null(); Type object() = object("java.lang.Object"); +Stat incr(str name, int i) = \do(inc(name, i)); + Stat invokeSuper(list[Type] formals, list[Exp] args) = invokeSuper(constructorDesc(formals), args);