Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions libs/estdlib/src/code_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
atom_resolver/2,
literal_resolver/2,
type_resolver/2,
import_resolver/2,
set_native_code/3
]).

Expand Down Expand Up @@ -135,6 +136,14 @@ literal_resolver(_Module, _Index) ->
type_resolver(_Module, _Index) ->
erlang:nif_error(undefined).

%% @doc Get an imported function triplet from its index
%% @return The imported function as {Module, Function, Arity}
%% @param Module module to get the imported function from
%% @param Index imported function index in the module
-spec import_resolver(Module :: module(), Index :: non_neg_integer()) -> {atom(), atom(), non_neg_integer()}.
import_resolver(_Module, _Index) ->
erlang:nif_error(undefined).

%% @doc Associate a native code stream with a module
%% @return ok
%% @param Module module to set the native code of
Expand Down Expand Up @@ -164,13 +173,17 @@ load(Module) ->
code_server:literal_resolver(Module, Index)
end,
TypeResolver = fun(Index) -> code_server:type_resolver(Module, Index) end,
ImportResolver = fun(Index) ->
code_server:import_resolver(Module, Index)
end,
{StreamModule, Stream0} = jit:stream(jit_mmap_size(byte_size(Code))),
{BackendModule, BackendState0} = jit:backend(StreamModule, Stream0),
{LabelsCount, BackendState1} = jit:compile(
Code,
AtomResolver,
LiteralResolver,
TypeResolver,
ImportResolver,
BackendModule,
BackendState0
),
Expand Down
Loading
Loading