Skip to content
This repository has been archived by the owner on Apr 12, 2019. It is now read-only.

Commit

Permalink
Check whether modules are loaded or not in the dispatcher rather than…
Browse files Browse the repository at this point in the history
… in Module.re
  • Loading branch information
Tony Arcieri committed Dec 26, 2010
1 parent e8b74b6 commit 08f87dc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
8 changes: 1 addition & 7 deletions src/builtins/module.re
Expand Up @@ -10,13 +10,7 @@ module Module

def call(receiver, :to_s, args, block)
(:reia_module, name) = receiver
case erl.code.ensure_loaded(name)
when (:module, name)
name.to_string()
when _
throw(NameError, "undefined module #{name}")
:error
end
name.to_string()
end

def call(receiver, :inspect, args, block)
Expand Down
10 changes: 8 additions & 2 deletions src/core/reia_dispatch.erl
Expand Up @@ -26,8 +26,14 @@ call(#reia_regexp{} = Receiver, Method, Arguments, Block) ->
'Regexp':call({Receiver, Method, Arguments}, Block);
call(#reia_range{} = Receiver, Method, Arguments, Block) ->
'Range':call({Receiver, Method, Arguments}, Block);
call(#reia_module{} = Receiver, Method, Arguments, Block) ->
'Module':call({Receiver, Method, Arguments, Block}, nil);
call(#reia_module{name=Name} = Receiver, Method, Arguments, Block) ->
case code:ensure_loaded(Name) of
{module, Name} ->
'Module':call({Receiver, Method, Arguments, Block}, nil);
_ ->
Message = lists:flatten(io_lib:format("undefined module ~s", [Name])),
reia:throw('NameError', Message)
end;
call(#reia_funref{} = Receiver, Method, Arguments, Block) ->
'Funref':call({Receiver, Method, Arguments}, Block);
call(Receiver, Method, Arguments, Block) when is_tuple(Receiver) ->
Expand Down

0 comments on commit 08f87dc

Please sign in to comment.