clj_module
Clojerl compilation module.
Keeps the Core Erlang representation for the modules being compiled.
It is mainly used byclj_emitter
to register new
modules and then add or update function as each form in the
compiler is processed.
Summary
Types
Functions
-
add_alias(AliasSym, AliasedNsSym, ModuleName)
Adds an alias symbol for a Clojerl namespace.
-
add_attributes(Attrs, ModuleName)
Adds arbitrary attributes to the module.
-
add_exports(Exports, ModuleName)
Adds exports of functions to the module.
-
add_functions(Funs, ModuleName)
Adds functions to the module.
-
add_mappings(Mappings, ModuleName)
Adds mappings from a symbol to a value.
-
add_on_load(Expr, ModuleName)
Adds an on_load expression to the module.
-
all_modules()
Returns a list where each element is Core Erlang module.
-
ensure_loaded(Source, Name)
Makes sure the clj_module is loaded.
-
fake_fun(ModuleName, Function, Arity)
Gets the named fake fun that corresponds to the mfa provided.
-
get_functions(ModuleName)
Returns all functions in the module.
-
get_module(ModuleName)
Returns the Core Erlang module named
ModuleName
. -
in_context()
Checks whether we are in a
clj_module
context. -
is_clojure(Name)
Checks if the
Name
module is a Clojerl module. -
is_loaded(Name)
Checks if the Clojelr module
Name
is loaded. -
is_protocol(Name)
Checks if the
Name
module is a Clojerl protocol. -
maybe_ensure_loaded(Name)
Ensures a module is loaded when in a compiling context.
-
remove_all_functions(ModuleName)
Remove all functions in the module.
- replace_remote_calls(C_call, CurrentModule)
-
replace_vars(T, IsFakeFun)
Adds the fake_fun flag to literal vars.
-
with_context(Fun)
Runs the function in a
clj_module
context.
Types
clj_module()
-type clj_module() :: #module{}.
function_id()
-type function_id() :: {atom(), integer()}.
Functions
add_alias(AliasSym, AliasedNsSym, ModuleName)
-spec add_alias('clojerl.Symbol':type(),
'clojerl.Symbol':type(),
module() | clj_module()) ->
clj_module().
Adds an alias symbol for a Clojerl namespace.
add_attributes(Attrs, ModuleName)
-spec add_attributes([{cerl:cerl(), cerl:cerl()}],
clj_module() | module()) ->
clj_module().
Adds arbitrary attributes to the module.
add_exports(Exports, ModuleName)
-spec add_exports([{atom(), non_neg_integer()}],
clj_module() | module()) ->
clj_module().
Adds exports of functions to the module.
add_functions(Funs, ModuleName)
-spec add_functions([{cerl:cerl(), cerl:cerl()}],
module() | clj_module()) ->
clj_module().
Adds functions to the module.
add_mappings(Mappings, ModuleName)
-spec add_mappings(['clojerl.Var':type() |
{binary(), 'erlang.Type':type()}],
module() | clj_module()) ->
clj_module().
Adds mappings from a symbol to a value.
add_on_load(Expr, ModuleName)
-spec add_on_load(cerl:cerl(), module() | clj_module()) -> clj_module().
Adds an on_load expression to the module.
all_modules()
-spec all_modules() -> [cerl:c_module()].
Returns a list where each element is Core Erlang module.
ensure_loaded(Source, Name)
-spec ensure_loaded(binary(), module()) -> ok.
Makes sure the clj_module is loaded.
fake_fun(ModuleName, Function, Arity)
-spec fake_fun(module(), atom(), integer()) -> function().
Gets the named fake fun that corresponds to the mfa provided.
A fake fun is generated during compile-time and it provides the same functionality as its original. The only difference is that all calls to functions in the same module are replaced by a call to clj_module:fake_fun/3.
This is necessary so that macro functions can be used without having to generate, compile and load the binary for the partial module each time a macro is found.
A fake module is generated for each fake fun because a previous attempt that used erl_eval to generate and execute the fake_fun was too slow.
get_functions(ModuleName)
-spec get_functions(module() | clj_module()) ->
[{function_id(), {cerl:c_fname(), cerl:c_fun()}}].
Returns all functions in the module.
get_module(ModuleName)
-spec get_module(atom()) -> cerl:c_module().
Returns the Core Erlang module named ModuleName
.
in_context()
-spec in_context() -> boolean().
Checks whether we are in a clj_module
context.
is_clojure(Name)
-spec is_clojure(module()) -> boolean().
Checks if the Name
module is a Clojerl module.
is_loaded(Name)
-spec is_loaded(module()) -> boolean().
Checks if the Clojelr module Name
is loaded.
is_protocol(Name)
-spec is_protocol(module() | cerl:c_module()) -> boolean().
Checks if the Name
module is a Clojerl protocol.
maybe_ensure_loaded(Name)
-spec maybe_ensure_loaded(module()) -> ok.
Ensures a module is loaded when in a compiling context
This is used from in-ns so that namespaces without any vars definition still get registered when compiling.
remove_all_functions(ModuleName)
-spec remove_all_functions(module() | clj_module()) -> clj_module().
Remove all functions in the module.
replace_remote_calls(C_call, CurrentModule)
-spec replace_remote_calls(cerl:cerl() |
[cerl:cerl()] |
{cerl:cerl(), cerl:cerl()},
module()) ->
cerl:cerl() |
[cerl:cerl()] |
{cerl:cerl(), cerl:cerl()}.
replace_vars(T, IsFakeFun)
-spec replace_vars(T, boolean()) -> T when T :: any().
Adds the fake_fun flag to literal vars
with_context(Fun)
-spec with_context(fun()) -> ok.
Runs the function in a clj_module
context.
clj_compiler
when evaluating or compiling
an expression. It should be used in conjuntion with in_context/0
when you need to find out if there is a clj_module
being processed.