Configuring a Mix compiler for LFE

215 views
Skip to first unread message

Kip Cole

unread,
May 22, 2016, 6:17:42 AM5/22/16
to elixir-lang-talk
I've mostly got LFE (Lisp Flavoured Erlang) running in a mix project as a dependency but I haven't got the compiling phase right.  I've configured the compiler and created the mix task.  Now I'm looking for some help on how to:
1.  Manage file change detection (looks like theres some kind of manifest api but I'm not understanding it)
2.  The mix task for compilation works (mostly) but it doesn't appear to be invoked with iex starts up with iex -S mix

Any suggestions?  My simple compiler task follows:

defmodule Mix.Tasks.Compile.Lfe do
  use Mix.Task

  @recursive true
  @manifest ".compile.lfe"

  @moduledoc """
  Force Lisp Flavored Erlang (lfe) modules to recompile
  """

  def run(_, source_dir \\ "src") do
    _ = Mix.Project.get!
    _app_dir = Mix.Project.app_path()

    source_dir
    |> Path.join("**/*.lfe")
    |> Path.wildcard()
    |> Enum.each(fn source ->
      IO.puts "Compiling #{inspect source}"
      :lfe_comp.file String.to_charlist(source)
    end)
    :ok
  end
  
  @doc """
  Returns Lfe manifests.
  """
  def manifests, do: [manifest]
  defp manifest, do: Path.join(Mix.Project.manifest_path, @manifest)
end

José Valim

unread,
May 22, 2016, 7:22:56 AM5/22/16
to elixir-l...@googlegroups.com
You should check how the compilers for Erlang and Yecc/Leex are implemented in Mix source. In the best scenario, it will be as simple as the Yecc/Leex one. In the worst scenario, as complex as the Erlang one.



José Valim
Skype: jv.ptec
Founder and Director of R&D

--
You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-ta...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-talk/8c267ef1-471f-4b7a-9d56-40f40dc43654%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Robert Virding

unread,
May 23, 2016, 4:00:40 AM5/23/16
to elixir-lang-talk, jose....@plataformatec.com.br
I can't help you on the mix side, though I am very interested in the results.

About the LFE compiler: its interface is very erlang compiler-like on how you call it and the options; a file can contain multiple modules so the return is a list of module information. This means that there is no direct coupling between the LFE file name and the modules generated. I don't know if mix supports this type of file/module handling directly. Elixir has the same feature so I would guess it does.

I am also very interested to know which parts you wrote in LFE.

Robert

José Valim

unread,
May 23, 2016, 4:21:36 AM5/23/16
to Robert Virding, elixir-lang-talk
Thank you Robert!

Mix already knows how to compile Erlang. The only complexity in the Erlang compiler is in tracking the .hrl files. Do we need to implement the same for the .lfe compiler? How does a LFE module "include" another module because it may need to use its macros?

José Valim
Skype: jv.ptec
Founder and Director of R&D

Robert Virding

unread,
May 23, 2016, 5:37:54 AM5/23/16
to elixir-lang-talk, rvir...@gmail.com, jose....@plataformatec.com.br
Yes, the LFE compiler includes files in pretty much the same way as the Erlang compiler. It can handle both LFE include files with the extension .lfe and Erlang .hrl files. The use is pretty much the same as in Erlang to define macros and records. So you would need to be able to track these.

We are *slowly* migrating away from this towards what I call "compile time macros". In these the macro call looks like a "normal" remote module call but the compiler checks at macro expansion if this function called is really a macro, if so it is expanded. It looks really strange doing function calls in a pattern. :-) The only requirement is that the module defining the macros is already compiled, and exports the macros. There is currently no way to check if a macro is exported from a module without trying to expand it.

There is also a wonderful hack where macros can be expanded at run-time as well. But this does not affect compiling.

Robert

José Valim

unread,
May 23, 2016, 5:41:16 AM5/23/16
to Robert Virding, elixir-lang-talk
Yes, the LFE compiler includes files in pretty much the same way as the Erlang compiler. It can handle both LFE include files with the extension .lfe and Erlang .hrl files. The use is pretty much the same as in Erlang to define macros and records. So you would need to be able to track these.

That's really helpful. So the LFE compiler for Mix has two options here. Pre-parse the .lfe files to find the includes (similar to how we do with Erlang) or have a configuration option which tells which modules must be compiled first.

Kip Cole

unread,
May 23, 2016, 5:59:16 AM5/23/16
to elixir-l...@googlegroups.com, Robert Virding
Thanks for the guidance gentlemen, I'll probably not get back to this until the weekend.

Robert, and working to migration the Calendrical Calculations code from CL to efl.  Am really enjoying effort but some ways to go.

My project will leverage this code to support a flexible calendaring system (hoping to leverage the Calendar behaviour in Elixirr 1.3).

In parallel also using leex/yecc and Erlang to parse cldr files for locale specific formatting.  And elixir for the business logic.

It's a great platform where all of these play so well together.

Thanks to you both for making it possible - and fun.

Cheers, Kip

Sent from my iPhone
You received this message because you are subscribed to a topic in the Google Groups "elixir-lang-talk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elixir-lang-talk/4TMtr8WJjwQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to elixir-lang-ta...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-talk/CAGnRm4Lc9DGwwFyh2HO1_i01qYFeN%2B5jumUkeuqt74QBnxx3Pw%40mail.gmail.com.

dead.tr...@gmail.com

unread,
Jun 3, 2016, 6:17:04 PM6/3/16
to elixir-lang-talk
Hey, any progress so far? 

Kip Cole

unread,
Jun 3, 2016, 8:49:02 PM6/3/16
to elixir-l...@googlegroups.com
Hi, no, not yet (well basic compilation on iex-S mix startup but no dependency checking or reloading yet.  Still finishing some other work until I can get back to this.  Probably a couple of weeks away.  I'll post in the group when I make more progress.

Louis Pilfold

unread,
Jun 4, 2016, 6:01:39 AM6/4/16
to elixir-lang-talk

That's great to hear! That you for your work so far :)

Reply all
Reply to author
Forward
0 new messages