<ulclass="toc"><li><ahref="M-cpiti.html#SP1">§1. Code packages</a></li><li><ahref="M-cpiti.html#SP2">§2. Local variables</a></li><li><ahref="M-cpiti.html#SP3">§3. Labels</a></li><li><ahref="M-cpiti.html#SP4">§4. Primitive invocations</a></li><li><ahref="M-cpiti.html#SP6">§6. Function invocations</a></li><li><ahref="M-cpiti.html#SP7">§7. Val and cast</a></li><li><ahref="M-cpiti.html#SP8">§8. Ref, lab and code</a></li><li><ahref="M-cpiti.html#SP9">§9. Evaluation and reference</a></li></ul><hrclass="tocbar">
<pclass="commentary firstcommentary"><aid="SP1"class="paragraph-anchor"></a><b>§1. Code packages. </b>To recap: a file of textual inter has a brief global section at the top, and
<pclass="commentary">Note that <spanclass="extract"><spanclass="extract-syntax">package</span></span> is a data statement, not a code statement, and it follows
<pclass="commentary firstcommentary"><aid="SP2"class="paragraph-anchor"></a><b>§2. Local variables. </b>The statement <spanclass="extract"><spanclass="extract-syntax">local NAME KIND</span></span> gives the code package a local variable;
the <spanclass="extract"><spanclass="extract-syntax">NAME</span></span> must be a private <spanclass="extract"><spanclass="extract-syntax">misc</span></span> symbol in the package's symbols table.
<spanclass="plain-syntax"></span><spanclass="reserved-syntax">local</span><spanclass="plain-syntax"> x </span><spanclass="identifier-syntax">K_number</span>
<pclass="commentary">then a call <spanclass="extract"><spanclass="extract-syntax">Double(6)</span></span> would begin executing with <spanclass="extract"><spanclass="extract-syntax">x</span></span> equal to 6.
<pclass="commentary firstcommentary"><aid="SP3"class="paragraph-anchor"></a><b>§3. Labels. </b>Like labels in any assembly language, these are named reference points in the
code; they are written <spanclass="extract"><spanclass="extract-syntax">NAME</span></span>, where <spanclass="extract"><spanclass="extract-syntax">NAME</span></span> must be a private <spanclass="extract"><spanclass="extract-syntax">label</span></span> symbol
in the package's symbols table, and must begin with a full stop <spanclass="extract"><spanclass="extract-syntax">.</span></span>.
<pclass="commentary firstcommentary"><aid="SP4"class="paragraph-anchor"></a><b>§4. Primitive invocations. </b>Other than labels and locals, code is a series of "invocations". An invocation
<pclass="commentary">Primitives are, in effect, built-in functions. <spanclass="extract"><spanclass="extract-syntax">IN</span></span> can either be <spanclass="extract"><spanclass="extract-syntax">void</span></span> or
can be a list of one or more terms which are all either <spanclass="extract"><spanclass="extract-syntax">ref</span></span>, <spanclass="extract"><spanclass="extract-syntax">val</span></span>, <spanclass="extract"><spanclass="extract-syntax">lab</span></span> or
<spanclass="extract"><spanclass="extract-syntax">code</span></span>. <spanclass="extract"><spanclass="extract-syntax">OUT</span></span> can be either <spanclass="extract"><spanclass="extract-syntax">void</span></span> or else a single term which is either
<spanclass="extract"><spanclass="extract-syntax">ref</span></span> or <spanclass="extract"><spanclass="extract-syntax">val</span></span>. For example,
<pclass="commentary">declares that the signature of the primitive <spanclass="extract"><spanclass="extract-syntax">!plus</span></span> is <spanclass="extract"><spanclass="extract-syntax">val val -> val</span></span>,
<pclass="commentary">says that <spanclass="extract"><spanclass="extract-syntax">!ifelse</span></span> consumes a value and two blocks of code, and produces
nothing. Of course, <spanclass="extract"><spanclass="extract-syntax">!plus</span></span> adds the values, whereas <spanclass="extract"><spanclass="extract-syntax">!ifelse</span></span> evaluates
<pclass="commentary">The third term type, <spanclass="extract"><spanclass="extract-syntax">lab</span></span>, means "the name of a label". This must be an
<spanclass="extract"><spanclass="extract-syntax">!jump</span></span> is <spanclass="extract"><spanclass="extract-syntax">primitive !jump lab -> void</span></span> and not <spanclass="extract"><spanclass="extract-syntax">primitive !jump val -> void</span></span>.
<pclass="commentary">The final term type, <spanclass="extract"><spanclass="extract-syntax">ref</span></span>, means "a reference to a value", and is in
<pclass="commentary firstcommentary"><aid="SP5"class="paragraph-anchor"></a><b>§5. </b>A primitive is invoked by <spanclass="extract"><spanclass="extract-syntax">inv PRIMITIVE</span></span>, with any necessary inputs,
<pclass="commentary">would compute <spanclass="extract"><spanclass="extract-syntax">2+2</span></span>. This brings up the issue of "context". Code statements
<pclass="commentary">the invocation of <spanclass="extract"><spanclass="extract-syntax">!print</span></span> occurs at the top level of the function, in what
is called "void" context; but the <spanclass="extract"><spanclass="extract-syntax">val</span></span> statement occurs in value context,
because it appears where the <spanclass="extract"><spanclass="extract-syntax">!print</span></span> invocation expects to find a text value.
<pclass="commentary">is an error, because it makes no sense to evaluate <spanclass="extract"><spanclass="extract-syntax">!plus</span></span> in a void context:
the sum would just be thrown away unused. The context in which an <spanclass="extract"><spanclass="extract-syntax">inv</span></span>
statement is allowed depends on the <spanclass="extract"><spanclass="extract-syntax">OUT</span></span> part of the signature of its
primitive. Comparing the declarations of <spanclass="extract"><spanclass="extract-syntax">!print</span></span> and <spanclass="extract"><spanclass="extract-syntax">!plus</span></span>, we see:
<pclass="commentary">so that <spanclass="extract"><spanclass="extract-syntax">!print</span></span> can only be invoked in a void context, and <spanclass="extract"><spanclass="extract-syntax">!plus</span></span> in a
<pclass="commentary firstcommentary"><aid="SP6"class="paragraph-anchor"></a><b>§6. Function invocations. </b>The same statement, <spanclass="extract"><spanclass="extract-syntax">inv</span></span>, is also used to call functions which are not
<spanclass="plain-syntax"></span><spanclass="reserved-syntax">local</span><spanclass="plain-syntax"> x </span><spanclass="identifier-syntax">K_number</span>
<pclass="commentary">The value <spanclass="extract"><spanclass="extract-syntax">Double</span></span> now evaluates to this function, and that's what we
<pclass="commentary">It would not make sense, and is an error, to write <spanclass="extract"><spanclass="extract-syntax">inv Double_B</span></span>, because
<spanclass="extract"><spanclass="extract-syntax">Double_B</span></span> is a package name, not a value; and because there is no way to
know its signature. By contrast, <spanclass="extract"><spanclass="extract-syntax">Double</span></span> is indeed a value, and by looking
at its kind <spanclass="extract"><spanclass="extract-syntax">K_number_to_number</span></span>, we can see that the signature for the
invocation must be <spanclass="extract"><spanclass="extract-syntax">val -> val</span></span>.
<pclass="commentary firstcommentary"><aid="SP7"class="paragraph-anchor"></a><b>§7. Val and cast. </b>As has already been seen in the above examples, <spanclass="extract"><spanclass="extract-syntax">val KIND VALUE</span></span> can be
<pclass="commentary">In general, inter code has very weak type checking. <spanclass="extract"><spanclass="extract-syntax">val KIND VALUE</span></span> forces
the <spanclass="extract"><spanclass="extract-syntax">VALUE</span></span> to conform to the <spanclass="extract"><spanclass="extract-syntax">KIND</span></span>, but no check is made on whether
<pclass="commentary">is valid only in value context, and marks that a value of <spanclass="extract"><spanclass="extract-syntax">KIND2</span></span> needs to
be interpreted in some way as a value of <spanclass="extract"><spanclass="extract-syntax">KIND1</span></span>. For example, one might
<pclass="commentary firstcommentary"><aid="SP8"class="paragraph-anchor"></a><b>§8. Ref, lab and code. </b>Just as <spanclass="extract"><spanclass="extract-syntax">val</span></span> supplies a value as needed by a <spanclass="extract"><spanclass="extract-syntax">val</span></span> term in an invocation
signature, so <spanclass="extract"><spanclass="extract-syntax">ref</span></span>, <spanclass="extract"><spanclass="extract-syntax">lab</span></span> and <spanclass="extract"><spanclass="extract-syntax">code</span></span> meet the other possible requirements.
<pclass="commentary">Here <spanclass="extract"><spanclass="extract-syntax">.end</span></span> is the name of a label in the current function. References to
labels in other functions are impossible, because label names are all <spanclass="extract"><spanclass="extract-syntax">private</span></span>
to the current symbols table. No kind is mentioned in a <spanclass="extract"><spanclass="extract-syntax">lab</span></span> statement
<pclass="commentary">Here <spanclass="extract"><spanclass="extract-syntax">x</span></span> is the name of a variable, but it could be the name of any form of
storage. On the other hand, <spanclass="extract"><spanclass="extract-syntax">ref K_number 10</span></span> would be an error, because it
<pclass="commentary">compiles to something like <spanclass="extract"><spanclass="extract-syntax">if (flag) { print "Yes!"; }</span></span>. The <spanclass="extract"><spanclass="extract-syntax">code</span></span> statement
<pclass="commentary firstcommentary"><aid="SP9"class="paragraph-anchor"></a><b>§9. Evaluation and reference. </b>Using the mechanisms above, there is no good way to throw away an unwanted
<pclass="commentary"><spanclass="extract"><spanclass="extract-syntax">reference</span></span> is similarly a shim, but from reference context to value context.
<pclass="commentary">In general <spanclass="extract"><spanclass="extract-syntax">reference</span></span> must only be used where it can be proved that its