summaryrefslogtreecommitdiffstats
path: root/articles/xerl-0.2-two-modules/index.html
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2017-10-03 13:39:41 +0200
committerLoïc Hoguin <[email protected]>2017-10-03 13:39:41 +0200
commitb5d4cb91f80c833795a2d87050c3674bb7aecdc5 (patch)
tree62bf0ad8326006fcd3407fcb7c34c844c0dc0874 /articles/xerl-0.2-two-modules/index.html
parent1f8d51dd2692fc3978080419987bbe4d49a41a90 (diff)
downloadninenines.eu-b5d4cb91f80c833795a2d87050c3674bb7aecdc5.tar.gz
ninenines.eu-b5d4cb91f80c833795a2d87050c3674bb7aecdc5.tar.bz2
ninenines.eu-b5d4cb91f80c833795a2d87050c3674bb7aecdc5.zip
Update Hugo, docs
Diffstat (limited to 'articles/xerl-0.2-two-modules/index.html')
-rw-r--r--articles/xerl-0.2-two-modules/index.html390
1 files changed, 221 insertions, 169 deletions
diff --git a/articles/xerl-0.2-two-modules/index.html b/articles/xerl-0.2-two-modules/index.html
index 632248a0..279aaa23 100644
--- a/articles/xerl-0.2-two-modules/index.html
+++ b/articles/xerl-0.2-two-modules/index.html
@@ -7,7 +7,7 @@
<meta name="description" content="">
<meta name="author" content="Loïc Hoguin based on a design from (Soft10) Pol Cámara">
- <meta name="generator" content="Hugo 0.17" />
+ <meta name="generator" content="Hugo 0.26" />
<title>Nine Nines: Xerl: two modules</title>
@@ -74,149 +74,149 @@
</p>
</header>
-<div class="paragraph"><p>Everything is an expression.</p></div>
-<div class="paragraph"><p>This sentence carries profound meaning. We will invoke it many
-times over the course of these articles.</p></div>
-<div class="paragraph"><p>If everything is an expression, then the language shouldn&#8217;t have
-any problem with me defining two modules in the same source file.</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="color: #FF6600">mod</span> <span style="color: #FF6600">first_module</span>
-<span style="font-weight: bold"><span style="color: #0000FF">begin</span></span>
-<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
-
-<span style="color: #FF6600">mod</span> <span style="color: #FF6600">second_module</span>
-<span style="font-weight: bold"><span style="color: #0000FF">begin</span></span>
-<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
-<div class="paragraph"><p>Likewise, it shouldn&#8217;t have any problem with me defining a
-module inside another module.</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="color: #FF6600">mod</span> <span style="color: #FF6600">out_module</span>
-<span style="font-weight: bold"><span style="color: #0000FF">begin</span></span>
- <span style="color: #FF6600">mod</span> <span style="color: #FF6600">in_module</span>
- <span style="font-weight: bold"><span style="color: #0000FF">begin</span></span>
- <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
-<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
-<div class="paragraph"><p>Of course, in the context of the Erlang VM, these two snippets
-are equivalent; there is nothing preventing you from calling the
-<code>in_module</code> module from any other module. The <code>mod</code>
-instruction means a module should be created in the Erlang VM,
-with no concept of scope attached.</p></div>
-<div class="paragraph"><p>Still we need to handle both. To do this we will add a step
-between the parser and the code generator that will walk over the
-abstract syntax tree, from here onward shortened as <em>AST</em>,
-and transform the AST by executing it where applicable.</p></div>
-<div class="paragraph"><p>What happens when you execute a <code>mod</code> instruction?
-A module is created. Since we are compiling, that simply means
-the compiler will branch out and create a module.</p></div>
-<div class="paragraph"><p>If everything is an expression, does that mean this will allow
-me to create modules at runtime using the same syntax? Yes, but
-let&#8217;s not get ahead of ourselves yet.</p></div>
-<div class="paragraph"><p>For now we will just iterate over the AST, and will compile
-a module for each <code>mod</code> found. Modules cannot contain
-expressions yet, so there&#8217;s no need to recurse over it at this
-point. This should solve the compilation of our first snippet.</p></div>
-<div class="paragraph"><p>The <code>compile/1</code> function becomes:</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="font-weight: bold"><span style="color: #000000">compile</span></span>(<span style="color: #009900">Filename</span>) <span style="color: #990000">-&gt;</span>
- <span style="font-weight: bold"><span style="color: #000000">io:format</span></span>(<span style="color: #FF0000">"Compiling ~s...~n"</span>, [<span style="color: #009900">Filename</span>]),
- {<span style="color: #FF6600">ok</span>, <span style="color: #009900">Src</span>} <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">file:read_file</span></span>(<span style="color: #009900">Filename</span>),
- {<span style="color: #FF6600">ok</span>, <span style="color: #009900">Tokens</span>, <span style="color: #990000">_</span>} <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">xerl_lexer:string</span></span>(<span style="font-weight: bold"><span style="color: #000080">binary_to_list</span></span>(<span style="color: #009900">Src</span>)),
- {<span style="color: #FF6600">ok</span>, <span style="color: #009900">Exprs</span>} <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">xerl_parser:parse</span></span>(<span style="color: #009900">Tokens</span>),
- <span style="font-weight: bold"><span style="color: #000000">execute</span></span>(<span style="color: #009900">Filename</span>, <span style="color: #009900">Exprs</span>, [])<span style="color: #990000">.</span>
-
-<span style="font-weight: bold"><span style="color: #000000">execute</span></span>(<span style="color: #990000">_</span>, [], <span style="color: #009900">Modules</span>) <span style="color: #990000">-&gt;</span>
- <span style="font-weight: bold"><span style="color: #000000">io:format</span></span>(<span style="color: #FF0000">"Done...~n"</span>),
- {<span style="color: #FF6600">ok</span>, <span style="font-weight: bold"><span style="color: #000000">lists:reverse</span></span>(<span style="color: #009900">Modules</span>)};
-<span style="font-weight: bold"><span style="color: #000000">execute</span></span>(<span style="color: #009900">Filename</span>, [<span style="color: #009900">Expr</span> <span style="color: #990000">=</span> {<span style="color: #FF6600">mod</span>, <span style="color: #990000">_</span>, {<span style="font-weight: bold"><span style="color: #000080">atom</span></span>, <span style="color: #990000">_</span>, <span style="color: #009900">Name</span>}, []}|<span style="color: #009900">Tail</span>], <span style="color: #009900">Modules</span>) <span style="color: #990000">-&gt;</span>
- {<span style="color: #FF6600">ok</span>, [<span style="color: #009900">Core</span>]} <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">xerl_codegen:exprs</span></span>([<span style="color: #009900">Expr</span>]),
- {<span style="color: #FF6600">ok</span>, [{<span style="color: #009900">Name</span>, []}]} <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">core_lint:module</span></span>(<span style="color: #009900">Core</span>),
- <span style="font-weight: bold"><span style="color: #000000">io:format</span></span>(<span style="color: #FF0000">"~s~n"</span>, [<span style="font-weight: bold"><span style="color: #000000">core_pp:format</span></span>(<span style="color: #009900">Core</span>)]),
- {<span style="color: #FF6600">ok</span>, <span style="color: #990000">_</span>, <span style="color: #009900">Beam</span>} <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">compile:forms</span></span>(<span style="color: #009900">Core</span>,
- [<span style="font-weight: bold"><span style="color: #000080">binary</span></span>, <span style="color: #FF6600">from_core</span>, <span style="color: #FF6600">return_errors</span>, {<span style="color: #FF6600">source</span>, <span style="color: #009900">Filename</span>}]),
- {<span style="color: #FF6600">module</span>, <span style="color: #009900">Name</span>} <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">code:load_binary</span></span>(<span style="color: #009900">Name</span>, <span style="color: #009900">Filename</span>, <span style="color: #009900">Beam</span>),
- <span style="font-weight: bold"><span style="color: #000000">execute</span></span>(<span style="color: #009900">Filename</span>, <span style="color: #009900">Tail</span>, [<span style="color: #009900">Name</span>|<span style="color: #009900">Modules</span>])<span style="color: #990000">.</span></tt></pre></div></div>
-<div class="paragraph"><p>Running this compiler over the first snippet yields the following
-result:</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="color: #009900">Compiling</span> <span style="font-weight: bold"><span style="color: #000000">test</span></span><span style="color: #990000">/</span><span style="font-weight: bold"><span style="color: #000000">mod_SUITE_data</span></span><span style="color: #990000">/</span><span style="color: #FF6600">two_modules</span><span style="color: #990000">.</span><span style="color: #FF6600">xerl</span><span style="color: #990000">...</span>
-<span style="color: #FF6600">module</span> <span style="color: #FF6600">'first_module'</span> [<span style="color: #FF6600">'module_info'</span><span style="color: #990000">/</span><span style="color: #993399">0</span>,
- <span style="color: #FF6600">'module_info'</span><span style="color: #990000">/</span><span style="color: #993399">1</span>]
- <span style="color: #FF6600">attributes</span> []
-<span style="color: #FF6600">'module_info'</span><span style="color: #990000">/</span><span style="color: #993399">0</span> <span style="color: #990000">=</span>
- <span style="font-weight: bold"><span style="color: #0000FF">fun</span></span> () <span style="color: #990000">-&gt;</span>
- <span style="font-weight: bold"><span style="color: #000080">call</span></span> <span style="color: #FF6600">'erlang'</span><span style="color: #990000">:</span><span style="color: #FF6600">'get_module_info'</span>
- (<span style="color: #FF6600">'first_module'</span>)
-<span style="color: #FF6600">'module_info'</span><span style="color: #990000">/</span><span style="color: #993399">1</span> <span style="color: #990000">=</span>
- <span style="font-weight: bold"><span style="color: #0000FF">fun</span></span> (<span style="color: #009900">Key</span>) <span style="color: #990000">-&gt;</span>
- <span style="font-weight: bold"><span style="color: #000080">call</span></span> <span style="color: #FF6600">'erlang'</span><span style="color: #990000">:</span><span style="color: #FF6600">'get_module_info'</span>
- (<span style="color: #FF6600">'first_module'</span>, <span style="color: #009900">Key</span>)
-<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
-<span style="color: #FF6600">module</span> <span style="color: #FF6600">'second_module'</span> [<span style="color: #FF6600">'module_info'</span><span style="color: #990000">/</span><span style="color: #993399">0</span>,
- <span style="color: #FF6600">'module_info'</span><span style="color: #990000">/</span><span style="color: #993399">1</span>]
- <span style="color: #FF6600">attributes</span> []
-<span style="color: #FF6600">'module_info'</span><span style="color: #990000">/</span><span style="color: #993399">0</span> <span style="color: #990000">=</span>
- <span style="font-weight: bold"><span style="color: #0000FF">fun</span></span> () <span style="color: #990000">-&gt;</span>
- <span style="font-weight: bold"><span style="color: #000080">call</span></span> <span style="color: #FF6600">'erlang'</span><span style="color: #990000">:</span><span style="color: #FF6600">'get_module_info'</span>
- (<span style="color: #FF6600">'second_module'</span>)
-<span style="color: #FF6600">'module_info'</span><span style="color: #990000">/</span><span style="color: #993399">1</span> <span style="color: #990000">=</span>
- <span style="font-weight: bold"><span style="color: #0000FF">fun</span></span> (<span style="color: #009900">Key</span>) <span style="color: #990000">-&gt;</span>
- <span style="font-weight: bold"><span style="color: #000080">call</span></span> <span style="color: #FF6600">'erlang'</span><span style="color: #990000">:</span><span style="color: #FF6600">'get_module_info'</span>
- (<span style="color: #FF6600">'second_module'</span>, <span style="color: #009900">Key</span>)
-<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
-<span style="color: #009900">Done</span><span style="color: #990000">...</span>
-{<span style="color: #FF6600">ok</span>,[<span style="color: #FF6600">first_module</span>,<span style="color: #FF6600">second_module</span>]}</tt></pre></div></div>
-<div class="paragraph"><p>Everything looks fine. And we can check that the two modules have
-been loaded into the VM:</p></div>
-<div class="listingblock">
-<div class="content"><!-- Generator: GNU source-highlight 3.1.8
-by Lorenzo Bettini
-http://www.lorenzobettini.it
-http://www.gnu.org/software/src-highlite -->
-<pre><tt><span style="color: #993399">9</span><span style="color: #990000">&gt;</span> <span style="color: #FF6600">m</span>(<span style="color: #FF6600">first_module</span>)<span style="color: #990000">.</span>
-<span style="color: #009900">Module</span> <span style="color: #FF6600">first_module</span> <span style="color: #FF6600">compiled</span><span style="color: #990000">:</span> <span style="color: #009900">Date</span><span style="color: #990000">:</span> <span style="color: #009900">February</span> <span style="color: #993399">2</span> <span style="color: #993399">2013</span>, <span style="color: #009900">Time</span><span style="color: #990000">:</span> <span style="color: #993399">14.56</span>
-<span style="color: #009900">Compiler</span> <span style="color: #FF6600">options</span><span style="color: #990000">:</span> [<span style="color: #FF6600">from_core</span>]
-<span style="color: #009900">Object</span> <span style="font-weight: bold"><span style="color: #000000">file: test</span></span><span style="color: #990000">/</span><span style="font-weight: bold"><span style="color: #000000">mod_SUITE_data</span></span><span style="color: #990000">/</span><span style="color: #FF6600">two_modules</span><span style="color: #990000">.</span><span style="color: #FF6600">xerl</span>
-<span style="color: #009900">Exports</span><span style="color: #990000">:</span>
- <span style="font-weight: bold"><span style="color: #000080">module_info</span></span><span style="color: #990000">/</span><span style="color: #993399">0</span>
- <span style="font-weight: bold"><span style="color: #000080">module_info</span></span><span style="color: #990000">/</span><span style="color: #993399">1</span>
-<span style="color: #FF6600">ok</span>
-<span style="color: #993399">10</span><span style="color: #990000">&gt;</span> <span style="color: #FF6600">m</span>(<span style="color: #FF6600">second_module</span>)<span style="color: #990000">.</span>
-<span style="color: #009900">Module</span> <span style="color: #FF6600">second_module</span> <span style="color: #FF6600">compiled</span><span style="color: #990000">:</span> <span style="color: #009900">Date</span><span style="color: #990000">:</span> <span style="color: #009900">February</span> <span style="color: #993399">2</span> <span style="color: #993399">2013</span>, <span style="color: #009900">Time</span><span style="color: #990000">:</span> <span style="color: #993399">14.56</span>
-<span style="color: #009900">Compiler</span> <span style="color: #FF6600">options</span><span style="color: #990000">:</span> [<span style="color: #FF6600">from_core</span>]
-<span style="color: #009900">Object</span> <span style="font-weight: bold"><span style="color: #000000">file: test</span></span><span style="color: #990000">/</span><span style="font-weight: bold"><span style="color: #000000">mod_SUITE_data</span></span><span style="color: #990000">/</span><span style="color: #FF6600">two_modules</span><span style="color: #990000">.</span><span style="color: #FF6600">xerl</span>
-<span style="color: #009900">Exports</span><span style="color: #990000">:</span>
- <span style="font-weight: bold"><span style="color: #000080">module_info</span></span><span style="color: #990000">/</span><span style="color: #993399">0</span>
- <span style="font-weight: bold"><span style="color: #000080">module_info</span></span><span style="color: #990000">/</span><span style="color: #993399">1</span>
-<span style="color: #FF6600">ok</span></tt></pre></div></div>
-<div class="paragraph"><p>So far so good!</p></div>
-<div class="paragraph"><p>What about the second snippet? It brings up many questions. What
-happens once a <code>mod</code> expression has been executed at
-compile time? If it&#8217;s an expression then it has to have a result,
-right? Right. We are still a bit lacking with expressions for now,
-though, so let&#8217;s get back to it after we add more.</p></div>
-<div class="ulist"><ul>
-<li>
-<p>
-<a href="https://github.com/extend/xerl/blob/0.2/">View the source</a>
-</p>
-</li>
-</ul></div>
+<div class="paragraph"><p>Everything is an expression.</p></div>
+<div class="paragraph"><p>This sentence carries profound meaning. We will invoke it many
+times over the course of these articles.</p></div>
+<div class="paragraph"><p>If everything is an expression, then the language shouldn&#8217;t have
+any problem with me defining two modules in the same source file.</p></div>
+<div class="listingblock">
+<div class="content"><!-- Generator: GNU source-highlight 3.1.8
+by Lorenzo Bettini
+http://www.lorenzobettini.it
+http://www.gnu.org/software/src-highlite -->
+<pre><tt><span style="color: #FF6600">mod</span> <span style="color: #FF6600">first_module</span>
+<span style="font-weight: bold"><span style="color: #0000FF">begin</span></span>
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
+
+<span style="color: #FF6600">mod</span> <span style="color: #FF6600">second_module</span>
+<span style="font-weight: bold"><span style="color: #0000FF">begin</span></span>
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
+<div class="paragraph"><p>Likewise, it shouldn&#8217;t have any problem with me defining a
+module inside another module.</p></div>
+<div class="listingblock">
+<div class="content"><!-- Generator: GNU source-highlight 3.1.8
+by Lorenzo Bettini
+http://www.lorenzobettini.it
+http://www.gnu.org/software/src-highlite -->
+<pre><tt><span style="color: #FF6600">mod</span> <span style="color: #FF6600">out_module</span>
+<span style="font-weight: bold"><span style="color: #0000FF">begin</span></span>
+ <span style="color: #FF6600">mod</span> <span style="color: #FF6600">in_module</span>
+ <span style="font-weight: bold"><span style="color: #0000FF">begin</span></span>
+ <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
+<div class="paragraph"><p>Of course, in the context of the Erlang VM, these two snippets
+are equivalent; there is nothing preventing you from calling the
+<code>in_module</code> module from any other module. The <code>mod</code>
+instruction means a module should be created in the Erlang VM,
+with no concept of scope attached.</p></div>
+<div class="paragraph"><p>Still we need to handle both. To do this we will add a step
+between the parser and the code generator that will walk over the
+abstract syntax tree, from here onward shortened as <em>AST</em>,
+and transform the AST by executing it where applicable.</p></div>
+<div class="paragraph"><p>What happens when you execute a <code>mod</code> instruction?
+A module is created. Since we are compiling, that simply means
+the compiler will branch out and create a module.</p></div>
+<div class="paragraph"><p>If everything is an expression, does that mean this will allow
+me to create modules at runtime using the same syntax? Yes, but
+let&#8217;s not get ahead of ourselves yet.</p></div>
+<div class="paragraph"><p>For now we will just iterate over the AST, and will compile
+a module for each <code>mod</code> found. Modules cannot contain
+expressions yet, so there&#8217;s no need to recurse over it at this
+point. This should solve the compilation of our first snippet.</p></div>
+<div class="paragraph"><p>The <code>compile/1</code> function becomes:</p></div>
+<div class="listingblock">
+<div class="content"><!-- Generator: GNU source-highlight 3.1.8
+by Lorenzo Bettini
+http://www.lorenzobettini.it
+http://www.gnu.org/software/src-highlite -->
+<pre><tt><span style="font-weight: bold"><span style="color: #000000">compile</span></span>(<span style="color: #009900">Filename</span>) <span style="color: #990000">-&gt;</span>
+ <span style="font-weight: bold"><span style="color: #000000">io:format</span></span>(<span style="color: #FF0000">"Compiling ~s...~n"</span>, [<span style="color: #009900">Filename</span>]),
+ {<span style="color: #FF6600">ok</span>, <span style="color: #009900">Src</span>} <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">file:read_file</span></span>(<span style="color: #009900">Filename</span>),
+ {<span style="color: #FF6600">ok</span>, <span style="color: #009900">Tokens</span>, <span style="color: #990000">_</span>} <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">xerl_lexer:string</span></span>(<span style="font-weight: bold"><span style="color: #000080">binary_to_list</span></span>(<span style="color: #009900">Src</span>)),
+ {<span style="color: #FF6600">ok</span>, <span style="color: #009900">Exprs</span>} <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">xerl_parser:parse</span></span>(<span style="color: #009900">Tokens</span>),
+ <span style="font-weight: bold"><span style="color: #000000">execute</span></span>(<span style="color: #009900">Filename</span>, <span style="color: #009900">Exprs</span>, [])<span style="color: #990000">.</span>
+
+<span style="font-weight: bold"><span style="color: #000000">execute</span></span>(<span style="color: #990000">_</span>, [], <span style="color: #009900">Modules</span>) <span style="color: #990000">-&gt;</span>
+ <span style="font-weight: bold"><span style="color: #000000">io:format</span></span>(<span style="color: #FF0000">"Done...~n"</span>),
+ {<span style="color: #FF6600">ok</span>, <span style="font-weight: bold"><span style="color: #000000">lists:reverse</span></span>(<span style="color: #009900">Modules</span>)};
+<span style="font-weight: bold"><span style="color: #000000">execute</span></span>(<span style="color: #009900">Filename</span>, [<span style="color: #009900">Expr</span> <span style="color: #990000">=</span> {<span style="color: #FF6600">mod</span>, <span style="color: #990000">_</span>, {<span style="font-weight: bold"><span style="color: #000080">atom</span></span>, <span style="color: #990000">_</span>, <span style="color: #009900">Name</span>}, []}|<span style="color: #009900">Tail</span>], <span style="color: #009900">Modules</span>) <span style="color: #990000">-&gt;</span>
+ {<span style="color: #FF6600">ok</span>, [<span style="color: #009900">Core</span>]} <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">xerl_codegen:exprs</span></span>([<span style="color: #009900">Expr</span>]),
+ {<span style="color: #FF6600">ok</span>, [{<span style="color: #009900">Name</span>, []}]} <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">core_lint:module</span></span>(<span style="color: #009900">Core</span>),
+ <span style="font-weight: bold"><span style="color: #000000">io:format</span></span>(<span style="color: #FF0000">"~s~n"</span>, [<span style="font-weight: bold"><span style="color: #000000">core_pp:format</span></span>(<span style="color: #009900">Core</span>)]),
+ {<span style="color: #FF6600">ok</span>, <span style="color: #990000">_</span>, <span style="color: #009900">Beam</span>} <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">compile:forms</span></span>(<span style="color: #009900">Core</span>,
+ [<span style="font-weight: bold"><span style="color: #000080">binary</span></span>, <span style="color: #FF6600">from_core</span>, <span style="color: #FF6600">return_errors</span>, {<span style="color: #FF6600">source</span>, <span style="color: #009900">Filename</span>}]),
+ {<span style="color: #FF6600">module</span>, <span style="color: #009900">Name</span>} <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">code:load_binary</span></span>(<span style="color: #009900">Name</span>, <span style="color: #009900">Filename</span>, <span style="color: #009900">Beam</span>),
+ <span style="font-weight: bold"><span style="color: #000000">execute</span></span>(<span style="color: #009900">Filename</span>, <span style="color: #009900">Tail</span>, [<span style="color: #009900">Name</span>|<span style="color: #009900">Modules</span>])<span style="color: #990000">.</span></tt></pre></div></div>
+<div class="paragraph"><p>Running this compiler over the first snippet yields the following
+result:</p></div>
+<div class="listingblock">
+<div class="content"><!-- Generator: GNU source-highlight 3.1.8
+by Lorenzo Bettini
+http://www.lorenzobettini.it
+http://www.gnu.org/software/src-highlite -->
+<pre><tt><span style="color: #009900">Compiling</span> <span style="font-weight: bold"><span style="color: #000000">test</span></span><span style="color: #990000">/</span><span style="font-weight: bold"><span style="color: #000000">mod_SUITE_data</span></span><span style="color: #990000">/</span><span style="color: #FF6600">two_modules</span><span style="color: #990000">.</span><span style="color: #FF6600">xerl</span><span style="color: #990000">...</span>
+<span style="color: #FF6600">module</span> <span style="color: #FF6600">'first_module'</span> [<span style="color: #FF6600">'module_info'</span><span style="color: #990000">/</span><span style="color: #993399">0</span>,
+ <span style="color: #FF6600">'module_info'</span><span style="color: #990000">/</span><span style="color: #993399">1</span>]
+ <span style="color: #FF6600">attributes</span> []
+<span style="color: #FF6600">'module_info'</span><span style="color: #990000">/</span><span style="color: #993399">0</span> <span style="color: #990000">=</span>
+ <span style="font-weight: bold"><span style="color: #0000FF">fun</span></span> () <span style="color: #990000">-&gt;</span>
+ <span style="font-weight: bold"><span style="color: #000080">call</span></span> <span style="color: #FF6600">'erlang'</span><span style="color: #990000">:</span><span style="color: #FF6600">'get_module_info'</span>
+ (<span style="color: #FF6600">'first_module'</span>)
+<span style="color: #FF6600">'module_info'</span><span style="color: #990000">/</span><span style="color: #993399">1</span> <span style="color: #990000">=</span>
+ <span style="font-weight: bold"><span style="color: #0000FF">fun</span></span> (<span style="color: #009900">Key</span>) <span style="color: #990000">-&gt;</span>
+ <span style="font-weight: bold"><span style="color: #000080">call</span></span> <span style="color: #FF6600">'erlang'</span><span style="color: #990000">:</span><span style="color: #FF6600">'get_module_info'</span>
+ (<span style="color: #FF6600">'first_module'</span>, <span style="color: #009900">Key</span>)
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
+<span style="color: #FF6600">module</span> <span style="color: #FF6600">'second_module'</span> [<span style="color: #FF6600">'module_info'</span><span style="color: #990000">/</span><span style="color: #993399">0</span>,
+ <span style="color: #FF6600">'module_info'</span><span style="color: #990000">/</span><span style="color: #993399">1</span>]
+ <span style="color: #FF6600">attributes</span> []
+<span style="color: #FF6600">'module_info'</span><span style="color: #990000">/</span><span style="color: #993399">0</span> <span style="color: #990000">=</span>
+ <span style="font-weight: bold"><span style="color: #0000FF">fun</span></span> () <span style="color: #990000">-&gt;</span>
+ <span style="font-weight: bold"><span style="color: #000080">call</span></span> <span style="color: #FF6600">'erlang'</span><span style="color: #990000">:</span><span style="color: #FF6600">'get_module_info'</span>
+ (<span style="color: #FF6600">'second_module'</span>)
+<span style="color: #FF6600">'module_info'</span><span style="color: #990000">/</span><span style="color: #993399">1</span> <span style="color: #990000">=</span>
+ <span style="font-weight: bold"><span style="color: #0000FF">fun</span></span> (<span style="color: #009900">Key</span>) <span style="color: #990000">-&gt;</span>
+ <span style="font-weight: bold"><span style="color: #000080">call</span></span> <span style="color: #FF6600">'erlang'</span><span style="color: #990000">:</span><span style="color: #FF6600">'get_module_info'</span>
+ (<span style="color: #FF6600">'second_module'</span>, <span style="color: #009900">Key</span>)
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
+<span style="color: #009900">Done</span><span style="color: #990000">...</span>
+{<span style="color: #FF6600">ok</span>,[<span style="color: #FF6600">first_module</span>,<span style="color: #FF6600">second_module</span>]}</tt></pre></div></div>
+<div class="paragraph"><p>Everything looks fine. And we can check that the two modules have
+been loaded into the VM:</p></div>
+<div class="listingblock">
+<div class="content"><!-- Generator: GNU source-highlight 3.1.8
+by Lorenzo Bettini
+http://www.lorenzobettini.it
+http://www.gnu.org/software/src-highlite -->
+<pre><tt><span style="color: #993399">9</span><span style="color: #990000">&gt;</span> <span style="color: #FF6600">m</span>(<span style="color: #FF6600">first_module</span>)<span style="color: #990000">.</span>
+<span style="color: #009900">Module</span> <span style="color: #FF6600">first_module</span> <span style="color: #FF6600">compiled</span><span style="color: #990000">:</span> <span style="color: #009900">Date</span><span style="color: #990000">:</span> <span style="color: #009900">February</span> <span style="color: #993399">2</span> <span style="color: #993399">2013</span>, <span style="color: #009900">Time</span><span style="color: #990000">:</span> <span style="color: #993399">14.56</span>
+<span style="color: #009900">Compiler</span> <span style="color: #FF6600">options</span><span style="color: #990000">:</span> [<span style="color: #FF6600">from_core</span>]
+<span style="color: #009900">Object</span> <span style="font-weight: bold"><span style="color: #000000">file: test</span></span><span style="color: #990000">/</span><span style="font-weight: bold"><span style="color: #000000">mod_SUITE_data</span></span><span style="color: #990000">/</span><span style="color: #FF6600">two_modules</span><span style="color: #990000">.</span><span style="color: #FF6600">xerl</span>
+<span style="color: #009900">Exports</span><span style="color: #990000">:</span>
+ <span style="font-weight: bold"><span style="color: #000080">module_info</span></span><span style="color: #990000">/</span><span style="color: #993399">0</span>
+ <span style="font-weight: bold"><span style="color: #000080">module_info</span></span><span style="color: #990000">/</span><span style="color: #993399">1</span>
+<span style="color: #FF6600">ok</span>
+<span style="color: #993399">10</span><span style="color: #990000">&gt;</span> <span style="color: #FF6600">m</span>(<span style="color: #FF6600">second_module</span>)<span style="color: #990000">.</span>
+<span style="color: #009900">Module</span> <span style="color: #FF6600">second_module</span> <span style="color: #FF6600">compiled</span><span style="color: #990000">:</span> <span style="color: #009900">Date</span><span style="color: #990000">:</span> <span style="color: #009900">February</span> <span style="color: #993399">2</span> <span style="color: #993399">2013</span>, <span style="color: #009900">Time</span><span style="color: #990000">:</span> <span style="color: #993399">14.56</span>
+<span style="color: #009900">Compiler</span> <span style="color: #FF6600">options</span><span style="color: #990000">:</span> [<span style="color: #FF6600">from_core</span>]
+<span style="color: #009900">Object</span> <span style="font-weight: bold"><span style="color: #000000">file: test</span></span><span style="color: #990000">/</span><span style="font-weight: bold"><span style="color: #000000">mod_SUITE_data</span></span><span style="color: #990000">/</span><span style="color: #FF6600">two_modules</span><span style="color: #990000">.</span><span style="color: #FF6600">xerl</span>
+<span style="color: #009900">Exports</span><span style="color: #990000">:</span>
+ <span style="font-weight: bold"><span style="color: #000080">module_info</span></span><span style="color: #990000">/</span><span style="color: #993399">0</span>
+ <span style="font-weight: bold"><span style="color: #000080">module_info</span></span><span style="color: #990000">/</span><span style="color: #993399">1</span>
+<span style="color: #FF6600">ok</span></tt></pre></div></div>
+<div class="paragraph"><p>So far so good!</p></div>
+<div class="paragraph"><p>What about the second snippet? It brings up many questions. What
+happens once a <code>mod</code> expression has been executed at
+compile time? If it&#8217;s an expression then it has to have a result,
+right? Right. We are still a bit lacking with expressions for now,
+though, so let&#8217;s get back to it after we add more.</p></div>
+<div class="ulist"><ul>
+<li>
+<p>
+<a href="https://github.com/extend/xerl/blob/0.2/">View the source</a>
+</p>
+</li>
+</ul></div>
</article>
</div>
@@ -225,55 +225,107 @@ though, so let&#8217;s get back to it after we add more.</p></div>
<h3>More articles</h3>
<ul id="articles-nav" class="extra_margin">
- <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li>
+
+ <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.2/">Cowboy 2.0 release candidate 2</a></li>
+
+
+
+ <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li>
+
- <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-rc.1/">Cowboy 2.0 release candidate 1</a></li>
+
+ <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li>
+
- <li><a href="https://ninenines.eu/articles/the-elephant-in-the-room/">The elephant in the room</a></li>
+
+ <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don&#39;t let it crash</a></li>
+
- <li><a href="https://ninenines.eu/articles/dont-let-it-crash/">Don&#39;t let it crash</a></li>
+
+ <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li>
+
- <li><a href="https://ninenines.eu/articles/cowboy-2.0.0-pre.4/">Cowboy 2.0 pre-release 4</a></li>
+
+ <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li>
+
- <li><a href="https://ninenines.eu/articles/ranch-1.3/">Ranch 1.3</a></li>
+
+ <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li>
+
- <li><a href="https://ninenines.eu/articles/ml-archives/">Mailing list archived</a></li>
+
+ <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li>
+
- <li><a href="https://ninenines.eu/articles/website-update/">Website update</a></li>
+
+ <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li>
+
- <li><a href="https://ninenines.eu/articles/erlanger-playbook-september-2015-update/">The Erlanger Playbook September 2015 Update</a></li>
+
+ <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li>
+
- <li><a href="https://ninenines.eu/articles/erlanger-playbook/">The Erlanger Playbook</a></li>
+
+ <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li>
+
- <li><a href="https://ninenines.eu/articles/erlang-validate-utf8/">Validating UTF-8 binaries with Erlang</a></li>
+
+ <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li>
+
- <li><a href="https://ninenines.eu/articles/on-open-source/">On open source</a></li>
+
+ <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li>
+
- <li><a href="https://ninenines.eu/articles/the-story-so-far/">The story so far</a></li>
+
+ <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li>
+
- <li><a href="https://ninenines.eu/articles/cowboy2-qs/">Cowboy 2.0 and query strings</a></li>
+
+ <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li>
+
- <li><a href="https://ninenines.eu/articles/january-2014-status/">January 2014 status</a></li>
+
+ <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li>
+
- <li><a href="https://ninenines.eu/articles/farwest-funded/">Farwest got funded!</a></li>
+
+ <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li>
+
- <li><a href="https://ninenines.eu/articles/erlang.mk-and-relx/">Build Erlang releases with Erlang.mk and Relx</a></li>
+
+ <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li>
+
- <li><a href="https://ninenines.eu/articles/xerl-0.5-intermediate-module/">Xerl: intermediate module</a></li>
+
+ <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li>
+
- <li><a href="https://ninenines.eu/articles/xerl-0.4-expression-separator/">Xerl: expression separator</a></li>
+
+ <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li>
+
- <li><a href="https://ninenines.eu/articles/erlang-scalability/">Erlang Scalability</a></li>
+
+ <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li>
+
- <li><a href="https://ninenines.eu/articles/xerl-0.3-atomic-expressions/">Xerl: atomic expressions</a></li>
+
+ <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li>
+
- <li><a href="https://ninenines.eu/articles/xerl-0.2-two-modules/">Xerl: two modules</a></li>
+
+ <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li>
+
- <li><a href="https://ninenines.eu/articles/xerl-0.1-empty-modules/">Xerl: empty modules</a></li>
+
+ <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li>
+
- <li><a href="https://ninenines.eu/articles/ranch-ftp/">Build an FTP Server with Ranch in 30 Minutes</a></li>
+
+ <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li>
+
- <li><a href="https://ninenines.eu/articles/tictactoe/">Erlang Tic Tac Toe</a></li>
+
</ul>