Skip to content

Commit 0467436

Browse files
sys_core_bsm: specs
1 parent 2e83823 commit 0467436

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

lib/compiler/src/sys_core_bsm.erl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424

2525
-module(sys_core_bsm).
26+
-compile(warn_missing_spec_all).
2627
-moduledoc false.
2728
-export([module/2]).
2829

@@ -33,6 +34,7 @@
3334
module(#c_module{defs=Ds}=Mod, _Opts) ->
3435
{ok,Mod#c_module{defs=function(Ds)}}.
3536

37+
-spec function([{cerl:c_var(), cerl:cerl()}]) -> [{cerl:c_var(), cerl:cerl()}].
3638
function([{#c_var{name={F,Arity}}=Name,B0}|Fs]) ->
3739
try cerl_trees:map(fun bsm_reorder/1, B0) of
3840
B -> [{Name,B} | function(Fs)]
@@ -46,13 +48,15 @@ function([]) ->
4648

4749
%%% Reorder bit syntax matching to facilitate optimization in further passes.
4850

51+
-spec bsm_reorder(cerl:cerl()) -> cerl:cerl().
4952
bsm_reorder(#c_case{arg=#c_var{}=V}=Case) ->
5053
bsm_reorder_1([V], Case);
5154
bsm_reorder(#c_case{arg=#c_values{es=Es}}=Case) ->
5255
bsm_reorder_1(Es, Case);
5356
bsm_reorder(Core) ->
5457
Core.
5558

59+
-spec bsm_reorder_1([cerl:cerl()], cerl:c_case()) -> cerl:cerl().
5660
bsm_reorder_1(Vs0, #c_case{clauses=Cs0}=Case) ->
5761
case bsm_leftmost(Cs0) of
5862
Pos when Pos > 0, Pos =/= none ->
@@ -64,6 +68,7 @@ bsm_reorder_1(Vs0, #c_case{clauses=Cs0}=Case) ->
6468
Case
6569
end.
6670

71+
-spec move_from_col(integer(), [cerl:cerl()]) -> [cerl:cerl()].
6772
move_from_col(Pos, L) ->
6873
{First,[Col|Rest]} = lists:split(Pos - 1, L),
6974
[Col|First] ++ Rest.
@@ -72,15 +77,18 @@ move_from_col(Pos, L) ->
7277
%% Find the leftmost argument that matches a nonempty binary.
7378
%% Return either 'none' or the argument number (1-N).
7479

80+
-spec bsm_leftmost([cerl:c_clause()]) -> integer() | none.
7581
bsm_leftmost(Cs) ->
7682
bsm_leftmost_1(Cs, none).
7783

84+
-spec bsm_leftmost_1([cerl:c_clause()], integer() | none) -> integer() | none.
7885
bsm_leftmost_1([_|_], 1) ->
7986
1;
8087
bsm_leftmost_1([#c_clause{pats=Ps}|Cs], Pos) ->
8188
bsm_leftmost_2(Ps, Cs, 1, Pos);
8289
bsm_leftmost_1([], Pos) -> Pos.
8390

91+
-spec bsm_leftmost_2([cerl:cerl()], [cerl:c_clause()], integer(), integer() | none) -> integer() | none.
8492
bsm_leftmost_2(_, Cs, Pos, Pos) ->
8593
bsm_leftmost_1(Cs, Pos);
8694
bsm_leftmost_2([#c_binary{segments=[_|_]}|_], Cs, N, _) ->

0 commit comments

Comments
 (0)