Add loop operator in fcode #889

Open
zxq9 wants to merge 27 commits from loop-op into master
2 changed files with 5 additions and 5 deletions
Showing only changes of commit c4243fb1da - Show all commits

View File

@ -656,7 +656,7 @@ expr_to_fcode(Env, _Type, {list, _, Es}) ->
expr_to_fcode(Env, _Type, {app, _, {'..', _}, [A, B]}) -> expr_to_fcode(Env, _Type, {app, _, {'..', _}, [A, B]}) ->
St = fresh_name(), St = fresh_name(),
Init = expr_to_fcode(Env, A), Init = expr_to_fcode(Env, A),
Loop = {loop, Init, St, make_if({op, '<', [{var, St}, expr_to_fcode(Env, B)]}, Loop = {loop, {}, St, make_if({op, '<', [{var, St}, expr_to_fcode(Env, B)]},
{continue, {op, '+', [{var, St}, {lit, {int, 1}}]}}, {continue, {op, '+', [{var, St}, {lit, {int, 1}}]}},
{break, nil} {break, nil}
)}, )},

View File

@ -375,14 +375,14 @@ to_scode1(Env, {closure, Fun, FVs}) ->
to_scode1(Env, {loop, Init, It, Expr}) -> to_scode1(Env, {loop, Init, It, Expr}) ->
ContRef = make_ref(), ContRef = make_ref(),
BreakRef = make_ref(), BreakRef = make_ref(),
InitS = to_scode(Env, Init) ++ [{jump, ContRef}],
{ItV, Env1} = bind_local(It, Env), {ItV, Env1} = bind_local(It, Env),
InitS = to_scode(Env, Init) ++ [aeb_fate_ops:store({var, ItV}, {stack, 0}), {jump, ContRef}],
ExprS = to_scode(bind_loop(ContRef, BreakRef, ItV, Env1), Expr) ++ [{jumpif, ?a, ContRef}, {jump, BreakRef}], ExprS = to_scode(bind_loop(ContRef, BreakRef, ItV, Env1), Expr) ++ [{jumpif, ?a, ContRef}, {jump, BreakRef}],
[{loop, InitS, It, ExprS, ContRef, BreakRef}]; [{loop, InitS, It, ExprS, ContRef, BreakRef}];
to_scode1(Env = #env{cont_ref = ContRef, loop_it = It}, {continue, Expr}) -> to_scode1(Env = #env{loop_it = It}, {continue, Expr}) ->
ExprS = to_scode1(Env, Expr), ExprS = to_scode1(Env, Expr),
ExprS ++ [{'STORE', It, ?a}, push(?i(1))]; ExprS ++ [aeb_fate_ops:store({var, It}, {stack, 0}), push(?i(1))];
to_scode1(Env = #env{break_ref = BreakRef}, {break, Expr}) -> to_scode1(Env, {break, Expr}) ->
ExprS = to_scode1(Env, Expr), ExprS = to_scode1(Env, Expr),
ExprS ++ [push(?i(0))]; ExprS ++ [push(?i(0))];
to_scode1(Env, {switch, Case}) -> to_scode1(Env, {switch, Case}) ->