mirror of
https://github.com/ganelson/inform.git
synced 2024-07-08 18:14:21 +03:00
143 lines
10 KiB
HTML
143 lines
10 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
<html>
|
|
<head>
|
|
<title>Package Types</title>
|
|
<meta name="viewport" content="width=device-width initial-scale=1">
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<meta http-equiv="Content-Language" content="en-gb">
|
|
<link href="../inweb.css" rel="stylesheet" rev="stylesheet" type="text/css">
|
|
|
|
</head>
|
|
<body>
|
|
<nav role="navigation">
|
|
<h1><a href="../index.html">
|
|
<img src="../docs-src/Figures/Inform.png" height=72">
|
|
</a></h1>
|
|
<ul><li><a href="../compiler.html">compiler tools</a></li>
|
|
<li><a href="../other.html">other tools</a></li>
|
|
<li><a href="../extensions.html">extensions and kits</a></li>
|
|
<li><a href="../units.html">unit test tools</a></li>
|
|
</ul><h2>Compiler Webs</h2><ul>
|
|
<li><a href="../inbuild/index.html">inbuild</a></li>
|
|
<li><a href="../inform7/index.html">inform7</a></li>
|
|
<li><a href="../inter/index.html">inter</a></li>
|
|
</ul><h2>Inbuild Modules</h2><ul>
|
|
<li><a href="../supervisor-module/index.html">supervisor</a></li>
|
|
</ul><h2>Inform7 Modules</h2><ul>
|
|
<li><a href="../core-module/index.html">core</a></li>
|
|
<li><a href="../inflections-module/index.html">inflections</a></li>
|
|
<li><a href="../linguistics-module/index.html">linguistics</a></li>
|
|
<li><a href="../kinds-module/index.html">kinds</a></li>
|
|
<li><a href="../if-module/index.html">if</a></li>
|
|
<li><a href="../multimedia-module/index.html">multimedia</a></li>
|
|
<li><a href="../problems-module/index.html">problems</a></li>
|
|
<li><a href="../index-module/index.html">index</a></li>
|
|
</ul><h2>Inter Modules</h2><ul>
|
|
<li><a href="../bytecode-module/index.html">bytecode</a></li>
|
|
<li><a href="index.html"><span class="selectedlink">building</span></a></li>
|
|
<li><a href="../codegen-module/index.html">codegen</a></li>
|
|
</ul><h2>Shared Modules</h2><ul>
|
|
<li><a href="../arch-module/index.html">arch</a></li>
|
|
<li><a href="../syntax-module/index.html">syntax</a></li>
|
|
<li><a href="../words-module/index.html">words</a></li>
|
|
<li><a href="../html-module/index.html">html</a></li>
|
|
<li><a href="../../../inweb/docs/foundation-module/index.html">foundation</a></li>
|
|
|
|
</ul>
|
|
</nav>
|
|
<main role="main">
|
|
|
|
<!--Weave of 'Package Types' generated by 7-->
|
|
<ul class="crumbs"><li><a href="../index.html">Home</a></li><li><a href="../compiler.html">Inter Modules</a></li><li><a href="index.html">building</a></li><li><a href="index.html#1">Chapter 1: Architecture</a></li><li><b>Package Types</b></li></ul><p class="purpose">To manage the different types of packages emitted by Inform.</p>
|
|
|
|
<ul class="toc"><li><a href="#SP1">§1. Package types</a></li></ul><hr class="tocbar">
|
|
|
|
<p class="inwebparagraph"><a id="SP1"></a><b>§1. Package types. </b>Inter code is a nested hierarchy of "packages", which can be assigned "types".
|
|
Inter requires two types to exist, <code class="display"><span class="extract">_plain</span></code> and <code class="display"><span class="extract">_code</span></code>, and leaves the rest
|
|
to the user (i.e., us) to define as we see fit. In fact Inform generates
|
|
packages of slightly over 50 different types.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">At run time, package types are pointers to the inter symbol which defined them,
|
|
but this is not a convenient way to refer to them in the Inform source code.
|
|
Instead we use the following function:
|
|
</p>
|
|
|
|
<pre class="display">
|
|
<span class="identifier">inter_symbol</span><span class="plain"> *</span><span class="functiontext">PackageTypes::get<button class="popup" onclick="togglePopup('usagePopup115')">...<span class="popuptext" id="usagePopup115">Usage of <b>PackageTypes::get</b>:<br><a href="#SP2">§2</a>, Building Site - <a href="1-bs.html#SP2">§2</a><br>Hierarchy Locations - <a href="1-hl.html#SP3">§3</a>, <a href="1-hl.html#SP4">§4</a>, <a href="1-hl.html#SP5">§5</a>, <a href="1-hl.html#SP6">§6</a><br>Packaging - <a href="1-pck.html#SP11">§11</a>, <a href="1-pck.html#SP15">§15</a>, <a href="1-pck.html#SP18">§18</a>, <a href="1-pck.html#SP20">§20</a><br>Producing Inter - <a href="3-prd.html#SP3">§3</a></span></button></span><span class="plain">(</span><span class="identifier">inter_tree</span><span class="plain"> *</span><span class="identifier">I</span><span class="plain">, </span><span class="identifier">text_stream</span><span class="plain"> *</span><span class="identifier">name</span><span class="plain">) {</span>
|
|
<span class="identifier">inter_symbols_table</span><span class="plain"> *</span><span class="identifier">scope</span><span class="plain"> = </span><span class="identifier">Inter::Tree::global_scope</span><span class="plain">(</span><span class="identifier">I</span><span class="plain">);</span>
|
|
|
|
<span class="identifier">inter_symbol</span><span class="plain"> *</span><span class="identifier">ptype</span><span class="plain"> = </span><span class="identifier">Inter::SymbolsTables::symbol_from_name</span><span class="plain">(</span><span class="identifier">scope</span><span class="plain">, </span><span class="identifier">name</span><span class="plain">);</span>
|
|
<span class="reserved">if</span><span class="plain"> (</span><span class="identifier">ptype</span><span class="plain"> == </span><span class="identifier">NULL</span><span class="plain">) {</span>
|
|
<span class="reserved">int</span><span class="plain"> </span><span class="identifier">enclose</span><span class="plain"> = </span><span class="identifier">TRUE</span><span class="plain">;</span>
|
|
<<span class="cwebmacro">Decide if this package type is to be enclosing</span> <span class="cwebmacronumber">1.1</span>><span class="plain">;</span>
|
|
<span class="identifier">ptype</span><span class="plain"> = </span><span class="functiontext"><a href="3-prd.html#SP2">Produce::new_symbol</a></span><span class="plain">(</span><span class="identifier">scope</span><span class="plain">, </span><span class="identifier">name</span><span class="plain">);</span>
|
|
<span class="functiontext"><a href="3-prd.html#SP2">Produce::guard</a></span><span class="plain">(</span><span class="identifier">Inter::PackageType::new_packagetype</span><span class="plain">(</span>
|
|
<span class="functiontext"><a href="1-bs.html#SP2">Site::package_types</a></span><span class="plain">(</span><span class="identifier">I</span><span class="plain">), </span><span class="identifier">ptype</span><span class="plain">,</span>
|
|
<span class="constant">0</span><span class="plain">, </span><span class="identifier">NULL</span><span class="plain">));</span>
|
|
<span class="reserved">if</span><span class="plain"> (</span><span class="identifier">enclose</span><span class="plain">) </span><span class="functiontext"><a href="3-prd.html#SP2">Produce::annotate_symbol_i</a></span><span class="plain">(</span><span class="identifier">ptype</span><span class="plain">, </span><span class="identifier">ENCLOSING_IANN</span><span class="plain">, </span><span class="constant">1</span><span class="plain">);</span>
|
|
<span class="plain">}</span>
|
|
<span class="reserved">return</span><span class="plain"> </span><span class="identifier">ptype</span><span class="plain">;</span>
|
|
<span class="plain">}</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="inwebparagraph"><a id="SP1_1"></a><b>§1.1. </b>Most package types are "enclosing". Suppose that Inform is compiling
|
|
something to go into the package, but finds that it needs to compile something
|
|
else in order to do so — for example, it's compiling code to set a variable
|
|
to be equal to a literal piece of text, which must itself be compiled as a
|
|
small array. Where does Inform put that array? If the current package is
|
|
"enclosing", then Inform puts it into the package itself; and if not, then
|
|
into the package holding the current package, if that in turn is "enclosing";
|
|
and so on.
|
|
</p>
|
|
|
|
<p class="inwebparagraph">It seems tidy to make all packages enclosing, and in fact (after much
|
|
experiment) Inform nearly does that. But <code class="display"><span class="extract">_code</span></code> packages have to be an
|
|
exception, because the Inter specification doesn't allow constants (and
|
|
therefore arrays) to be defined inside <code class="display"><span class="extract">_code</span></code> packages.
|
|
</p>
|
|
|
|
|
|
<p class="macrodefinition"><code class="display">
|
|
<<span class="cwebmacrodefn">Decide if this package type is to be enclosing</span> <span class="cwebmacronumber">1.1</span>> =
|
|
</code></p>
|
|
|
|
|
|
<pre class="displaydefn">
|
|
<span class="reserved">if</span><span class="plain"> (</span><span class="identifier">Str::eq</span><span class="plain">(</span><span class="identifier">name</span><span class="plain">, </span><span class="identifier">I</span><span class="string">"_code"</span><span class="plain">)) </span><span class="identifier">enclose</span><span class="plain"> = </span><span class="identifier">FALSE</span><span class="plain">;</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<p class="endnote">This code is used in <a href="#SP1">§1</a>.</p>
|
|
|
|
<p class="inwebparagraph"><a id="SP2"></a><b>§2. </b>Symbol lookups by name are fast, but not instant, so we might some day
|
|
want to optimise this by cacheing the result:
|
|
</p>
|
|
|
|
<pre class="display">
|
|
<span class="identifier">inter_symbol</span><span class="plain"> *</span><span class="functiontext">PackageTypes::function<button class="popup" onclick="togglePopup('usagePopup116')">...<span class="popuptext" id="usagePopup116">Usage of <b>PackageTypes::function</b>:<br>Packaging - <a href="1-pck.html#SP19">§19</a></span></button></span><span class="plain">(</span><span class="identifier">inter_tree</span><span class="plain"> *</span><span class="identifier">I</span><span class="plain">) {</span>
|
|
<span class="reserved">return</span><span class="plain"> </span><span class="functiontext"><a href="#SP1">PackageTypes::get</a></span><span class="plain">(</span><span class="identifier">I</span><span class="plain">, </span><span class="identifier">I</span><span class="string">"_function"</span><span class="plain">);</span>
|
|
<span class="plain">}</span>
|
|
</pre>
|
|
|
|
<p class="inwebparagraph"></p>
|
|
|
|
<hr class="tocbar">
|
|
<ul class="toc"><li><a href="1-pck.html">Back to 'Packaging'</a></li><li><a href="1-in.html">Continue with 'Inter Namespace'</a></li></ul><hr class="tocbar">
|
|
<!--End of weave-->
|
|
<script>
|
|
function togglePopup(material_id) {
|
|
var popup = document.getElementById(material_id);
|
|
popup.classList.toggle("show");
|
|
}
|
|
</script>
|
|
|
|
<link href="Popups.css" rel="stylesheet" rev="stylesheet" type="text/css">
|
|
</main>
|
|
</body>
|
|
</html>
|
|
|