View Source Hologram.Compiler.Encoder (hologram v0.2.0)

Summary

Functions

Prints debug info for intercepted encode_ir/2 calls.

Encodes Elixir or Erlang alias as JavaScript class name.

Encodes an Elixir function into a JavaScript statement.

Extracts JavaScript source code for the given ported Erlang function and generates interpreter function definition JavaScript statetement.

Encodes Elixir IR to JavaScript source code.

Encodes Elixir term into JavaScript. If the term can be encoded into JavaScript then the result is in the shape of {:ok, js}. If the term can't be encoded into JavaScript then an error message is returned in the shape of {:error, message}.

Encodes Elixir term into JavaScript, erroring out if the term can't be encoded into JavaScript.

Functions

debug(arg, result, start_timestamp)

@spec debug(
  {module(), atom(),
   [Hologram.Compiler.IR.t() | Hologram.Compiler.Context.t()]},
  String.t() | %FunctionClauseError{},
  integer()
) :: :ok

Prints debug info for intercepted encode_ir/2 calls.

encode_as_class_name(alias_atom)

@spec encode_as_class_name(module() | atom()) :: String.t()

Encodes Elixir or Erlang alias as JavaScript class name.

Examples

iex> encode_as_class_name(Aaa.Bbb.Ccc)
"Elixir_Aaa_Bbb_Ccc"

iex> encode_as_class_name(:erlang)
"Erlang"

iex> encode_as_class_name(:aaa_bbb)
"Erlang_Aaa_Bbb"      

encode_elixir_function(module_name, function, arity, visibility, clauses, context)

@spec encode_elixir_function(
  String.t(),
  atom(),
  non_neg_integer(),
  :public | :private,
  [Hologram.Compiler.IR.FunctionClause.t()],
  Hologram.Compiler.Context.t()
) :: String.t()

Encodes an Elixir function into a JavaScript statement.

encode_erlang_function(module, function, arity, erlang_source_dir)

@spec encode_erlang_function(module(), atom(), integer(), String.t()) :: String.t()

Extracts JavaScript source code for the given ported Erlang function and generates interpreter function definition JavaScript statetement.

encode_ir(ir, context)

Encodes Elixir IR to JavaScript source code.

Examples

iex> ir = %IR.ListType{
...>   data: [
...>     %IR.IntegerType{value: 1},
...>     %IR.AtomType{value: :abc}
...>   ]
...> }
iex> encode_ir(ir, %Context{})
"Type.list([Type.integer(1), Type.atom("abc")])"

encode_term(term)

@spec encode_term(any()) :: {:ok, String.t()} | {:error, String.t()}

Encodes Elixir term into JavaScript. If the term can be encoded into JavaScript then the result is in the shape of {:ok, js}. If the term can't be encoded into JavaScript then an error message is returned in the shape of {:error, message}.

encode_term!(term)

@spec encode_term!(any()) :: String.t()

Encodes Elixir term into JavaScript, erroring out if the term can't be encoded into JavaScript.