diff options
author | Hans Bolinder <[email protected]> | 2017-06-09 14:34:39 +0200 |
---|---|---|
committer | Hans Bolinder <[email protected]> | 2017-06-12 14:53:11 +0200 |
commit | 44d609df5fc694ed1030cf7d56c492fc7e222590 (patch) | |
tree | c54f6919f825c63861390fafe904ca549f8265ed /lib/stdlib/src | |
parent | dd9e39dc2b97e30c03b24a00eb757be7d2c2bdc2 (diff) | |
download | otp-44d609df5fc694ed1030cf7d56c492fc7e222590.tar.gz otp-44d609df5fc694ed1030cf7d56c492fc7e222590.tar.bz2 otp-44d609df5fc694ed1030cf7d56c492fc7e222590.zip |
stdlib: Evaluate expressions in fun2ms bodies
The ms_transform module, used by ets:fun2ms/1 and dbg:fun2ms,
evaluates constant arithmetic expressions. This is necessary since the
Erlang compiler, which normally evaluates constant expressions, does
not recognize the format generated by ms_transform.
Diffstat (limited to 'lib/stdlib/src')
-rw-r--r-- | lib/stdlib/src/ms_transform.erl | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/stdlib/src/ms_transform.erl b/lib/stdlib/src/ms_transform.erl index c1c09f091c..6616e957c0 100644 --- a/lib/stdlib/src/ms_transform.erl +++ b/lib/stdlib/src/ms_transform.erl @@ -501,10 +501,20 @@ tg0(Line,[H|T],B) -> tg({match,Line,_,_},B) -> throw({error,Line,?ERR_GENMATCH+B#tgd.eb}); -tg({op, Line, Operator, O1, O2}, B) -> - {tuple, Line, [{atom, Line, Operator}, tg(O1,B), tg(O2,B)]}; -tg({op, Line, Operator, O1}, B) -> - {tuple, Line, [{atom, Line, Operator}, tg(O1,B)]}; +tg({op, Line, Operator, O1, O2}=Expr, B) -> + case erl_eval:partial_eval(Expr) of + Expr -> + {tuple, Line, [{atom, Line, Operator}, tg(O1, B), tg(O2, B)]}; + Value -> + Value + end; +tg({op, Line, Operator, O1}=Expr, B) -> + case erl_eval:partial_eval(Expr) of + Expr -> + {tuple, Line, [{atom, Line, Operator}, tg(O1, B)]}; + Value -> + Value + end; tg({call, _Line, {atom, Line2, bindings},[]},_B) -> {atom, Line2, '$*'}; tg({call, _Line, {atom, Line2, object},[]},_B) -> |