The document describes the compilation process of Erlang code to Core Erlang and machine code. It begins with Erlang source code, which is passed through a scanner, parser and various optimizations to produce an intermediate representation in Core Erlang. Core Erlang code is then passed through additional optimizations to produce Erlang Abstract Syntax Machine (ASM) code. The ASM code is finally compiled to machine code. Core Erlang is designed to be a target language for compilers with a simple, functional semantics to facilitate code analysis tools. Joxa code also compiles to Core Erlang through a similar process.
13. Core Erlang
Designed as a ‘target language’ for compilers
Strict, higher-order functional language with clear and simple
semantics
Should be as regular as possible to facilitate development of code
walking tools
Translation from Erlang to Core Erlang should be as
straightforward
Should have a human readable textual representation
Monday, June 3, 13
14. Core - The Language Designer
Erlang compiles to core erlang!
Almost all the optimizations and error checking are in the core
Erlang passes!
Core Erlang as a nice ast building module in cerl.erl
Its easy to target!
Monday, June 3, 13
20. What is Joxa
Designed as a Simple, Functional, Lisp (though not as a
Common Lisp)
Designed to be a general purpose, usable language in its own
right
Also designed to be a platform for DSLs
Monday, June 3, 13
21. What is Joxa’s Status
Still many features we want to implement
Better Joxa Layer Warnings
More metadata (apropo, live arguments)
Support for Slime + Swank
Production Quality
Monday, June 3, 13
23. A Quick Intro - Macros
(defmacro+ and (&rest args)
(case args
([x y]
`(erlang/and ~x ~y))
((a . b)
`(erlang/and ~a (joxa-core/and ~@b)))
(arg
arg)))
(defmacro+ or (&rest args)
(case args
([x y]
`(erlang/or ~x ~y))
((a . b)
`(erlang/or ~a (joxa-core/and ~@b)))
(arg
arg)))
Monday, June 3, 13
24. ;; Apply the body to every item in the list. The 'value' part of an
;; expression may be a pattern. If the pattern does not match then
;; the non-matching element is skipped
;; Without Guard
;; (dolist (x (lists/seq 0 1)) (+ x 1))
;; With Guard
;; (dolist (x (when (> x 1)) (lists/seq 0 10)) (+ x 1))
;;
(defmacro+ dolist (binding &rest body)
(case binding
([val items]
(let* (arg (joxa-core/gensym "doseq"))
`(lists/foreach
(fn (~arg)
(case ~arg
~@(if (needs-catchall? val)
[`(~val
~@body) `(_ :ok)]
[`(~val
~@body)]))) ~items)))
([val guard items]
(let* (arg (joxa-core/gensym "dolist"))
`(lists/foreach
(fn (~arg)
(case ~arg
(~val ~guard
~@body)
(_ :ok))) ~items)))
(invalid
(erlang/error {:invalid-binding invalid }))))
Monday, June 3, 13
25. ;; Apply the body to every item in the list. The 'value' part of an
;; expression may be a pattern. If the pattern does not match then
;; the non-matching element is skipped, The result of each body is
;; cated to the list and returned as a new list
;; Without Guard
;; (joxa-lists/map (x (lists/seq 0 1)) (+ x 1))
;; With Guard
;; (joxa-lists/map (x (> x 1) (lists/seq 0 10)) (+ x 1))
(defmacro+ map (binding &rest body)
(let* (catcher (joxa-core/gensym "map")
acc-sym (joxa-core/gensym "map")
arg (joxa-core/gensym "map")
body-gen <BODY GEN SEE ->
(case (body-gen binding)
({fun-body items}
`(lists/reverse
(lists/foldl
(fn (~arg ~acc-sym)
~fun-body) [] ~items))))))
BODY GEN:
(fn (binding1)
(case binding1
([val items]
{`(case ~arg
~@(if (needs-catchall? val)
[`(~val
((do ~@body) . ~acc-sym))
`(_ ~acc-sym)]
[`(~val
((do ~@body) . ~acc-sym))])) items})
([val guard items]
{`(case ~arg
~@(if (needs-catchall? val)
[`(~val
(case ~guard
(:true ((do ~@body) . ~acc-sym))
(:false ~acc-sym))
((do ~@body) . ~acc-sym))
`(_ ~acc-sym)]
[`(~val
(case ~guard
(:true ((do ~@body) . ~acc-sym))
(:false ~acc-sym)))])) items})
(invalid
(erlang/error {:invalid-binding invalid })))))
Monday, June 3, 13
26. Records
Provide a unit of abstraction around Erlang’s record syntax
Getters, Setters, Pattern Decomposition Generated
Much, Much prettier then Erlang Records
Monday, June 3, 13