Formular.Compiler (formular v0.4.1)

This module is used to compile the code into Elixir modules.

Link to this section Summary

Functions

Create an Elixir module from the raw code (AST).

Link to this section Functions

Link to this function

create_module(module, raw_ast, env \\ %Macro.Env{})

Specs

create_module(module(), Macro.t(), Macro.Env.t()) :: {:module, module()}

Create an Elixir module from the raw code (AST).

The created module will have to public functions:

  • run/1 which accepts a binding keyword list and execute the code.
  • used_variables/0 which returns a list of variable names that have been used in the code.

Usage

iex> ast = quote do: a + b
...> Formular.Compiler.create_module(MyMod, ast)
...> MyMod.run(a: 1, b: 2)
3

...> MyMod.used_variables()
[:a, :b]