
Jeffery C.The implementation of Icon and Unicon.2004
.pdf
355
A.2.4 Lists
A list consists of a listheader block that points to a doublylinked list of listelement blocks, in which the list elements are stored in circular queues. See Chapter 6 for details. An example is the list
[1,2,3]
which is represented as
Here there is only one listelement block:

356
A.2.5 Sets
A set consists of a setheader block that contains slots for linked lists of set element blocks. See Sec. 7.1 for details. An example is given by
set([1, 2, 3, 4])
which is represented as
The setelement block for the member 3 is

357
A.2.6 Tables
A table is similar to a set, except that a tableheader block contains the default assigned value as well as slots for linked lists of tableelement blocks. See Sec. 7.2 for details. An example is given by
t := table()
every t[1 | 4 | 7] := 1
The table t is represented as
The tableelement block for the entry value 4 in the previous example is

358
A.2.7 Procedures
The procedure blocks for procedures and functions are similar. For a procedure declaration such as
procedure calc(i,j) local k
static base, index end
the procedure block is
In a procedure block for a function, there is a value of 1 in place of the number of dynamic locals. For example, the procedure block for repl is
In the case of a function, such as write, which has a variable number of arguments, the number of arguments is given as 1:

359
A.2.8 Files
The block for a file contains a pointer to the corresponding file, a word containing the file status, and a qualifier for the name of the file. For example, the block for &output is
The file status values are
0closed
1 open for reading
2 open for writing
4 open to create
8 open to append
16 open as a pipe
A.2.9 Trapped Variables
There are three kinds of trapped variables: keyword trapped variables, substring trapped variables, and tableelement trapped variables. The corresponding blocks are tailored to the kind of trapped variable.
The value of &trace illustrates a typical keyword trapped variable:

360
A substring trapped variable contains the offset and length of the substring, as well as a variable that points to the qpalifier for the string. For example, if the value of s is "abcdef", the substring trappedvariable block for s [2:5] is
A tableelement trappedvariable block contains a word for the hash number of the entry value, a pointer to the table, the entry value, and a descriptor reserved for the assigned value. For example, if t is a table, the tableelement trappedvariable block for t[36] is
A.2.10 CoExpressions
A coexpression block consists of heading information, an array of words for saving the C state, an interpreter stack, and a C stack:

361
The refresh block contains information derived from the procedure block for the procedure in which the coexpression was created. Consider, for example,
procedure labgen(s) local i, j, e
i := 1
j := 100
e := create (s || (i to j) || ":")
...
end
For the call labgen("L"), the refresh block for e is

362
0
363

364
Appendix B: Virtual Machine Instructions
This appendix lists all the Icon virtual machine instructions. For instructions that correspond to sourcelanguage operators, only the corresponding operations are shown. Unless otherwise specified, references to the stack mean the interpreter stack.
arg n Push a variable descriptor pointing to argument n. asgn expr1 := exp12
bang lexpr
bscan Push the current values of &subject and &pos. Convert the descriptor prior to these two descriptors into a string. If the conversion cannot be performed, terminate execution with an error message. Otherwise, assign it to &subject and assign 1 to &pos. Then suspend. If resumed, restore the former values of &subject and &pos and fail.
cat expr1 || exp12
ccase Push a copy of the descriptor just below the current expression frame. chfail n Change the failure ipc in the current expression frame marker to n.
coact Save the current state information in the current coexpression block, restore state information from the coexpression block being activated, perform a context switch, and continue execution.
cofail Save the current state information in the current coexpression block, restore state information from the coexpression block being activated, perform a context switch, and continue execution with coexpression failure signal set.
compl ~expr
caret Save the current state information in the current coexpression block, restore state information from the coexpression block being activated, perform a context switch, and continue execution with coexpression return signal set.
create Allocate a coexpression block and a refresh block. Copy the current procedure frame marker, argument values, and local identifier values into the refresh block. Place a procedure frame for the current procedure on the stack of the new coexpression block.
cset a Push a descriptor for the cset block at address a onto the stack.
diff |
expr1 expr2 |
div |
expr1 / expr2 |
dup |
Push a null descriptor onto the stack and then push a copy of the descriptor that |
was previously on top of the stack. |
|
efail |
If there is a generator frame in the current expression frame, resume its generator. |
Otherwise remove the current expression frame. If the ipc in its marker is nonzero, set ipc to it. If the failure ipc is zero, repeat efail.
eqv expr1 === expr2