Previous: Using External Calls, Up: External Calls [Index]
INTERCAL-72 | C-INTERCAL | CLC-INTERCAL | J-INTERCAL |
---|---|---|---|
no | version 0.28+ | no | no |
The C-INTERCAL distribution comes with libraries that can
be used to extend its capabilities; they are implemented using the
external call mechanism, and are in effect standard files to include
using that mechanism. To use an expansion library, give the
-e option to ick
(note that this means you
cannot use them with the debugger or profiler, nor with multithreaded
or backtracking programs), and specify the expansion library’s
name at the end of the command line (or to be precise, anywhere after
the initial INTERCAL file). The libraries themselves
are written in C and have a ‘.c’ extension,
and are human-readable; C-INTERCAL will look for them in
the same places as it looks for the system library (including in the
current directory, so you can test your own expansion libraries without
having to install them).
Expansion libraries use C identifiers which start with the string ‘ick_my_’ (this is not used by the compiler, and is explicitly not affected by the prohibition on identifiers starting ‘ick_’ when writing an expansion library), and use line labels in the range (1600) to (1699). (Most programs will be avoiding this range anyway, because it’s inside the (1000) to (1999) range reserved for the system library, but the system library doesn’t use it, in much the same way that the identifiers used are inside the range reserved for the compiler, but the compiler doesn’t use them.)
Expansion libraries are available from C-INTERCAL version 0.28; CLC-INTERCAL has a similar concept (that of ‘preloads’), but implemented a completely different way.
syslibc is an implementation of the base-2 INTERCAL system library in C (see System Libraries); using it in programs running in other bases is accepted by the compiler, but likely to produce unpredictable results. When using this expansion library, you also need to give the -E option (see -E) so that the main system library is not included, or it will be used in preference to the expansion library. All documented features of the INTERCAL base-2 system library are implemented, but most undocumented features are not, so INTERCAL programs which relied on them (dubious behaviour in any case) will not work with syslibc. The main reason to use this library is to increase the speed of an INTERCAL program; however, note that the speed gains in arithmetic will be accompanied by the performance penalty of using the external calls infrastructure, unless you were already using it.
As an example of using ick_create
, a very simple expansion
library is provided to enable a computed NEXT capability, by defining a
new command COMPUNEX
. It is used as DO .1
COMPUNEX
(allowing any expression in place of the .1), and is
similar to an ordinary NEXT
, but has two limitations: it
takes up two NEXT
stack entries, and the top one should
not be RESUMEd
past or forgotten (thus it isn’t a
particularly useful command, except maybe to produce the equivalent of
something like function pointers). By the way, note that
C-INTERCAL avoids computed NEXT
mainstream
for much the same way that CLC-INTERCAL avoids
NEXT
altogether; it makes things too easy. This example is
provided mostly just to demonstrate the syntax, and the care that needs
to be taken with implementing flow control operators.
‘compunex’ is double-deprecated; an
alternative is the following sequence of commands involving computed
CREATE
:
DO CREATE .1 ABC DO ABC
This sequence emulates all features of NEXT
(although it
has different gerunds and is two statements, not one), making it much
more useful for simulating computed NEXT
than
COMPUNEX
is. (There’s no need to avoid forgetting
the return value; although this skips the CREATE
cleanup,
none is required because the created statement ABC
(any
other statement would do just as well) takes no arguments.)
Previous: Using External Calls, Up: External Calls [Index]