@@ -25,6 +25,7 @@ find_import(Meta, Name, Arity, S) ->
25
25
26
26
case find_dispatch (Meta , Tuple , S ) of
27
27
{ function , Receiver } -> Receiver ;
28
+ { import , Receiver } -> Receiver ;
28
29
{ macro , Receiver } -> Receiver ;
29
30
nomatch -> false
30
31
end .
@@ -39,6 +40,8 @@ import_function(Meta, Name, Arity, S) ->
39
40
remote_function (Meta , Receiver , Name , Arity , S );
40
41
{ macro , _Receiver } ->
41
42
false ;
43
+ { import , Receiver } ->
44
+ require_function (Meta , Receiver , Name , Arity , S );
42
45
nomatch ->
43
46
{ { 'fun' , ? line (Meta ), { function , Name , Arity } }, S }
44
47
end .
@@ -66,6 +69,8 @@ dispatch_import(Meta, Name, Args, S, Callback) ->
66
69
false -> Receiver
67
70
end ,
68
71
elixir_translator :translate_each ({ { '.' , Meta , [Endpoint , Name ] }, Meta , Args }, S );
72
+ { import , Receiver } ->
73
+ elixir_translator :translate_each ({ { '.' , Meta , [Receiver , Name ] }, [{require ,false }|Meta ], Args }, S );
69
74
Result ->
70
75
case do_expand_import (Meta , Tuple , Args , Module , S , Result ) of
71
76
{ error , noexpansion } ->
@@ -85,14 +90,15 @@ dispatch_require(Meta, Receiver, Name, Args, S, Callback) ->
85
90
86
91
case (Receiver == ? BUILTIN ) andalso is_element (Tuple , in_erlang_functions ()) of
87
92
true ->
88
- elixir_translator :translate_each ({ { '.' , Meta , [erlang , Name ] }, Meta , Args }, S );
93
+ { TArgs , SA } = elixir_translator :translate_args (Args , S ),
94
+ { ? wrap_call (? line (Meta ), erlang , Name , TArgs ), SA };
89
95
false ->
90
96
case expand_require (Meta , Receiver , Tuple , Args , Module , S ) of
91
97
{ error , noexpansion } ->
92
98
Callback ();
93
99
{ error , internal } ->
94
100
elixir_macros :translate ({ Name , Meta , Args }, S );
95
- { ok , Tree } ->
101
+ { ok , _Receiver , Tree } ->
96
102
translate_expansion (Meta , Tree , S )
97
103
end
98
104
end .
@@ -115,6 +121,8 @@ do_expand_import(Meta, { Name, Arity } = Tuple, Args, Module, S, Result) ->
115
121
{ macro , Receiver } ->
116
122
elixir_import :record (import , Tuple , Receiver , Module ),
117
123
{ ok , Receiver , expand_macro_named (Meta , Receiver , Name , Arity , Args , Module , S ) };
124
+ { import , Receiver } ->
125
+ expand_require (Meta , Receiver , Tuple , Args , Module , S );
118
126
_ ->
119
127
Fun = (S # elixir_scope .function /= Tuple ) andalso
120
128
elixir_def_local :macro_for (Tuple , true , Module ),
@@ -131,7 +139,7 @@ expand_require(Meta, ?BUILTIN, { Name, Arity } = Tuple, Args, Module, S) ->
131
139
true -> { error , internal };
132
140
false ->
133
141
case is_element (Tuple , in_elixir_macros ()) of
134
- true -> { ok , expand_macro_named (Meta , ? BUILTIN , Name , Arity , Args , Module , S ) };
142
+ true -> { ok , ? BUILTIN , expand_macro_named (Meta , ? BUILTIN , Name , Arity , Args , Module , S ) };
135
143
false -> { error , noexpansion }
136
144
end
137
145
end ;
@@ -143,12 +151,12 @@ expand_require(Meta, Receiver, { Name, Arity } = Tuple, Args, Module, S) ->
143
151
case Fun of
144
152
false ->
145
153
case is_element (Tuple , get_optional_macros (Receiver )) of
146
- true -> { ok , expand_macro_named (Meta , Receiver , Name , Arity , Args , Module , S ) };
154
+ true -> { ok , Receiver , expand_macro_named (Meta , Receiver , Name , Arity , Args , Module , S ) };
147
155
false -> { error , noexpansion }
148
156
end ;
149
157
_ ->
150
158
elixir_import :record (import , Tuple , Receiver , Module ),
151
- { ok , expand_macro_fun (Meta , Fun , Receiver , Name , Args , Module , S ) }
159
+ { ok , Receiver , expand_macro_fun (Meta , Fun , Receiver , Name , Args , Module , S ) }
152
160
end .
153
161
154
162
% % Expansion helpers
@@ -203,21 +211,26 @@ find_dispatch(Meta, Tuple, S) ->
203
211
find_dispatch (Meta , Tuple , [], S ).
204
212
205
213
find_dispatch (Meta , Tuple , Extra , S ) ->
206
- Functions = S # elixir_scope .functions ,
207
- Macros = Extra ++ S # elixir_scope .macros ,
208
- File = S # elixir_scope .file ,
209
- FunMatch = find_dispatch (Tuple , Functions ),
210
- MacMatch = find_dispatch (Tuple , Macros ),
211
-
212
- case { FunMatch , MacMatch } of
213
- { [], [Receiver ] } -> { macro , Receiver };
214
- { [Receiver ], [] } -> { function , Receiver };
215
- { [], [] } -> nomatch ;
216
- _ ->
217
- { Name , Arity } = Tuple ,
218
- [First , Second |_ ] = FunMatch ++ MacMatch ,
219
- Err = { ambiguous_call , { First , Second , Name , Arity } },
220
- elixir_errors :form_error (Meta , File , ? MODULE , Err )
214
+ case lists :keyfind (import , 1 , Meta ) of
215
+ { import , _ } = Import ->
216
+ Import ;
217
+ false ->
218
+ Functions = S # elixir_scope .functions ,
219
+ Macros = Extra ++ S # elixir_scope .macros ,
220
+ File = S # elixir_scope .file ,
221
+ FunMatch = find_dispatch (Tuple , Functions ),
222
+ MacMatch = find_dispatch (Tuple , Macros ),
223
+
224
+ case { FunMatch , MacMatch } of
225
+ { [], [Receiver ] } -> { macro , Receiver };
226
+ { [Receiver ], [] } -> { function , Receiver };
227
+ { [], [] } -> nomatch ;
228
+ _ ->
229
+ { Name , Arity } = Tuple ,
230
+ [First , Second |_ ] = FunMatch ++ MacMatch ,
231
+ Error = { ambiguous_call , { First , Second , Name , Arity } },
232
+ elixir_errors :form_error (Meta , File , ? MODULE , Error )
233
+ end
221
234
end .
222
235
223
236
find_dispatch (Tuple , List ) ->
@@ -252,7 +265,7 @@ remote_function(Meta, Receiver, Name, Arity, S) ->
252
265
Line = ? line (Meta ),
253
266
254
267
Final =
255
- case Receiver == ? BUILTIN andalso is_element ({ Name , Arity }, in_erlang_functions ()) of
268
+ case ( Receiver == ? BUILTIN ) andalso is_element ({ Name , Arity }, in_erlang_functions ()) of
256
269
true -> erlang ;
257
270
false -> Receiver
258
271
end ,
0 commit comments