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

Summary

Functions

Aggregates function clauses from a module definition.

Returns Hologram IR for the given Elixir source code.

Returns Hologram IR of the given module. Specifying the module's BEAM path makes the call faster.

Returns Hologram IR for the given Elixir term. If the term can be represented in IR then its value is returned in the shape of {:ok, ir}. If the term can't be represented in IR then an error message is returned in the shape of {:error, message}.

Returns Hologram IR for the given Elixir term, erroring out if the term can't be represented in IR.

Types

t()

@type t() ::
  Hologram.Compiler.IR.AnonymousFunctionCall.t()
  | Hologram.Compiler.IR.AnonymousFunctionType.t()
  | Hologram.Compiler.IR.AtomType.t()
  | Hologram.Compiler.IR.BitstringSegment.t()
  | Hologram.Compiler.IR.BitstringType.t()
  | Hologram.Compiler.IR.Block.t()
  | Hologram.Compiler.IR.Case.t()
  | Hologram.Compiler.IR.Clause.t()
  | Hologram.Compiler.IR.Comprehension.t()
  | Hologram.Compiler.IR.ComprehensionFilter.t()
  | Hologram.Compiler.IR.Cond.t()
  | Hologram.Compiler.IR.CondClause.t()
  | Hologram.Compiler.IR.ConsOperator.t()
  | Hologram.Compiler.IR.DotOperator.t()
  | Hologram.Compiler.IR.FloatType.t()
  | Hologram.Compiler.IR.FunctionClause.t()
  | Hologram.Compiler.IR.FunctionDefinition.t()
  | Hologram.Compiler.IR.IgnoredExpression.t()
  | Hologram.Compiler.IR.IntegerType.t()
  | Hologram.Compiler.IR.ListType.t()
  | Hologram.Compiler.IR.LocalFunctionCall.t()
  | Hologram.Compiler.IR.MapType.t()
  | Hologram.Compiler.IR.MatchOperator.t()
  | Hologram.Compiler.IR.MatchPlaceholder.t()
  | Hologram.Compiler.IR.ModuleAttributeOperator.t()
  | Hologram.Compiler.IR.ModuleDefinition.t()
  | Hologram.Compiler.IR.PIDType.t()
  | Hologram.Compiler.IR.PinOperator.t()
  | Hologram.Compiler.IR.PortType.t()
  | Hologram.Compiler.IR.ReferenceType.t()
  | Hologram.Compiler.IR.RemoteFunctionCall.t()
  | Hologram.Compiler.IR.StringType.t()
  | Hologram.Compiler.IR.Try.t()
  | Hologram.Compiler.IR.TryCatchClause.t()
  | Hologram.Compiler.IR.TryRescueClause.t()
  | Hologram.Compiler.IR.TupleType.t()
  | Hologram.Compiler.IR.Variable.t()
  | Hologram.Compiler.IR.With.t()

Functions

aggregate_module_funs(module_def)

@spec aggregate_module_funs(Hologram.Compiler.IR.ModuleDefinition.t()) :: [
  {{atom(), non_neg_integer()},
   {:public | :private, [Hologram.Compiler.IR.FunctionClause.t()]}}
]

Aggregates function clauses from a module definition.

Returns

A list, where each item is in the format: {{function_name, arity}, {visibility, [clause_1, clause_2, ...]}}

Example

iex> module_def = %ModuleDefinition{...}
iex> aggregate_module_funs(module_def)
[
  {{:my_function_1, 3}, {:public, [%IR.FunctionClause{...}, %IR.FunctionClause{...}]}},
  {{:my_function_2, 1}, {:private, [%IR.FunctionClause{...}]}}
]

for_code(code, context)

@spec for_code(binary(), Hologram.Compiler.Context.t()) :: t()

Returns Hologram IR for the given Elixir source code.

Examples

iex> for_code("my_fun(1, 2)")
%IR.LocalFunctionCall{function: :my_fun, args: [%IR.IntegerType{value: 1}, %IR.IntegerType{value: 2}]}

for_module(module, beam_path \\ nil)

@spec for_module(module(), charlist() | nil) :: t()

Returns Hologram IR of the given module. Specifying the module's BEAM path makes the call faster.

Examples

iex> for_module(MyModule)
%IR.ModuleDefinition{module: MyModule, body: %IR.Block{expressions: [...]}}

for_term(term)

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

Returns Hologram IR for the given Elixir term. If the term can be represented in IR then its value is returned in the shape of {:ok, ir}. If the term can't be represented in IR then an error message is returned in the shape of {:error, message}.

Examples

iex> my_var = 123
iex> for_term(my_var)
{:ok, %IR.IntegerType{value: 123}}

for_term!(term)

@spec for_term!(any()) :: t()

Returns Hologram IR for the given Elixir term, erroring out if the term can't be represented in IR.

Examples

iex> my_var = 123
iex> for_term!(my_var)
%IR.IntegerType{value: 123}