2019-04-19 16:36:05 +03:00
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
< html >
< head >
2020-04-14 19:56:54 +03:00
< title > Package Types< / title >
2020-05-03 03:20:55 +03:00
< link href = "../docs-assets/Breadcrumbs.css" rel = "stylesheet" rev = "stylesheet" type = "text/css" >
2020-03-19 02:11:25 +02:00
< meta name = "viewport" content = "width=device-width initial-scale=1" >
2019-04-19 16:36:05 +03:00
< meta http-equiv = "Content-Type" content = "text/html; charset=utf-8" >
< meta http-equiv = "Content-Language" content = "en-gb" >
2020-05-03 03:01:21 +03:00
2020-05-03 03:20:55 +03:00
< link href = "../docs-assets/Contents.css" rel = "stylesheet" rev = "stylesheet" type = "text/css" >
< link href = "../docs-assets/Progress.css" rel = "stylesheet" rev = "stylesheet" type = "text/css" >
< link href = "../docs-assets/Navigation.css" rel = "stylesheet" rev = "stylesheet" type = "text/css" >
< link href = "../docs-assets/Fonts.css" rel = "stylesheet" rev = "stylesheet" type = "text/css" >
< link href = "../docs-assets/Base.css" rel = "stylesheet" rev = "stylesheet" type = "text/css" >
2020-05-03 03:01:21 +03:00
< script >
function togglePopup(material_id) {
var popup = document.getElementById(material_id);
popup.classList.toggle("show");
}
< / script >
2020-05-03 03:20:55 +03:00
< link href = "../docs-assets/Popups.css" rel = "stylesheet" rev = "stylesheet" type = "text/css" >
< link href = "../docs-assets/Colours.css" rel = "stylesheet" rev = "stylesheet" type = "text/css" >
2020-04-14 19:56:54 +03:00
2019-04-19 16:36:05 +03:00
< / head >
2020-05-03 03:01:21 +03:00
< body class = "commentary-font" >
2020-03-19 02:11:25 +02:00
< nav role = "navigation" >
2020-04-14 19:56:54 +03:00
< h1 > < a href = "../index.html" >
2020-05-03 18:34:53 +03:00
< img src = "../docs-assets/Inform.png" height = 72" >
2020-04-14 19:56:54 +03:00
< / a > < / h1 >
< ul > < li > < a href = "../compiler.html" > compiler tools< / a > < / li >
2020-03-19 02:11:25 +02:00
< 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 >
2020-04-14 19:56:54 +03:00
< / ul > < h2 > Compiler Webs< / h2 > < ul >
2020-03-19 02:11:25 +02:00
< 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 >
2020-04-14 19:56:54 +03:00
< / ul > < h2 > Inbuild Modules< / h2 > < ul >
< li > < a href = "../supervisor-module/index.html" > supervisor< / a > < / li >
< / ul > < h2 > Inform7 Modules< / h2 > < ul >
2020-03-19 02:11:25 +02:00
< li > < a href = "../core-module/index.html" > core< / a > < / li >
2020-08-27 17:50:24 +03:00
< li > < a href = "../assertions-module/index.html" > assertions< / a > < / li >
< li > < a href = "../values-module/index.html" > values< / a > < / li >
< li > < a href = "../knowledge-module/index.html" > knowledge< / a > < / li >
< li > < a href = "../imperative-module/index.html" > imperative< / a > < / li >
< li > < a href = "../runtime-module/index.html" > runtime< / a > < / li >
2020-03-19 02:11:25 +02:00
< li > < a href = "../if-module/index.html" > if< / a > < / li >
< li > < a href = "../multimedia-module/index.html" > multimedia< / a > < / li >
< li > < a href = "../index-module/index.html" > index< / a > < / li >
2020-04-14 19:56:54 +03:00
< / 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 >
2021-08-10 13:01:03 +03:00
< li > < a href = "../pipeline-module/index.html" > pipeline< / a > < / li >
< li > < a href = "../final-module/index.html" > final< / a > < / li >
2020-05-20 02:02:28 +03:00
< / ul > < h2 > Services< / h2 > < ul >
2020-04-14 19:56:54 +03:00
< li > < a href = "../arch-module/index.html" > arch< / a > < / li >
2020-08-27 17:50:24 +03:00
< li > < a href = "../calculus-module/index.html" > calculus< / a > < / li >
2020-04-14 19:56:54 +03:00
< li > < a href = "../html-module/index.html" > html< / a > < / li >
2020-05-20 02:02:28 +03:00
< li > < a href = "../inflections-module/index.html" > inflections< / a > < / li >
2020-08-27 17:50:24 +03:00
< li > < a href = "../kinds-module/index.html" > kinds< / a > < / li >
2020-05-20 02:02:28 +03:00
< li > < a href = "../linguistics-module/index.html" > linguistics< / a > < / li >
< li > < a href = "../problems-module/index.html" > problems< / a > < / li >
2020-08-27 17:50:24 +03:00
< li > < a href = "../syntax-module/index.html" > syntax< / a > < / li >
< li > < a href = "../words-module/index.html" > words< / a > < / li >
2020-03-19 02:11:25 +02:00
< li > < a href = "../../../inweb/docs/foundation-module/index.html" > foundation< / a > < / li >
2020-04-14 19:56:54 +03:00
< / ul >
2020-03-19 02:11:25 +02:00
< / nav >
< main role = "main" >
2020-05-03 03:01:21 +03:00
<!-- Weave of 'Package Types' generated by Inweb -->
< div class = "breadcrumbs" >
< 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 > < / div >
< p class = "purpose" > To manage the different types of packages emitted by Inform.< / p >
2019-04-22 17:06:29 +03:00
2020-04-16 01:49:59 +03:00
< ul class = "toc" > < li > < a href = "1-pt.html#SP1" > § 1. Package types< / a > < / li > < / ul > < hr class = "tocbar" >
2019-04-22 17:06:29 +03:00
2020-08-27 17:50:24 +03:00
< p class = "commentary firstcommentary" > < a id = "SP1" class = "paragraph-anchor" > < / a > < b > § 1. Package types. < / b > Inter code is a nested hierarchy of "packages", which can be assigned "types".
2020-05-03 03:01:21 +03:00
Inter requires two types to exist, < span class = "extract" > < span class = "extract-syntax" > _plain< / span > < / span > and < span class = "extract" > < span class = "extract-syntax" > _code< / span > < / span > , and leaves the rest
2019-04-19 16:36:05 +03:00
to the user (i.e., us) to define as we see fit. In fact Inform generates
packages of slightly over 50 different types.
< / p >
2020-05-03 03:01:21 +03:00
< p class = "commentary" > At run time, package types are pointers to the inter symbol which defined them,
2019-04-19 16:36:05 +03:00
but this is not a convenient way to refer to them in the Inform source code.
2019-08-31 15:56:36 +03:00
Instead we use the following function:
2019-04-19 16:36:05 +03:00
< / p >
2020-05-03 03:01:21 +03:00
< pre class = "displayed-code all-displayed-code code-font" >
2021-04-25 15:23:45 +03:00
< span class = "identifier-syntax" > inter_symbol< / span > < span class = "plain-syntax" > *< / span > < span class = "function-syntax" > PackageTypes::get< / span > < button class = "popup" onclick = "togglePopup('usagePopup1')" > < span class = "comment-syntax" > ?< / span > < span class = "popuptext" id = "usagePopup1" > Usage of < span class = "code-font" > < span class = "function-syntax" > PackageTypes::get< / span > < / span > :< br / > < a href = "1-pt.html#SP2" > § 2< / a > < br / > Building Site - < a href = "1-bs.html#SP3" > § 3< / 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 > < br / > Packaging - < a href = "1-pck.html#SP11" > § 11< / a > , < a href = "1-pck.html#SP14" > § 14< / a > , < a href = "1-pck.html#SP17" > § 17< / a > , < a href = "1-pck.html#SP19" > § 19< / a > < br / > Producing Inter - < a href = "3-prd.html#SP3" > § 3< / a > < / span > < / button > < span class = "plain-syntax" > (< / span > < span class = "identifier-syntax" > inter_tree< / span > < span class = "plain-syntax" > *< / span > < span class = "identifier-syntax" > I< / span > < span class = "plain-syntax" > , < / span > < span class = "identifier-syntax" > text_stream< / span > < span class = "plain-syntax" > *< / span > < span class = "identifier-syntax" > name< / span > < span class = "plain-syntax" > ) {< / span >
2021-04-16 00:42:28 +03:00
< span class = "plain-syntax" > < / span > < span class = "identifier-syntax" > inter_symbols_table< / span > < span class = "plain-syntax" > *< / span > < span class = "identifier-syntax" > scope< / span > < span class = "plain-syntax" > = < / span > < span class = "identifier-syntax" > InterTree::global_scope< / span > < span class = "plain-syntax" > (< / span > < span class = "identifier-syntax" > I< / span > < span class = "plain-syntax" > );< / span >
2020-05-03 03:01:21 +03:00
2021-04-15 00:57:48 +03:00
< span class = "plain-syntax" > < / span > < span class = "identifier-syntax" > inter_symbol< / span > < span class = "plain-syntax" > *< / span > < span class = "identifier-syntax" > ptype< / span > < span class = "plain-syntax" > = < / span > < span class = "identifier-syntax" > InterSymbolsTables::symbol_from_name< / span > < span class = "plain-syntax" > (< / span > < span class = "identifier-syntax" > scope< / span > < span class = "plain-syntax" > , < / span > < span class = "identifier-syntax" > name< / span > < span class = "plain-syntax" > );< / span >
2020-05-03 03:01:21 +03:00
< span class = "plain-syntax" > < / span > < span class = "reserved-syntax" > if< / span > < span class = "plain-syntax" > (< / span > < span class = "identifier-syntax" > ptype< / span > < span class = "plain-syntax" > == < / span > < span class = "identifier-syntax" > NULL< / span > < span class = "plain-syntax" > ) {< / span >
< span class = "plain-syntax" > < / span > < span class = "reserved-syntax" > int< / span > < span class = "plain-syntax" > < / span > < span class = "identifier-syntax" > enclose< / span > < span class = "plain-syntax" > = < / span > < span class = "identifier-syntax" > TRUE< / span > < span class = "plain-syntax" > ;< / span >
< span class = "plain-syntax" > < / span > < span class = "named-paragraph-container code-font" > < a href = "1-pt.html#SP1_1" class = "named-paragraph-link" > < span class = "named-paragraph" > Decide if this package type is to be enclosing< / span > < span class = "named-paragraph-number" > 1.1< / span > < / a > < / span > < span class = "plain-syntax" > ;< / span >
< span class = "plain-syntax" > < / span > < span class = "identifier-syntax" > ptype< / span > < span class = "plain-syntax" > = < / span > < a href = "3-prd.html#SP2" class = "function-link" > < span class = "function-syntax" > Produce::new_symbol< / span > < / a > < span class = "plain-syntax" > (< / span > < span class = "identifier-syntax" > scope< / span > < span class = "plain-syntax" > , < / span > < span class = "identifier-syntax" > name< / span > < span class = "plain-syntax" > );< / span >
< span class = "plain-syntax" > < / span > < a href = "3-prd.html#SP2" class = "function-link" > < span class = "function-syntax" > Produce::guard< / span > < / a > < span class = "plain-syntax" > (< / span > < span class = "identifier-syntax" > Inter::PackageType::new_packagetype< / span > < span class = "plain-syntax" > (< / span >
< span class = "plain-syntax" > < / span > < a href = "1-bs.html#SP2" class = "function-link" > < span class = "function-syntax" > Site::package_types< / span > < / a > < span class = "plain-syntax" > (< / span > < span class = "identifier-syntax" > I< / span > < span class = "plain-syntax" > ), < / span > < span class = "identifier-syntax" > ptype< / span > < span class = "plain-syntax" > ,< / span >
< span class = "plain-syntax" > < / span > < span class = "constant-syntax" > 0< / span > < span class = "plain-syntax" > , < / span > < span class = "identifier-syntax" > NULL< / span > < span class = "plain-syntax" > ));< / span >
< span class = "plain-syntax" > < / span > < span class = "reserved-syntax" > if< / span > < span class = "plain-syntax" > (< / span > < span class = "identifier-syntax" > enclose< / span > < span class = "plain-syntax" > ) < / span > < a href = "3-prd.html#SP2" class = "function-link" > < span class = "function-syntax" > Produce::annotate_symbol_i< / span > < / a > < span class = "plain-syntax" > (< / span > < span class = "identifier-syntax" > ptype< / span > < span class = "plain-syntax" > , < / span > < span class = "identifier-syntax" > ENCLOSING_IANN< / span > < span class = "plain-syntax" > , < / span > < span class = "constant-syntax" > 1< / span > < span class = "plain-syntax" > );< / span >
< span class = "plain-syntax" > }< / span >
< span class = "plain-syntax" > < / span > < span class = "reserved-syntax" > return< / span > < span class = "plain-syntax" > < / span > < span class = "identifier-syntax" > ptype< / span > < span class = "plain-syntax" > ;< / span >
< span class = "plain-syntax" > }< / span >
2019-04-19 16:36:05 +03:00
< / pre >
2020-08-27 17:50:24 +03:00
< p class = "commentary firstcommentary" > < a id = "SP1_1" class = "paragraph-anchor" > < / a > < b > § 1.1. < / b > Most package types are "enclosing". Suppose that Inform is compiling
2019-04-19 16:36:05 +03:00
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 >
2020-05-03 03:01:21 +03:00
< p class = "commentary" > It seems tidy to make all packages enclosing, and in fact (after much
experiment) Inform nearly does that. But < span class = "extract" > < span class = "extract-syntax" > _code< / span > < / span > packages have to be an
2019-04-19 16:36:05 +03:00
exception, because the Inter specification doesn't allow constants (and
2020-05-03 03:01:21 +03:00
therefore arrays) to be defined inside < span class = "extract" > < span class = "extract-syntax" > _code< / span > < / span > packages.
2019-04-19 16:36:05 +03:00
< / p >
2020-05-03 03:01:21 +03:00
< p class = "commentary" > < span class = "named-paragraph-container code-font" > < span class = "named-paragraph-defn" > Decide if this package type is to be enclosing< / span > < span class = "named-paragraph-number" > 1.1< / span > < / span > < span class = "comment-syntax" > =< / span >
< / p >
2019-04-19 16:36:05 +03:00
2020-05-03 03:01:21 +03:00
< pre class = "displayed-code all-displayed-code code-font" >
< span class = "plain-syntax" > < / span > < span class = "reserved-syntax" > if< / span > < span class = "plain-syntax" > (< / span > < span class = "identifier-syntax" > Str::eq< / span > < span class = "plain-syntax" > (< / span > < span class = "identifier-syntax" > name< / span > < span class = "plain-syntax" > , < / span > < span class = "identifier-syntax" > I< / span > < span class = "string-syntax" > "_code"< / span > < span class = "plain-syntax" > )) < / span > < span class = "identifier-syntax" > enclose< / span > < span class = "plain-syntax" > = < / span > < span class = "identifier-syntax" > FALSE< / span > < span class = "plain-syntax" > ;< / span >
2019-04-19 16:36:05 +03:00
< / pre >
2020-05-03 03:01:21 +03:00
< ul class = "endnotetexts" > < li > This code is used in < a href = "1-pt.html#SP1" > § 1< / a > .< / li > < / ul >
2020-08-27 17:50:24 +03:00
< p class = "commentary firstcommentary" > < a id = "SP2" class = "paragraph-anchor" > < / a > < b > § 2. < / b > Symbol lookups by name are fast, but not instant, so we might some day
2019-08-31 15:56:36 +03:00
want to optimise this by cacheing the result:
2019-04-19 16:36:05 +03:00
< / p >
2020-05-03 03:01:21 +03:00
< pre class = "displayed-code all-displayed-code code-font" >
2021-04-12 12:20:09 +03:00
< span class = "identifier-syntax" > inter_symbol< / span > < span class = "plain-syntax" > *< / span > < span class = "function-syntax" > PackageTypes::function< / span > < button class = "popup" onclick = "togglePopup('usagePopup2')" > < span class = "comment-syntax" > ?< / span > < span class = "popuptext" id = "usagePopup2" > Usage of < span class = "code-font" > < span class = "function-syntax" > PackageTypes::function< / span > < / span > :< br / > Packaging - < a href = "1-pck.html#SP18" > § 18< / a > < / span > < / button > < span class = "plain-syntax" > (< / span > < span class = "identifier-syntax" > inter_tree< / span > < span class = "plain-syntax" > *< / span > < span class = "identifier-syntax" > I< / span > < span class = "plain-syntax" > ) {< / span >
2020-05-03 03:01:21 +03:00
< span class = "plain-syntax" > < / span > < span class = "reserved-syntax" > return< / span > < span class = "plain-syntax" > < / span > < a href = "1-pt.html#SP1" class = "function-link" > < span class = "function-syntax" > PackageTypes::get< / span > < / a > < span class = "plain-syntax" > (< / span > < span class = "identifier-syntax" > I< / span > < span class = "plain-syntax" > , < / span > < span class = "identifier-syntax" > I< / span > < span class = "string-syntax" > "_function"< / span > < span class = "plain-syntax" > );< / span >
< span class = "plain-syntax" > }< / span >
2019-04-19 16:36:05 +03:00
< / pre >
2020-05-03 03:01:21 +03:00
< nav role = "progress" > < div class = "progresscontainer" >
< ul class = "progressbar" > < li class = "progressprev" > < a href = "1-pck.html" > ❮ < / a > < / li > < li class = "progresscurrentchapter" > 1< / li > < li class = "progresssection" > < a href = "1-bm.html" > bm< / a > < / li > < li class = "progresssection" > < a href = "1-bs.html" > bs< / a > < / li > < li class = "progresssection" > < a href = "1-ip.html" > ip< / a > < / li > < li class = "progresssection" > < a href = "1-tv.html" > tv< / a > < / li > < li class = "progresssection" > < a href = "1-hl.html" > hl< / a > < / li > < li class = "progresssection" > < a href = "1-trn.html" > trn< / a > < / li > < li class = "progresssection" > < a href = "1-pck.html" > pck< / a > < / li > < li class = "progresscurrent" > pt< / li > < li class = "progresssection" > < a href = "1-in.html" > in< / a > < / li > < li class = "progresschapter" > < a href = "2-is.html" > 2< / a > < / li > < li class = "progresschapter" > < a href = "3-prd.html" > 3< / a > < / li > < li class = "progressnext" > < a href = "1-in.html" > ❯ < / a > < / li > < / ul > < / div >
< / nav > <!-- End of weave -->
2019-04-19 16:36:05 +03:00
2020-03-19 02:11:25 +02:00
< / main >
2019-04-19 16:36:05 +03:00
< / body >
< / html >