TRE INTERPRETER POLIZ-63* Ye.A.
ZHOGOLEV
Moscow (Received
26
1964)
September
of a translator for the IN this paper we describe the construction machine “Setun’ ” [I]. Because of the small capacity of the machine store we proceeded as follows. 1.
lo.
We took a simplified
version
of ALGOL-60 as the initial
language.
2’. We do the translation linearly (in a single run) so that neither the initial information nor the resulting program (or pseudo-program) is stored in the machine memory: the input of information is made for a single symbol which is processed at once, and when the next order (or pseudo-order) is received this is output immediately on punched tape. into a pseudo-code, which must be 3'. The algorithms are translated easily interpreted, and not into the actual machine language. The last point takes into account the fact that the “Setun’ ” has a two-level memory (a ferrite cube and a magnetic drum). As we showed in __ __ [ll, [2! simple interpretative systems are feasible on this machine when a considerable part of the interpretation is done during the time used to find a zero zone on the magnetic drum. Since in the use of efficient interpretative systems (see [ll) only one zone of the operative memory remains for the exchange of information with the magnetic drum (not including exchange with zones of the program) as well as for the execution of the simplest sub-routines, before calling any sub-routine into the operative memory we must have all the information needed to execute this sub-routine. Each such sub-routine
l
Zh.
vijichisl.
Mat.
mat.
performs
Fiz.
5,
a certain
operation
1, 67 - ‘76, 89
1965.
of the given
90
Ye.A.
Zhogolav
pseudo-code. To call down and execute any sub-routine it is necessary to indicate the corresponding operation of this pseudo-code in the required place of the pseudo-program. Thus, to construct a simple and efficient interpreter on the “Set& * in the pseudo-progrsm designed for it, all the addresses determining the information required in the execution of any algorithm must be set before the operation is performed. We usually call this method of representing algorithms the “Polish inverse representation” (POLIZ). The efficiency of an interpretative system largely depends on the content of the operations performed by the sub-routines included in it. Therefore from the very start we sought to make the set of “elementary” operations of the pseudo-code as worthwhile as possible. In this sense the given variant of POLIZ had to satisfy requirements which differed fundamentally from those [31. On the other hand, the translation algorithms are greatly simplified if we include in this set sub-routines which perform all the operations of ALGOL-60,since then the task of the translator will consist in the coding of identifiers, numbers and operations (as well as in the appropriate distribution of the store) and in placing them in a sequence which corresponds to POLIZ, the latter turning out to be sufficiently simple in this case for it to be done in a single run. In this paper we consider a specific variant of the interpreter POLIZ. We shall not give a complete description of the set of operations (of sub-routines), the main structure of which is obvious. We shall consider here only those operations which illustrate the basic ideas of this interpreter. The first variant of such sn interpreter was described in a report to the Scientific Research Seminar on Automatic Programming, held at Moscow State University in April. 1962, and its basic concepts were described in M. The present version incorporates a number of new ideas which permit further simplification of the translation algorithm. 2. In the present variant of POLIZ {~LrZ-63) the algorit~ is represented by a sequence of generalized addresses (see Cd) which we shall call the syllables of the representation. These syllables are of three types, differing in the value of their highest ternary digit (indicator) and they correspond to the three types of objects with which the given interpreter operates: operations, values, and references. An operation is the designation of a sub-routine (the generalized address of its beginning) and has the indicator w? = T. Here we denote an operation either by generally accepted symbols for operations or by underlined words. The execution of a syllable-operation by the interpreter consists in calling out the corresponding sub-routine into the
The
operative
interpreter
memoryand transferring
Poliz-63
control
91
to it.
A value is the information to which the sub;routines (operations) are applied, and has the indicator qI, = 0. A value can be real, integral, boolean or an address. A real value is represented by a long (18-digit) ternary word in the form of a floating-point number as used in the IP-3 system (see Cl]). The five highest digits of such a word give the ternary order p of the number, where, in this case, the only real values allowed are those for which the highest digit of the order contains a zero, i.e. \p\ <40. By representing real values in this way we can do calculations to roughly six correct decimal places in the range IO-l9 to 10t19. An integral value is a short ternary word, the decimal point being fixed in front of the lowest digit of this word. We can only have integral values which have zeros in the highest place and the lowest place after the point), i.e. integral values exceed 1093 in modulus. Using these integral numbers (including negative ones) we can enumerate all the long words, and these can be placed on the magnetic drum. The integral values are mainly intended for the control of the computing process. A boolean value is also represented by a short word, with a zero corresponding to the value false and a non-zero word (but with “‘p = 0) corresponding to the value true. The address is represented by a generalized address in the sense of [ll and is used to denote objects which are placed correspondingly in the machine store. In translation many identifiers are replaced by addresses. In form an address differs from an integral value only in that its smallest ternary digit can take any value which is an indicator of the length of the word in accordance with the structure of the generalized address. An address which replaces an identifier will here be denoted as follows: ) < identifier
> (.
For example
)x1(. All other types of values will be written in ALGOL.The execution of a syllable value by the interpreter consists in sending the given syllable to the working registers of the interpreter for subsequent use in the execution of the sub-routines. A syllable in a pseudo-program can be a value of any type. apart from a real value, since the latter is represented by a long word. A real value is sent to the working registers of the interpreter as a result of the execution of a syllable reference. A reference is the designation of an object (including a reference), represented by a short word with wW,= 1, and differs from an address
92
Ye.A.
Zhogoleu
only in the value of this indicator x9. In translation any identifier is replaced either by a reference of by an address. Here we shall denote a reference simply by the identifier which it replaces. The execution of a syllable-reference consists in substituting the given syllable by the object whose designation is the given reference and in repeatedly using it as the new syllable. Thus, if a reference is the designation of a value (including a real value) this value is sent to the working registers of the interpreter - this is what the basic intention of a syllable-reference is. When the reference is the designation of a reference, we are dealing with a reference of high rank, defined in an exactly analogous way to the way it is done for addresses of high rank (see [41). The final result of the executiou of a syllable-reference of high rank is the transfer of a value into the working registers of the interpreter or the execution of an operation, whose designation (of corresponding rank) was the given reference. 3. Accordingly, each operation. in a pseudo-program must be preceded by syllables giving the information for this operation. The amount of information and its nature is determined only by the nature of the content of each specific operation. An operation can be applied to one or more operands (arguments) which are always values. When it is being executed one or more values may be formed in the working registers of the interpreter as the result of this operation. These results are used to carry out the next operations, then are erased from the working registers of the interpreter as “used” operands. If any operand has to be stored in the working registers of the interpreter, it can always also be assigned to a number of results of the corresponding operation. The result of the execution of several operations can be formed not only in the working registers of the interpreter, but also on the magnetic drum; for example, in the execution of the operation : = Let us illustrate this using syllable in POLIZ being written
(assign). the examples given in Table on a separate line.
1, each
In these examples the operations have the following meaning. The operation + forms the sum of the last two operands in the working registers. The operation : = writes the first operand on to the magnetic drum at the address given by the second operand (the first operand is formed in the working registers of the interpreter before the second); no results are formed in the working registers of the interpreter. The operation go to substitutes the last operand (last in time of formation) for the “address of the executed syllable” according to which the interpreter chooses the next syllable to be executed, the address replacing
The
interpreter
Poliz-63
93
TABLE 1. Example
ALGOL representation z:=z+y
POLIZ
)z(
Example
ALGOL representation U: =a
[i]
; + := go to M
)M(
go to
PGLIZ
component := go to Ll [3]
by 3
component go to
the label M being the generalized address of the start of the sequence of syllables of the pseudo-program realizing the statement indicated by this label. The operation component puts in the working registers of the interpreter the value corresponding to the address equal to the sum of the last two operands, the address which replaces the identifier of the array a (switch identifier u) being the generalized address of the zero component of this array (switch). Here the switch declaration is ass-umed to be given by a list (table) of labels. In all its simplicity of interpretation POLIZ enables us to put algorithms in a very compact form. This is due to the fact that it does not contain many of the elements occurring in ordinary programs, such as the indication of the working registers for intermediate results, the codes of a number of “trivial” operations (such as sending information to any register) etc. What is also very useful in this sense is to set integral (and boolean) constants in explicit form in the pseudo-program. We can illustrate this to some extent by the examples given in Table 2. In this table we use the elementary functions of analysis as our operations. Their inclusion in the set of operations of the interpreter is very important from the point of view of its efficiency. In addition we illustrate in this table the realization of branching in the computing process. Only the operations then and index require any explanation here (the meaning of the other operations being obvious). If the first operand is equal to zero, the operation then substitutes the second operand for the “address of the executed syllable”. If not, this operation is equivalent to a dummyoperation with two operands (which are erased in the working registers of the interpreter). The operation index denotes fixed point addition. The labels labelling the syllables are put in the same line and are separated from the syllable by three dots.
Ye.A.
94
Zhogolev
TABLE 2. Exampl
ALGOL representation
POLIZ
u:=a+b x (c + Z/Y) t d
Jut
b”
Example
ALGOL sepresentat ion 2 [i - I] := if x>U then u [i] else 2, [i]
C X
7
y := sqrt (l$
sinkv
(4) t 2)
2 i + := y X
enp sin 2
POLIZ
I!( ; index 0” ‘t&
)f(
)& Ml. . .“p,‘p M2. . . e:mponent
:=
5sqrt :=
4. To carry out a pseudo-program constructed in this POLIZ a special organization of the “working registers of the interpreter” is required. For we have assumed throughout that a value formed in the working registers of the interpreter by the latter is used (and, therefore also erased) by the former and, conversely, the value formed by the former is used by the latter. This means that the registers must form a memory of the “stack” type. A stack (as we shall call this store in future) can, in principle, consist of sn arbitrary number of registers. However, there must be sufficient of them for the execution of the algorithms permitted in each specific variant of POLIZ. For example, to do example 5 we require at least six registers in the stack. A stack of only two registers is sufficient to translate any ALGOLrepresentation into FOLIZ in such a way that the stack is not overfilled in doing so. This question is discussed in the diploma research of Kh. Ramil’ Alvarez and V.M. Terekhin (Moscow State University, Faculty of Mechanics and Mathematics, Departwhich is based on the use of ment of Computational Mathematics, 1961/2), the first variant of the POLIZ interpreter. A restriction
on the number of registers
in the stack naturally
The
interpreter
Poliz-63
95
places certain restrictions on the POLIZ too, and this also complicates the translation algorithms. In particular, in such cases the problem of storing intermediate results is not completely eliminated (for a stack with two registers the problem is very difficult). For this reason we have assumed in the interpreter POLIZ-63 that the stack has an unlimited number of registers. Each of these registers is intended for the storage of a long word. If a short word is sent to the stack, then it is stored in the higher digits of the register. We make the stack “unlimited” at the cost of dividing it into two levels. The first level is formed of seven registers placed together with the interpreter in the operative store. If this part of the stack is full, the interpreter brings down from the magnetic drum a special sub-routine which transfers part of the stack in the first level to a free place on the drum (the second level of the stack), thus freeing the corresponding part on the first level. These values are again transferred to the operative store when they are needed. Information about the “free places” on the drum is given by the translator in standard registers. Whenthe second level of the stack is full the machine stops, signifying that the store is too small to solve the given problem. 5. During the operation of POLIZ-63 the operative store of the “Setun’ ” is used as follows: The zone @r is used to store the next (next to be executed) zone of the pseudo-program; the zone 0, is the place for the execution of sub-routines realizing elementary operations of the given pseudo-code, and also for calling down information into the stack; the zone 0-r is used to store the interpreter itself, together with the first level of the stack and its other working registers. To define the sequence of executing the syllables of the pseudoprogram the working registers of the interpreter contain the quantity N, the generalized address of the syllable to be executed. This quantity can be changed either by the interpreter (on going to the execution of the next syllable) or by the sub-routines (in conditional and unconditional jumps of control). In certain sub-routines it C&I be used as an additional operand. In addition the working registers of the interpreter contain the quantity i which indicates the number of the free register in the stack. This quantity can be changed both by the interpreter and by the sub-routines in accordance with the number of values being used and stored in the stack.
Ye.A.
96
Zhogolev
Below we give the ALGOL representation of the operation scheme of the interpreter. It reflects both the programming features of the “Setun’ ” and our desire to make it as compact as possible, having to find room for it and its working registers in one zone of the operative store. Due to the difficulty of using ALGOLto describe specific programs given in machine language we give the scheme here in the form of a composite statement, and assume that it is contained in a block in which all the identifiers used have been described. Any information about the identifiers which is required to understand the algorithm is given in the comments.
comment This line of statements in the interpreter is not realized. It only reflects the original value of certain quantities, pre-set, for example, when the interpreter is input into the operative store. The identifier s simply denotes the values of the summator register of the machine and must be considered as a simple variable of the type real: NO denotes the value of the type real giving the address of the first Integer values here are given in the syllable of the pseudo-program. same form as in the operation of the interpreter. Therefore all the addresses will be multiples of l/3. The identifiers b and i denote simple variables of the type integer; LZ: s :=
L2: N:=
next(s);
s;
Comment
The identifier next denotes the procedure function which formulates the address of the syllable following some other syllable, according to its address (see [II ). N is a simple variable of the type real (its values are multiples of l/3), giving the address of the executed syllable of the pseudo-program; If
mb(s)
--M#
0 then begin call (1, Mb(s));
M:=
mb(s)
end;
The identifier mb denotes the procedure function which picks Comment s = nJ4sAs as a value of out IV, from the given generalized address the type integer, while the identifiers delta and pi (see below) denote procedure functions which pick out, respectively, A, as a value of the type real (multiple of l/3 and TT~as a value of the type integer. II the value of which gives the number is a variable of the type integer, of the next zone of the pseudo-program. This quantity is stored in the working registers of the interpreter. With the help of this conditional statement a new zone of the pseudo-program is called down;
The
k :=
interpreter
Poliz-63
97
1.
lX:j:=dklta(s);s:=C(k,j); &aent variable of inside the selects as zone Ok;
k is a simple variable of the type real. the value zone. C is the identifier a value of the type real
the type integer, j is a simple of which gives the relative address of a procedure function which the contents of the line j of the
if b = 1 then GOT0 (k, j) else stuck [i] : =
s;
GO TO is the identifier of the procedure which transfers concemremt trol to the row j of the 246ne ok (to a sub-routine), stack is the identifier of the array containing the stack (array stack [1 : 71) stack [i] denotes the first free register (window) of the stack. It should be noted that the next syllable to be executed is placed at once in the window of the stack; b :=
--pi(s);
if b # 0 then L4: L5:
begin call (0, mb (s)) ; k : = 0; go to L2 end else/:= i1;
Comment f is a simple variable of the type integer denoting the values of the index register of the stack. A jump to the next statement with the label L6 takes place from the majoritg of sub-routines. In this case in each such sub-routine the value f, corresponding to the number of used aed formulated values is formed; T,6: s:=N;i:=f;b:=O; if f # 0 then go to LI; outstack;
Cornment outstack is the identifier of the transfer of five values of the first magnetic drum. In the other (“favoured’) preter this procedure simply carries out is overfull;
the procedure which carries out level of the stack to the variant of the POLIZ-63 interan emergency stop when the stack
End The calling down of values from the second level of the stack is done by the sub-routines themselves: when the values in the first level of
98
Ye.A.
Zhogolev
the stack are not sufficient for them they refer to a special procedure (sub-routine) instack which carries out the reverse transfer of part of the values from the second to the first level of the stack. 6. Let us give the characteristics of some of the sub-routines which carry out typical elementary operations of the FOLIZ-63 interpreter. Any sub-routine which calculates the value of the function F of one variable executes the following operations: if i = 7 then instack; f:=i; stack[f
+ I] :=
F(stack[f
+ I]);
go ta L6;
Any sub-routine which calculates the value of the function F of two variables executes the following operations: if i >
5 then
instack;
f :=i+I;
stack[f + I] := F(stack[f
+ I], stack[f]);
go to L6;
Any sub-routine which calculates the values of the two functions Fl and F2 of one variable executes the following operations: if i =
7 then
instaqk;
f:=i; stack[f] := FZ (stack[f + I]); stack [f + I] : = FI (stack [f + I] ) ; go toL5;
The sub-routine operations: if i = 7 then
realizing
the operation go to executes the following
instack;
i:=i+I;p:=O; s := stack[i]; go toL2;
The sub-routine realizing following operations
the operation
component
executes the
The
it i >
Poliz-63
99
5 then instack;
i:=i+2;
b:=O;
s := stack[i] go to L4; The sub-routine operations: if i >
interpreter
+ stuck[i -
realizing
I];
the operation
: =
executes
the following
5 then instack;
f:=i+Z; M := mb(stack[f] put (l,deZta(stack
f]),stuck
[f -
I]);
output (I, M) ; Comment tne procedure statement put (k, j, a) writes a in the line j of the zone ok. The procedure statement (k, ,W) writes the zone @k in the zone u of the magnetic go
the value output drum;
to 1.6;
And, finally, the sub-routine the following operations: if i >
5 then
f:=i+2; it stnck If J #
realizing
the operation
then executes
instuck; 0 then go to L6;
s:=stack[f-l];i:=f;b:=O; go to L2; The above sub-routines illustrate sufficiently fully the organization of various types of sub-routines which realize elementary operations of the interpreter. The check for the presence in the first level of the stack of the operands for the sub-routine at the beginning of each subroutine and, when necessary, reference to the procedure instack, are a consequence of the lack of room in the operative memory for the “extended” interpreter and of the desire to make the whole system as high-speed as possible. With certain restrictions on POLIZ we could put these operations in a number of sub-routines (for instance, those which calculate the value of a function of one variable). These operations are lacking in all sub-routines for the “favoured” variant of the POLIZ-63 interpreter which deals only with the stack on the first level. This variant of the interpreter is used in manual programming at present.
100
Ye.A.
Zhogolev
The question of the complete set of elementary operations of the interpreter and of the algorithm for translation from ALGOL-60 into a specific variant of POLIZ is the subject of special research.
Translated
by R.
Feinstein
REFERENCES 1.
ZHOGOLEV,Ye.A. Commandand interpretation “Setun’ I(. Zh. vychisl. Mat. nat. Fiz.,
system for the machine 1, No. 3, 499 - 512, 1961.
2.
ZHOGOLEV,Ye.A. On Logical Structures and the Mathematical Servicing of Small Automatic Digital Machines (0 logicheskikh strukturakh i natematicheskom obsluzhivanii malykh tsifrovykh avtomaticheskikh mashin.) Candidate Dissertation in Physical and Mathematical Sciences, MOSCOW State University, MOSCOW, 1962.
3.
DIJKSTRA, E.W. An attempt to Unify the Constituent Concepts of Serial Program Execution. Symbolic Languages in Data Processing Symposium, Rome, III, Int. Calc. Centre, 1962.
4.
YUSHCHENKO. Ye.L. Address Programming Gostekhizdat, Kiev, 1963.
(Adresnoe
programmirovanie).