Issues when compiling LFE

69 views
Skip to first unread message

Robert Virding

unread,
Jan 8, 2018, 7:42:12 PM1/8/18
to Lisp Flavoured Erlang
This is something which has been discussed in the irc and I mentioned in slack so I thought I would talk about here as well.

So LFE has always been compiled down not to erlang AST but to core erlang which is an internal language used in the compiler. However you can get the erlang compiler to take core erlang as input. Core is a more "normal" functional language and compiling LFE to it is generally quite straightforward. BUT the exact internal semantics of core is not well defined so it has sometimes been a bit tricky to work out what the exact core should be. And it can change between erlang releases.

Because of issues when compiling LFE to core erlang  I have been looking at compiling it to erlang AST instead. In some ways this is easier as erlang and its AST are much better defined. But there are some difficulties.

I wish I could mix as there are only some things which are tricky in core and some others which are tricky in erlang AST. The trickiest is getting the multi argument arithmetic, comparison and logic functions efficient. Yes, you can write (+ (a) (b) (c) (d)) and the same for comparisons and logic. In the current version these are macros and expanded into a 'let' where the body is the nested binary calls to the erlang bifs. Easy. This also works in guards as restricted lets are allowed in core erlang.

However this does not work as well in erlang as binding variables is not allowed in guards. The main problem is the =/= and /= operators where (=/= a b c d e) tests that none of the arguments are equal. So this expands in multiple tests where every argument is compared to every other arguments. This is very inefficient if the arguments have to be recalculated for every test, which they have to be done in guards as erlang does not permit binding variables in guards.

So both versions more or less work now and I haven't decided which one to go with. We will see where we end up.

Robert

Duncan McGreggor

unread,
Jan 12, 2018, 12:00:58 AM1/12/18
to Lisp Flavoured Erlang
Nice -- thanks for the summary, Robert!

d



--
You received this message because you are subscribed to the Google Groups "Lisp Flavoured Erlang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lisp-flavoured-erlang+unsub...@googlegroups.com.
To post to this group, send email to lisp-flavoured-erlang@googlegroups.com.
Visit this group at https://groups.google.com/group/lisp-flavoured-erlang.
For more options, visit https://groups.google.com/d/optout.

Robert Virding

unread,
Jan 21, 2018, 5:39:57 AM1/21/18
to Lisp Flavoured Erlang
I have now pushed the first version of LFE which compiles to the erlang AST. It is in the branch erlang-ast. It is not finished but most things work and is definitely at the stage for doing serious testing. Please test this and tell me how it goes and what doesn't yet work. When we see how it goes I decide whether this is the way to go.

Please note that you will probably end up with more warnings as we pass the code through the erlang linter as well. When compiling the eunit tests you will get warnings about re-exporting the test functions. This comes from the explicit export in the deftest macro and parse transform in eunit.hrl file. Yes, we have parse transforms.

The ms_transform_SUITE doesn't work yet but I will fix that in the next push.

So please test.

Robert
Reply all
Reply to author
Forward
0 new messages