mirror of
https://github.com/ganelson/inform.git
synced 2024-07-08 18:14:21 +03:00
101 lines
7.9 KiB
HTML
101 lines
7.9 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
<html>
|
|
<head>
|
|
<title>1/pck</title>
|
|
<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>
|
|
|
|
<!--Weave of '1/pt' generated by 7-->
|
|
<ul class="crumbs"><li><a href="../webs.html">★</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</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">Produce::new_symbol</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">Produce::guard</span><span class="plain">(</span><span class="identifier">Inter::PackageType::new_packagetype</span><span class="plain">(</span>
|
|
<span class="functiontext">Site::package_types</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="plain">0, </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">Produce::annotate_symbol_i</span><span class="plain">(</span><span class="identifier">ptype</span><span class="plain">, </span><span class="identifier">ENCLOSING_IANN</span><span class="plain">, 1);</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="endnote">The function PackageTypes::get is used in <a href="#SP2">§2</a>, 1/bs (<a href="1-bs.html#SP2">§2</a>), 1/hl (<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>), 1/pck (<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>), 3/pi (<a href="3-pi.html#SP3">§3</a>).</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</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">PackageTypes::get</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>
|
|
|
|
<p class="endnote">The function PackageTypes::function is used in 1/pck (<a href="1-pck.html#SP19">§19</a>).</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-->
|
|
</body>
|
|
</html>
|
|
|