mirror of
https://github.com/ganelson/inform.git
synced 2024-07-16 22:14:23 +03:00
341 lines
28 KiB
HTML
341 lines
28 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
<html>
|
|
<head>
|
|
<title>Inform Primitives</title>
|
|
<link href="../docs-assets/Breadcrumbs.css" rel="stylesheet" rev="stylesheet" type="text/css">
|
|
<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="../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">
|
|
<link href="../docs-assets/Colours.css" rel="stylesheet" rev="stylesheet" type="text/css">
|
|
|
|
</head>
|
|
<body class="commentary-font">
|
|
<nav role="navigation">
|
|
<h1><a href="../index.html">
|
|
<img src="../docs-assets/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="index.html"><span class="selectedlink">inter</span></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="../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>
|
|
<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>
|
|
</ul><h2>Inter Modules</h2><ul>
|
|
<li><a href="../bytecode-module/index.html">bytecode</a></li>
|
|
<li><a href="../building-module/index.html">building</a></li>
|
|
<li><a href="../pipeline-module/index.html">pipeline</a></li>
|
|
<li><a href="../final-module/index.html">final</a></li>
|
|
</ul><h2>Services</h2><ul>
|
|
<li><a href="../arch-module/index.html">arch</a></li>
|
|
<li><a href="../calculus-module/index.html">calculus</a></li>
|
|
<li><a href="../html-module/index.html">html</a></li>
|
|
<li><a href="../inflections-module/index.html">inflections</a></li>
|
|
<li><a href="../kinds-module/index.html">kinds</a></li>
|
|
<li><a href="../linguistics-module/index.html">linguistics</a></li>
|
|
<li><a href="../problems-module/index.html">problems</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="../../../inweb/docs/foundation-module/index.html">foundation</a></li>
|
|
|
|
</ul>
|
|
</nav>
|
|
<main role="main">
|
|
<!--Weave of 'Inform Primitives' generated by Inweb-->
|
|
<div class="breadcrumbs">
|
|
<ul class="crumbs"><li><a href="../index.html">Home</a></li><li><a href="../compiler.html">Compiler Tools</a></li><li><a href="index.html">inter</a></li><li><a href="index.html#M">Manual</a></li><li><b>Inform Primitives</b></li></ul></div>
|
|
<p class="purpose">The standard set of primitive invocations used within Inform.</p>
|
|
|
|
<ul class="toc"><li><a href="M-ip.html#SP1">§1. Status</a></li><li><a href="M-ip.html#SP2">§2. Arithmetic</a></li><li><a href="M-ip.html#SP3">§3. Logical operators</a></li><li><a href="M-ip.html#SP4">§4. Bitwise operators</a></li><li><a href="M-ip.html#SP5">§5. Numerical comparison</a></li><li><a href="M-ip.html#SP6">§6. Sequential evaluation</a></li><li><a href="M-ip.html#SP7">§7. Random numbers</a></li><li><a href="M-ip.html#SP8">§8. Printing</a></li><li><a href="M-ip.html#SP9">§9. Stack access</a></li><li><a href="M-ip.html#SP10">§10. Accessing storage</a></li><li><a href="M-ip.html#SP11">§11. Indirect function calls</a></li><li><a href="M-ip.html#SP12">§12. External function calls</a></li><li><a href="M-ip.html#SP13">§13. Control flow</a></li><li><a href="M-ip.html#SP14">§14. Interactive fiction-only primitives</a></li></ul><hr class="tocbar">
|
|
|
|
<p class="commentary firstcommentary"><a id="SP1" class="paragraph-anchor"></a><b>§1. Status. </b>The Inter specification allows for any number of primitive invocations to
|
|
be declared and used; none are built-in or required.
|
|
</p>
|
|
|
|
<p class="commentary">The Inform compiler, however, has a set of around 90 different primitives.
|
|
The back end of the compiler can compile those into valid Inform 6 code;
|
|
the front end of the compiler is guaranteed to declare and use only (a
|
|
subset of) those 90. That gives the following set of primitives a
|
|
kind of halfway status: though they are not part of the inter specification,
|
|
for the time being they're the only game in town.
|
|
</p>
|
|
|
|
<p class="commentary firstcommentary"><a id="SP2" class="paragraph-anchor"></a><b>§2. Arithmetic. </b>The following are standard integer arithmetic operations:
|
|
</p>
|
|
|
|
<ul class="items"><li>(a) <span class="extract"><span class="extract-syntax">primitive !plus val val -> val</span></span>. 16 or 32-bit integer addition.
|
|
</li><li>(b) <span class="extract"><span class="extract-syntax">primitive !minus val val -> val</span></span>. 16 or 32-bit integer subtraction.
|
|
</li><li>(c) <span class="extract"><span class="extract-syntax">primitive !unaryminus val -> val</span></span>. Equivalent to performing <span class="extract"><span class="extract-syntax">0 - x</span></span>.
|
|
</li><li>(d) <span class="extract"><span class="extract-syntax">primitive !times val val -> val</span></span>. 16 or 32-bit integer multiplication.
|
|
</li><li>(e) <span class="extract"><span class="extract-syntax">primitive !divide val val -> val</span></span>. 16 or 32-bit integer division.
|
|
</li><li>(f) <span class="extract"><span class="extract-syntax">primitive !modulo val val -> val</span></span>. Remainder after such a division.
|
|
</li></ul>
|
|
<p class="commentary firstcommentary"><a id="SP3" class="paragraph-anchor"></a><b>§3. Logical operators. </b>In general, the value 0 is false, and all other values are true.
|
|
</p>
|
|
|
|
<ul class="items"><li>(a) <span class="extract"><span class="extract-syntax">primitive !not val -> val</span></span>. True if the value is false, and vice versa.
|
|
</li><li>(b) <span class="extract"><span class="extract-syntax">primitive !and val val -> val</span></span>. True if both are true: doesn't evaluate the second if the first is false.
|
|
</li><li>(c) <span class="extract"><span class="extract-syntax">primitive !or val val -> val</span></span>. True if either is true: doesn't evaluate the second if the first is true.
|
|
</li></ul>
|
|
<p class="commentary firstcommentary"><a id="SP4" class="paragraph-anchor"></a><b>§4. Bitwise operators. </b>These differ in that they do not "short circuit", and do not squash values
|
|
down to just 0 or 1.
|
|
</p>
|
|
|
|
<ul class="items"><li>(a) <span class="extract"><span class="extract-syntax">primitive !bitwiseand val val -> val</span></span>.
|
|
</li><li>(a) <span class="extract"><span class="extract-syntax">primitive !bitwiseor val val -> val</span></span>.
|
|
</li><li>(a) <span class="extract"><span class="extract-syntax">primitive !bitwisenot val -> val</span></span>.
|
|
</li></ul>
|
|
<p class="commentary firstcommentary"><a id="SP5" class="paragraph-anchor"></a><b>§5. Numerical comparison. </b>These are comparisons of signed integers. (If Inform needs to compare unsigned
|
|
integers, it calls a routine in the I6 template.)
|
|
</p>
|
|
|
|
<ul class="items"><li>(a) <span class="extract"><span class="extract-syntax">primitive !eq val val -> val</span></span>.
|
|
</li><li>(b) <span class="extract"><span class="extract-syntax">primitive !ne val val -> val</span></span>.
|
|
</li><li>(c) <span class="extract"><span class="extract-syntax">primitive !gt val val -> val</span></span>.
|
|
</li><li>(d) <span class="extract"><span class="extract-syntax">primitive !ge val val -> val</span></span>.
|
|
</li><li>(e) <span class="extract"><span class="extract-syntax">primitive !lt val val -> val</span></span>.
|
|
</li><li>(f) <span class="extract"><span class="extract-syntax">primitive !le val val -> val</span></span>.
|
|
</li></ul>
|
|
<p class="commentary firstcommentary"><a id="SP6" class="paragraph-anchor"></a><b>§6. Sequential evaluation. </b>The reason for the existence of <span class="extract"><span class="extract-syntax">!ternarysequential</span></span> is that it's a convenient
|
|
shorthand, and also that it helps the code generator with I6 generation,
|
|
because I6 has problems with the syntax of complicated sequential evals.
|
|
</p>
|
|
|
|
<ul class="items"><li>(a) <span class="extract"><span class="extract-syntax">primitive !sequential val val -> val</span></span>. Evaluates the first, then the second
|
|
value, producing that second value.
|
|
</li><li>(a) <span class="extract"><span class="extract-syntax">primitive !ternarysequential val val val -> val</span></span>. Evaluates the first,
|
|
then the second, then the third value, producing that third value.
|
|
</li></ul>
|
|
<p class="commentary firstcommentary"><a id="SP7" class="paragraph-anchor"></a><b>§7. Random numbers. </b>There is just one primitive for this:
|
|
</p>
|
|
|
|
<ul class="items"><li>(a) <span class="extract"><span class="extract-syntax">primitive !random val -> val</span></span>. Produce a uniformly random integer in the range 0 up to <span class="extract"><span class="extract-syntax">val</span></span> minus 1.
|
|
</li></ul>
|
|
<p class="commentary firstcommentary"><a id="SP8" class="paragraph-anchor"></a><b>§8. Printing. </b>These print data of various kinds:
|
|
</p>
|
|
|
|
<ul class="items"><li>(a) <span class="extract"><span class="extract-syntax">primitive !print val -> void</span></span>. Print text.
|
|
</li><li>(b) <span class="extract"><span class="extract-syntax">primitive !printnumber val -> void</span></span>. Print a (signed) number in decimal.
|
|
</li><li>(c) <span class="extract"><span class="extract-syntax">primitive !printchar val -> void</span></span>. Print a character value.
|
|
</li><li>(d) <span class="extract"><span class="extract-syntax">primitive !printnl void -> void</span></span>. Print a newline. (This is needed because
|
|
some of our VMs use character 10 for newline, and crash on 13, and others vice versa.)
|
|
</li><li>(e) <span class="extract"><span class="extract-syntax">primitive !printdword val -> void</span></span>. Print a dictionary word.
|
|
</li><li>(f) <span class="extract"><span class="extract-syntax">primitive !printstring val -> void</span></span>. Print a packed string.
|
|
</li></ul>
|
|
<p class="commentary">There are also two primitive ways to change the visual style of text:
|
|
</p>
|
|
|
|
<ul class="items"><li>(a) <span class="extract"><span class="extract-syntax">primitive !font val -> void</span></span>. Change to fixed-width font if value is 1, or regular if 0.
|
|
</li><li>(b) <span class="extract"><span class="extract-syntax">primitive !style val -> void</span></span>. Change to this text style.
|
|
</li></ul>
|
|
<p class="commentary">The effect of these will depend on the platform the final Inter code is generated
|
|
for. If the value supplied to <span class="extract"><span class="extract-syntax">!style</span></span> is 0, 1, 2 or 3, then this should make an
|
|
effort to achieve roman, bold, italic, or reverse-video type, respectively, and
|
|
that should apply across all platforms. Use of any other value is likely to be
|
|
less portable. On C, for example, all other uses of <span class="extract"><span class="extract-syntax">!style</span></span> are (Inform) text
|
|
values which supply names for styles.
|
|
</p>
|
|
|
|
<p class="commentary">Lastly, a primitive for a rum feature of Inform 6 allowing for the display of
|
|
"box quotations" on screen:
|
|
</p>
|
|
|
|
<ul class="items"><li>(a) <span class="extract"><span class="extract-syntax">primitive !box val -> void</span></span>.
|
|
</li></ul>
|
|
<p class="commentary firstcommentary"><a id="SP9" class="paragraph-anchor"></a><b>§9. Stack access. </b>The stack is not directly accessible anywhere in memory, so the only access
|
|
is via the following.
|
|
</p>
|
|
|
|
<ul class="items"><li>(a) <span class="extract"><span class="extract-syntax">primitive !push val -> void</span></span>. Push value onto the stack.
|
|
</li><li>(b) <span class="extract"><span class="extract-syntax">primitive !pull ref -> void</span></span>. Pull value from the stack and write it into
|
|
the storage referred to. Values on the stack have unchecked kinds: it's up to
|
|
the author not to pull an inappropriate value.
|
|
</li></ul>
|
|
<p class="commentary firstcommentary"><a id="SP10" class="paragraph-anchor"></a><b>§10. Accessing storage. </b>Here the <span class="extract"><span class="extract-syntax">ref</span></span> term is a refernce to a piece of storage: a property of an
|
|
instance, or a global variable, or an entry in memory, for example.
|
|
</p>
|
|
|
|
<ul class="items"><li>(a) <span class="extract"><span class="extract-syntax">primitive !store ref val -> val</span></span>. Put the value in <span class="extract"><span class="extract-syntax">ref</span></span>.
|
|
</li><li>(b) <span class="extract"><span class="extract-syntax">primitive !setbit ref val -> void</span></span>. Set bits in the mask <span class="extract"><span class="extract-syntax">val</span></span> in <span class="extract"><span class="extract-syntax">ref</span></span>.
|
|
</li><li>(c) <span class="extract"><span class="extract-syntax">primitive !clearbit ref val -> void</span></span>. Clear bits in the mask <span class="extract"><span class="extract-syntax">val</span></span> in <span class="extract"><span class="extract-syntax">ref</span></span>.
|
|
</li><li>(d) <span class="extract"><span class="extract-syntax">primitive !postincrement ref -> val</span></span>. Performs the equivalent of <span class="extract"><span class="extract-syntax">ref++</span></span>.
|
|
</li><li>(e) <span class="extract"><span class="extract-syntax">primitive !preincrement ref -> val</span></span>. Performs the equivalent of <span class="extract"><span class="extract-syntax">++ref</span></span>.
|
|
</li><li>(f) <span class="extract"><span class="extract-syntax">primitive !postdecrement ref -> val</span></span>. Performs the equivalent of <span class="extract"><span class="extract-syntax">ref--</span></span>.
|
|
</li><li>(g) <span class="extract"><span class="extract-syntax">primitive !predecrement ref -> val</span></span>. Performs the equivalent of <span class="extract"><span class="extract-syntax">--ref</span></span>.
|
|
</li></ul>
|
|
<p class="commentary">Memory can be accessed with the following. The first value is the address of
|
|
the array; the second is an offset, that is, with 0 being the first entry,
|
|
1 the second, and so on. "Word" in this context means either an <span class="extract"><span class="extract-syntax">int16</span></span> or
|
|
an <span class="extract"><span class="extract-syntax">int32</span></span>, depending on what virtual machine are compiling to.
|
|
</p>
|
|
|
|
<ul class="items"><li>(a) <span class="extract"><span class="extract-syntax">primitive !lookup val val -> val</span></span>. Find word at this word offset.
|
|
</li><li>(b) <span class="extract"><span class="extract-syntax">primitive !lookupbyte val val -> val</span></span>. Find byte at this byte offset.
|
|
</li></ul>
|
|
<p class="commentary firstcommentary"><a id="SP11" class="paragraph-anchor"></a><b>§11. Indirect function calls. </b>Invocations of functions can only be made with <span class="extract"><span class="extract-syntax">inv</span></span> when the function is
|
|
specified as a constant, and when its signature is therefore known. If
|
|
we need to call "whatever function this variable refers to", we have to
|
|
use one of the following. They differ only in their signatures. The
|
|
first value is the function address, and subsequent ones are arguments.
|
|
</p>
|
|
|
|
<ul class="items"><li>(a) <span class="extract"><span class="extract-syntax">primitive !indirect0v val -> void</span></span>.
|
|
</li><li>(b) <span class="extract"><span class="extract-syntax">primitive !indirect1v val val -> void</span></span>.
|
|
</li><li>(c) <span class="extract"><span class="extract-syntax">primitive !indirect2v val val val -> void</span></span>.
|
|
</li><li>(d) <span class="extract"><span class="extract-syntax">primitive !indirect3v val val val val -> void</span></span>.
|
|
</li><li>(e) <span class="extract"><span class="extract-syntax">primitive !indirect4v val val val val val -> void</span></span>.
|
|
</li><li>(f) <span class="extract"><span class="extract-syntax">primitive !indirect5v val val val val val val -> void</span></span>.
|
|
</li><li>(g) <span class="extract"><span class="extract-syntax">primitive !indirect0 val -> val</span></span>.
|
|
</li><li>(h) <span class="extract"><span class="extract-syntax">primitive !indirect1 val val -> val</span></span>.
|
|
</li><li>(i) <span class="extract"><span class="extract-syntax">primitive !indirect2 val val val -> val</span></span>.
|
|
</li><li>(j) <span class="extract"><span class="extract-syntax">primitive !indirect3 val val val val -> val</span></span>.
|
|
</li><li>(k) <span class="extract"><span class="extract-syntax">primitive !indirect4 val val val val val -> val</span></span>.
|
|
</li><li>(l) <span class="extract"><span class="extract-syntax">primitive !indirect5 val val val val val val -> val</span></span>.
|
|
</li></ul>
|
|
<p class="commentary firstcommentary"><a id="SP12" class="paragraph-anchor"></a><b>§12. External function calls. </b>The following calls a function which is not part of the program itself, and
|
|
which is assumed to be provided by code written in a different programming
|
|
language. It cannot be used when Inter is being generated to Inform 6
|
|
code, because I6 has no ability to link with external code; but it can be
|
|
used when generating C, for example.
|
|
</p>
|
|
|
|
<p class="commentary">The first value must be a literal double-quoted text, and is the name of
|
|
the external function. The second value is an argument to pass to it; and
|
|
the result is whatever value it returns.
|
|
</p>
|
|
|
|
<ul class="items"><li>(a) <span class="extract"><span class="extract-syntax">primitive !externalcall val val -> val</span></span>.
|
|
</li></ul>
|
|
<p class="commentary firstcommentary"><a id="SP13" class="paragraph-anchor"></a><b>§13. Control flow. </b>The simplest control statement is an "if". Note that a different primitive
|
|
is used if there is an "else" attached: it would be impossible to use the
|
|
same primitive for both because they couldn't have the same signature.
|
|
</p>
|
|
|
|
<p class="commentary"><span class="extract"><span class="extract-syntax">!ifdebug</span></span> is an oddity: it executes the code only if the program is
|
|
being compiled in "debugging mode". (In Inform, that would mean that the
|
|
story file is being made inside the application, or else released in a
|
|
special testing configuration.) While the same effect could be achieved
|
|
using conditional compliation splats, this is much more efficient.
|
|
</p>
|
|
|
|
<ul class="items"><li>(a) <span class="extract"><span class="extract-syntax">primitive !if val code -> void</span></span>.
|
|
</li><li>(b) <span class="extract"><span class="extract-syntax">primitive !ifelse val code code -> void</span></span>.
|
|
</li><li>(c) <span class="extract"><span class="extract-syntax">primitive !ifdebug code -> void</span></span>.
|
|
</li></ul>
|
|
<p class="commentary">There are then several loops.
|
|
</p>
|
|
|
|
<ul class="items"><li>(a) <span class="extract"><span class="extract-syntax">primitive !while val code -> void</span></span>. Similar to <span class="extract"><span class="extract-syntax">while</span></span> in C.
|
|
</li><li>(b) <span class="extract"><span class="extract-syntax">primitive !for val val val code -> void</span></span>. Similar to <span class="extract"><span class="extract-syntax">for</span></span> in C.
|
|
</li><li>(c) <span class="extract"><span class="extract-syntax">primitive !objectloopx ref val code -> void</span></span>. A loop over instances,
|
|
stored in the variable <span class="extract"><span class="extract-syntax">ref</span></span>, of the kind of object <span class="extract"><span class="extract-syntax">val</span></span>.
|
|
</li><li>(d) <span class="extract"><span class="extract-syntax">primitive !objectloop ref val val code -> void</span></span>. A more general form,
|
|
where the secomd <span class="extract"><span class="extract-syntax">val</span></span> is a condition to be evaluated which decides whether
|
|
to execute the code for given <span class="extract"><span class="extract-syntax">ref</span></span> value.
|
|
</li></ul>
|
|
<p class="commentary">A switch statement takes a value, and then executes at most one of an
|
|
arbitrary number of possible code segments. This can't be implemented with
|
|
a single primitive, because its signature would have to be of varying
|
|
lengths with different uses (since some switches have many cases, some few).
|
|
Instead: a <span class="extract"><span class="extract-syntax">switch</span></span> takes a single <span class="extract"><span class="extract-syntax">code</span></span>, but that <span class="extract"><span class="extract-syntax">code</span></span> can in turn
|
|
contain only invocations of <span class="extract"><span class="extract-syntax">!case</span></span>, followed optionally by one of <span class="extract"><span class="extract-syntax">!default</span></span>.
|
|
</p>
|
|
|
|
<ul class="items"><li>(a) <span class="extract"><span class="extract-syntax">primitive !switch val code -> void</span></span>.
|
|
</li><li>(b) <span class="extract"><span class="extract-syntax">primitive !case val code -> void</span></span>.
|
|
</li><li>(c) <span class="extract"><span class="extract-syntax">primitive !default code -> void</span></span>.
|
|
</li></ul>
|
|
<p class="commentary">This looks a little baroque, but it works in practice:
|
|
</p>
|
|
|
|
<pre class="displayed-code all-displayed-code code-font">
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">inv</span><span class="plain-syntax"> </span><span class="function-syntax">!switch</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">val</span><span class="plain-syntax"> </span><span class="identifier-syntax">K_number</span><span class="plain-syntax"> X</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">code</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">inv</span><span class="plain-syntax"> </span><span class="function-syntax">!case</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">val</span><span class="plain-syntax"> </span><span class="identifier-syntax">K_number</span><span class="plain-syntax"> </span><span class="constant-syntax">1</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">code</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">inv</span><span class="plain-syntax"> </span><span class="function-syntax">!print</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">val</span><span class="plain-syntax"> </span><span class="identifier-syntax">K_text</span><span class="plain-syntax"> </span><span class="string-syntax">"One!"</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">inv</span><span class="plain-syntax"> </span><span class="function-syntax">!case</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">val</span><span class="plain-syntax"> </span><span class="identifier-syntax">K_number</span><span class="plain-syntax"> </span><span class="constant-syntax">2</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">code</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">inv</span><span class="plain-syntax"> </span><span class="function-syntax">!print</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">val</span><span class="plain-syntax"> </span><span class="identifier-syntax">K_text</span><span class="plain-syntax"> </span><span class="string-syntax">"Two!"</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">inv</span><span class="plain-syntax"> </span><span class="function-syntax">!default</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">code</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">inv</span><span class="plain-syntax"> </span><span class="function-syntax">!print</span>
|
|
<span class="plain-syntax"> </span><span class="reserved-syntax">val</span><span class="plain-syntax"> </span><span class="identifier-syntax">K_text</span><span class="plain-syntax"> </span><span class="string-syntax">"Something else!"</span>
|
|
</pre>
|
|
<p class="commentary">As in most C-like languages, there are primitives for:
|
|
</p>
|
|
|
|
<ul class="items"><li>(a) <span class="extract"><span class="extract-syntax">primitive !break void -> void</span></span>. Exit the innermost switch case or loop.
|
|
</li><li>(b) <span class="extract"><span class="extract-syntax">primitive !continue void -> void</span></span>. Complete the current iteration of
|
|
the innermost loop.
|
|
</li></ul>
|
|
<p class="commentary">Two ways to terminate what's happening:
|
|
</p>
|
|
|
|
<ul class="items"><li>(a) <span class="extract"><span class="extract-syntax">primitive !return val -> void</span></span>. Finish the current function, giving the
|
|
supplied value as the result if the function is being executed in a value
|
|
context, and throwing it away if not.
|
|
</li><li>(b) <span class="extract"><span class="extract-syntax">primitive !quit void -> void</span></span>. Halt the whole program immediately.
|
|
</li></ul>
|
|
<p class="commentary">And, lastly, the lowest-level way to travel:
|
|
</p>
|
|
|
|
<ul class="items"><li>(a) <span class="extract"><span class="extract-syntax">primitive !jump lab -> void</span></span>. Jumo to this label in the current function.
|
|
</li></ul>
|
|
<p class="commentary firstcommentary"><a id="SP14" class="paragraph-anchor"></a><b>§14. Interactive fiction-only primitives. </b>The following would make no sense in a general-purpose program. Most mirror
|
|
very low-level I6 features, and Inform uses them mainly when converting
|
|
I6 code into inter: in almost all cases it's better to call routines in the
|
|
template rather than to use these. First, the spatial containment object tree:
|
|
</p>
|
|
|
|
<ul class="items"><li>(a) <span class="extract"><span class="extract-syntax">primitive !move val val -> void</span></span>. Moves first to second (both are objects).
|
|
</li><li>(b) <span class="extract"><span class="extract-syntax">primitive !in val val -> val</span></span>. Tests if first is in second (both are objects).
|
|
</li><li>(c) <span class="extract"><span class="extract-syntax">primitive !notin val val -> val</span></span>. Negation of same.
|
|
</li></ul>
|
|
<p class="commentary">Object class membership:
|
|
</p>
|
|
|
|
<ul class="items"><li>(a) <span class="extract"><span class="extract-syntax">primitive !ofclass val val -> val</span></span>. Does the first belong to the enumerated
|
|
subkind whose weak type ID is the second value?
|
|
</li></ul>
|
|
<p class="commentary">Direct access to virtual machine object properties:
|
|
</p>
|
|
|
|
<ul class="items"><li>(a) <span class="extract"><span class="extract-syntax">primitive !propertyvalue val val -> val</span></span>.
|
|
</li><li>(b) <span class="extract"><span class="extract-syntax">primitive !propertyaddress val val -> val</span></span>.
|
|
</li><li>(c) <span class="extract"><span class="extract-syntax">primitive !propertylength val val -> val</span></span>.
|
|
</li><li>(d) <span class="extract"><span class="extract-syntax">primitive !propertyexists val val -> val</span></span>.
|
|
</li></ul>
|
|
<nav role="progress"><div class="progresscontainer">
|
|
<ul class="progressbar"><li class="progressprev"><a href="M-cpiti.html">❮</a></li><li class="progresscurrentchapter">M</li><li class="progresssection"><a href="M-ui.html">ui</a></li><li class="progresssection"><a href="M-ti.html">ti</a></li><li class="progresssection"><a href="M-dpiti.html">dpiti</a></li><li class="progresssection"><a href="M-cpiti.html">cpiti</a></li><li class="progresscurrent">ip</li><li class="progresssection"><a href="M-ia.html">ia</a></li><li class="progresssection"><a href="M-io.html">io</a></li><li class="progresssection"><a href="M-pas.html">pas</a></li><li class="progresssection"><a href="M-rc.html">rc</a></li><li class="progresschapter"><a href="1-mn.html">1</a></li><li class="progressnext"><a href="M-ia.html">❯</a></li></ul></div>
|
|
</nav><!--End of weave-->
|
|
|
|
</main>
|
|
</body>
|
|
</html>
|
|
|