Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Jeffery C.The implementation of Icon and Unicon.2004

.pdf
Скачиваний:
13
Добавлен:
23.08.2013
Размер:
3.05 Mб
Скачать

355

A.2.4 Lists

A list consists of a list­header block that points to a doubly­linked list of list­element 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 list­element block:

356

A.2.5 Sets

A set consists of a set­header 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 set­element block for the member 3 is

357

A.2.6 Tables

A table is similar to a set, except that a table­header block contains the default assigned value as well as slots for linked lists of table­element 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 table­element 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 table­element 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 trapped­variable block for s [2:5] is

A table­element trapped­variable 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 table­element trapped­variable block for t[36] is

A.2.10 Co­Expressions

A co­expression 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 co­expression 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 source­language 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 co­expression block, restore state information from the co­expression block being activated, perform a context switch, and continue execution.

cofail Save the current state information in the current co­expression block, restore state information from the co­expression block being activated, perform a context switch, and continue execution with co­expression failure signal set.

compl ~expr

caret Save the current state information in the current co­expression block, restore state information from the co­expression block being activated, perform a context switch, and continue execution with co­expression return signal set.

create Allocate a co­expression 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 co­expression 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

Соседние файлы в предмете Электротехника