@@ -21,17 +21,19 @@ unpack(Kind, Name, Args, S) ->
21
21
% % Unpack default from given args.
22
22
% % Returns the given arguments without their default
23
23
% % clauses and a list of clauses for the default calls.
24
- unpack_each (Kind , Name , [{'\\\\ ' , Line , [Expr , _ ]}|T ] = List , Acc , Clauses , S ) ->
25
- Base = build_match (Acc , Line , [] ),
26
- {Args , Invoke } = extract_defaults (List , Line , length (Base ), [], []),
24
+ unpack_each (Kind , Name , [{'\\\\ ' , DefMeta , [Expr , _ ]}|T ] = List , Acc , Clauses , S ) ->
25
+ Base = wrap_kind ( Kind , build_match (Acc , []) ),
26
+ {Args , Invoke } = extract_defaults (List , length (Base ), [], []),
27
27
28
28
{DefArgs , SA } = elixir_clauses :match (fun elixir_translator :translate_args /2 , Base ++ Args , S ),
29
29
{DefInvoke , _ } = elixir_translator :translate_args (Base ++ Invoke , SA ),
30
30
31
+ Line = ? line (DefMeta ),
32
+
31
33
Call = {call , Line ,
32
34
{atom , Line , name_for_kind (Kind , Name )},
33
35
DefInvoke
34
- },
36
+ },
35
37
36
38
Clause = {clause , Line , DefArgs , [], [Call ]},
37
39
unpack_each (Kind , Name , T , [Expr |Acc ], [Clause |Clauses ], S );
@@ -44,25 +46,28 @@ unpack_each(_Kind, _Name, [], Acc, Clauses, _S) ->
44
46
45
47
% Extract default values from args following the current default clause.
46
48
47
- extract_defaults ([{'\\\\ ' , _ , [_Expr , Default ]}|T ], Line , Counter , NewArgs , NewInvoke ) ->
48
- extract_defaults (T , Line , Counter , NewArgs , [Default |NewInvoke ]);
49
+ extract_defaults ([{'\\\\ ' , _ , [_Expr , Default ]}|T ], Counter , NewArgs , NewInvoke ) ->
50
+ extract_defaults (T , Counter , NewArgs , [Default |NewInvoke ]);
49
51
50
- extract_defaults ([_ |T ], Line , Counter , NewArgs , NewInvoke ) ->
51
- H = {elixir_utils :atom_concat ([" _@D " , Counter ]), Line , nil },
52
- extract_defaults (T , Line , Counter + 1 , [H |NewArgs ], [H |NewInvoke ]);
52
+ extract_defaults ([_ |T ], Counter , NewArgs , NewInvoke ) ->
53
+ H = {elixir_utils :atom_concat ([" x " , Counter ]), [] , nil },
54
+ extract_defaults (T , Counter + 1 , [H |NewArgs ], [H |NewInvoke ]);
53
55
54
- extract_defaults ([], _Line , _Counter , NewArgs , NewInvoke ) ->
56
+ extract_defaults ([], _Counter , NewArgs , NewInvoke ) ->
55
57
{lists :reverse (NewArgs ), lists :reverse (NewInvoke )}.
56
58
57
59
% Build matches for all the previous argument until the current default clause.
58
60
59
- build_match ([], _Line , Acc ) -> Acc ;
61
+ build_match ([], Acc ) -> Acc ;
60
62
61
- build_match ([_ |T ], Line , Acc ) ->
62
- Var = {elixir_utils :atom_concat ([" _@D " , length (T )]), Line , nil },
63
- build_match (T , Line , [Var |Acc ]).
63
+ build_match ([_ |T ], Acc ) ->
64
+ Var = {elixir_utils :atom_concat ([" x " , length (T )]), [] , nil },
65
+ build_match (T , [Var |Acc ]).
64
66
65
67
% Given the invoked function name based on the kind
66
68
69
+ wrap_kind (Kind , Args ) when Kind == defmacro ; Kind == defmacrop -> [{c , [], nil }|Args ];
70
+ wrap_kind (_Kind , Args ) -> Args .
71
+
67
72
name_for_kind (Kind , Name ) when Kind == defmacro ; Kind == defmacrop -> elixir_utils :macro_name (Name );
68
73
name_for_kind (_Kind , Name ) -> Name .
0 commit comments