![]() | Department of Computer
Science The University of Arizona Tucson, Arizona IPD169f February 3, 1997 http://www.cs.arizona.edu/icon/docs/ipd169.htm |
loads an icode file [Griswold86] specified by the file nameload(s, L, f1, f2, f3, i1, i2, i3)
s,
creates a task for it and returns a co-expression corresponding to the invocation
of the procedure main(L) in the loaded icode file. L
defaults to the empty list. Unlike conventional Icon command-line
argument lists, the argument list passed to load() can contain
values of any type, such as procedures, lists, and tables in the calling
task.load()
is termed the parent. The collection of all tasks forms a tree of parent-child
relationships.f1, f2, and f3 are three file arguments
to use as &input, &output, and &error
in the loaded task; &input, &output, and
&error default to those of the loading task. i1,
i2, and i3 are three integer arguments that supply
initial region sizes for the task's block, string, and stack memory areas,
respectively. i1 and i2 default to 65000, while
i3 defaults to 20000 (the defaults may be changed by the environment
variables BLKSIZE, STRSIZE, and MSTKSIZE).
load() is activated like any other
co-expression. When activated with the @ operator, the child
task begins executing its main procedure. Unless it suspends or activates
&source, the child task runs to completion, after which
control is returned to the parent. Chapter 5 presents an alternative means
of executing a child with which the parent retains control over the child
as it executes.
seqload,
which loads and executes each of its arguments (string names of executable
Icon programs) in turn. In this program the variable arguments is a list
of strings passed into the Icon program from the operating system. Each
of these strings (extracted from the list using the element-generation operator,
!) is passed in turn to load(). load()
reads the code for each argument and creates a task in which to execute
the loaded program; the tasks are then executed one-by-one by the co-expression
activation operator, @. This is ordinary Icon code; there is
nothing special about this example except the semantics of the load()
function and the independent execution environment (separate global variables,
heaps, and so forth), that load() provides to each task.
For example, if three Icon programs whose executable files are named translate, assemble, and link are to be run in succession, the command# seqload.icn procedure main(arguments) every @load(!arguments) end
seqload translate assemble link
main()'s argument list, through co-expression activation, or
by use of event monitoring facilities described in [Griswold92b]. In the
following pair of programs, the parent receives a list value from the child
and writes its elements out in reverse order.
# parent.icn
procedure main()
L := @ load("child")
while write(pull(L))
end
# child.icn
procedure main()
L := []
while put(L, read())
return L
end
This data access applies to all first-class data objects in Icon, such as
procedures and co-expressions.
calc()
and a main procedure that exports a reference to calc() for
sharing:
Note that a module exporting shared procedures can also have global variables (possibly initialized from other command-line arguments). Shared modules can export other values besides procedures using the same mechanism.# calc.icn procedure calc(args...) # code for calc # (may call other routines in calc.icn if there are any) end procedure main() # initialization code, if any return calc end
loadlib() in this example) of an
Icon table to store references to shared routines. The parent passes this
procedure to clients. Each client calls the procedure for each shared routine.
Routines that are already loaded are returned to requesting tasks after
a simple Icon table lookup. Whenever a routine is requested that has not
been loaded, the load() function is called and the shared library
activated.
procedure main(arguments)
@load("client",put(arguments,loadlib))
end
procedure loadlib(s, C)
static sharedlib
initial sharedlib := table()
sharedlib[s] := @load(s)
variable(s, C) := sharedlib[s]
end
A client of calc declares a global variable named calc,
and assigns its value after inspecting its argument list to find the shared
library loader:
global loadlib
global calc
procedure main(arguments)
if /loadlib then stop("no shared libraries present")
loadlib("calc", ¤t)
# ... remainder of program may call shared calc
end
¤t.cofail(C) : n transmit failure cofail(C) activates C and transmits a failure to it. It returns the transmitted value from the current co-expression's next activator, similar to @C. Default: C &source Error: 118 C not co-expression
display(i,f,C) : n display variables display(i,f,C) writes the image of the supplied co-expression and the values of the local variables of the i most recent procedure activations within C to file f. Defaults: i &level f &errout C ¤t Error: 118 C not co-expression
fieldnames(R) : s generate field names fieldnames(R) generates the names of the fields in record R in the order in which they appear in R's record declaration. Error: 107 R not record
globalnames(C) : s generate global variable names globalnames(C) generates the names of global identifiers in the task that contains co-expression C. Default: C ¤t Error: 118 C not co-expression
keyword(s, C) : s produce keyword keyword(s, C) produces the keyword named s in the task that contains C. The string name does not include the ampersand character (&). This function is supported for keywords whose values vary from task to task, summarized in the following table:
&allocated &errornumber &eventcode &input &pos &source &collections &errortext &eventsource &line &progname &storage &column &errorvalue &eventvalue &main &random &subject &error &errout &file &output ®ions &trace
On Icon systems with graphics facilities, the function also supports &window, &col, &row, &x, and &y. Note that &level and &time are not yet supported; this is a bug. keyword() fails on keywords such as &cset that are constants or are the same in all tasks. keyword() produces a variable if the corresponding keyword may be assigned to. Default: C ¤t Error: 118 C not co-expression
load(s,L,f1,f2,f3,i1,i2,i3) : C load task load(s,L,f1,f2,f3,i1,i2,i3) loads an icode file specified by file name s, creates a task for it, and returns a co-expression corresponding to the invocation of the procedure main(L) in the loaded task. f1, f2, and f3 are the child task standard input, output, and error files. If f1, f2, or f3 is closed by the parent or the child and subsequently used in the other task, dire consequences will result as the closure is not reflected in the other task. i1, i2, and i3 are the child task block region, string region, and stack sizes. Defaults: L [] f1 caller's &input f2 caller's &output f3 caller's &error i1 65000 or BLKSIZE i2 65000 or STRSIZE i3 10000 or MSTKSIZE Errors: 101 i1, i2, or i3 not integer 103 s not string 105 f1, f2, or f3 not file 108 L not list
localnames(x, i) : s generate local variable names localnames(p) generates the names of the local variables of procedure p. localnames(C, i) generates the local identifiers i levels above the currently active procedure in co-expression C. localnames() fails if i is larger than the level of the current procedure activation within C. Defaults: C ¤t i 0 Errors: 118 C not co-expression 101 i not integer 205 i less than zero
name(x,C) produce variable name name(x,C) produces the name of variable x. name() fails if x is not a variable from the task that contains co-expression C. Default: C ¤t Error: 118 C not co-expression
paramnames(x, i) : s generate parameter names paramnames(p) generates the names of the parameters of procedure p. paramnames(C, i) generates the names of the parameters i levels above the currently active procedure in co-expression C. paramnames() fails if i is larger than the level of the current procedure activation within C. Defaults: C ¤t i 0 Errors: 118 C not co-expression 101 i not integer 205 i less than zero
parent(C) : C produce parent's &main parent(C) produces the parent's &main with respect to the task that contains co-expression C. parent(C) fails if C is part of the root task. Default: C ¤t Error: 118 C not co-expression
proc(x, i, C) : p convert to procedure proc(x, i, C) produces the procedure named s within the task that contains C. Default: C ¤t Errors: 101 i not integer 118 C not co-expression
staticnames(x, i): s generate static variable names
staticnames(p) generates the names of the static variables of procedure p. staticnames(C, i) generates the names of all the static variables in the currently active procedure in the co-expression argument C. staticnames() fails if i is larger than the level of the current procedure activation within C.
Defaults: C ¤t
i 0
Errors: 118 C not co-expression
101 i not integer
205 i less than zero
variable(s, C, i): x produce variable
variable(s, C, i) produces the variable for the identifier or keyword named s within the task that created the co-expression argument C, examining local and static scopes i levels above the currently active procedure in C, and then checking for a global variable or keyword if no local or static variable by that name is found. variable() fails if i is larger than the level of the current procedure activation within C.
Defaults: C ¤t
i 0
Errors: 118 C not co-expression
101 i not integer
205 i less than zero
&column
A new keyword, &column, produces the current source column at which execution is taking place. &column is analogous to &line.