Skip to content

Commit

Permalink
progress on issue #9
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgenvinju committed Oct 15, 2019
1 parent 3b4bb7a commit 40c3a42
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
14 changes: 9 additions & 5 deletions src/lang/flybytes/Decompiler.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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]);
Expand Down
3 changes: 2 additions & 1 deletion src/lang/flybytes/Syntax.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 40c3a42

Please sign in to comment.