aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/src
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2015-02-03 16:49:17 +0100
committerBjörn Gustavsson <[email protected]>2015-02-12 13:14:37 +0100
commit058a4d87bb80254fe834d49cf9134d7d1dad9406 (patch)
treef5d5cd6aa316c91e778cf514e0ec618674bfb137 /lib/compiler/src
parent0910d13d2077af731a5e1eeed4ac3c11da8a329b (diff)
downloadotp-058a4d87bb80254fe834d49cf9134d7d1dad9406.tar.gz
otp-058a4d87bb80254fe834d49cf9134d7d1dad9406.tar.bz2
otp-058a4d87bb80254fe834d49cf9134d7d1dad9406.zip
sys_core_fold: Add is_int_type/2 and is_tuple_type/2
Those functions allow us to clean up some more code.
Diffstat (limited to 'lib/compiler/src')
-rw-r--r--lib/compiler/src/sys_core_fold.erl36
1 files changed, 19 insertions, 17 deletions
diff --git a/lib/compiler/src/sys_core_fold.erl b/lib/compiler/src/sys_core_fold.erl
index b298473617..bc9c97be87 100644
--- a/lib/compiler/src/sys_core_fold.erl
+++ b/lib/compiler/src/sys_core_fold.erl
@@ -1335,8 +1335,9 @@ eval_element(Call, #c_literal{val=Pos}, Tuple, Types)
eval_failure(Call, badarg)
end
end;
-eval_element(Call, Pos, Tuple, _Types) ->
- case is_not_integer(Pos) orelse is_not_tuple(Tuple) of
+eval_element(Call, Pos, Tuple, Sub) ->
+ case is_int_type(Pos, Sub) =:= no orelse
+ is_tuple_type(Tuple, Sub) =:= no of
true ->
eval_failure(Call, badarg);
false ->
@@ -1367,21 +1368,6 @@ eval_is_record(Call, Term, #c_literal{val=NeededTag},
end;
eval_is_record(Call, _, _, _, _) -> Call.
-%% is_not_integer(Core) -> true | false.
-%% Returns true if Core is definitely not an integer.
-
-is_not_integer(#c_literal{val=Val}) when not is_integer(Val) -> true;
-is_not_integer(#c_tuple{}) -> true;
-is_not_integer(#c_cons{}) -> true;
-is_not_integer(_) -> false.
-
-%% is_not_tuple(Core) -> true | false.
-%% Returns true if Core is definitely not a tuple.
-
-is_not_tuple(#c_literal{val=Val}) when not is_tuple(Val) -> true;
-is_not_tuple(#c_cons{}) -> true;
-is_not_tuple(_) -> false.
-
%% eval_setelement(Call, Pos, Tuple, NewVal) -> Core.
%% Evaluates setelement/3 if position Pos is an integer
%% the shape of the tuple Tuple is known.
@@ -2860,6 +2846,22 @@ is_boolean_type(Var, Sub) ->
yes_no(B)
end.
+-spec is_int_type(cerl:cerl(), sub()) -> yes_no_maybe().
+
+is_int_type(Var, Sub) ->
+ case get_type(Var, Sub) of
+ none -> maybe;
+ C -> yes_no(cerl:is_c_int(C))
+ end.
+
+-spec is_tuple_type(cerl:cerl(), sub()) -> yes_no_maybe().
+
+is_tuple_type(Var, Sub) ->
+ case get_type(Var, Sub) of
+ none -> maybe;
+ C -> yes_no(cerl:is_c_tuple(C))
+ end.
+
yes_no(true) -> yes;
yes_no(false) -> no.