Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
SECD machine
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Registers and memory== The SECD machine is [[Stack (abstract data type)|stack-based]]. Functions take their arguments from the stack. The arguments to built-in instructions are encoded immediately after them in the instruction stream. Like all internal data-structures, the stack is a list, with the '''<code>S</code>''' register pointing at the list's ''head'' or beginning. Due to the list structure, the stack need not be a continuous block of memory, so stack space is available as long as there is a single free memory cell. Even when all cells have been used, [[garbage collection (computer science)|garbage collection]] may yield additional free memory. Obviously, specific implementations of the SECD structure can implement the stack as a canonical stack structure, thus improving the overall efficiency of the virtual machine, provided that a strict bound be put on the dimension of the stack. The '''<code>C</code>''' register points at the head of the code or instruction list that will be evaluated. Once the instruction there has been executed, the '''<code>C</code>''' is pointed at the next instruction in the list—it is similar to an ''instruction pointer'' (or [[program counter]]) in conventional machines, except that subsequent instructions are always specified during execution and are not by default contained in subsequent memory locations, as is the case with the conventional machines. The current variable environment is managed by the '''<code>E</code>''' register, which points at a list of lists. Each individual list represents one environment level: the parameters of the current function are in the head of the list, variables that are free in the current function, but bound by a surrounding function, are in other elements of '''<code>E</code>'''. The dump, at whose head the '''<code>D</code>''' register points, is used as temporary storage for values of the other registers, for example during function calls. It can be likened to the return stack of other machines. The memory organization of the SECD machine is similar to the model used by most functional language [[interpreter (computer software)|interpreters]]: a number of memory cells, each of which can hold either an ''atom'' (a simple value, for example ''13''), or represent an empty or non-empty list. In the latter case, the cell holds two pointers to other cells, one representing the first element, the other representing the list except for the first element. The two pointers are traditionally named [[CAR and CDR|''car'' and ''cdr'']] respectively—but the more modern terms ''head'' and ''tail'' are often used instead. The different types of values that a cell can hold are distinguished by a ''[[Tagged architecture|tag]]''. Often different types of atoms (integers, strings, etc.) are distinguished as well. So, a list holding the numbers ''1'', ''2'', and ''3'', usually written as <code>(1 2 3)</code>, might be represented as follows: Address Tag Content (value for integers, car & cdr for lists) 9 [ integer | 2 ] 8 [ integer | 3 ] 7 [ list | 8 | 0 ] 6 [ list | 9 | 7 ] ... 2 [ list | 1 | 6 ] 1 [ integer | 1 ] 0 [ nil ] The memory cells 3 to 5 do not belong to our list, the cells of which can be distributed randomly over the memory. Cell 2 is the head of the list, it points to cell 1, which holds the first element's value, and the list containing only ''2'' and ''3'' (beginning at cell 6). Cell 6 points at a cell holding 2 and at cell 7, which represents the list containing only ''3''. It does so by pointing at cell 8 containing the value ''3'', and pointing at an empty list (''nil'') as cdr. In the SECD machine, cell 0 always implicitly represents the empty list, so no special tag value is needed to signal an empty list (everything needing that can simply point to cell 0). The principle that the cdr in a list cell must point at another list is just a convention. If both car and cdr point at atoms, that will yield a pair, usually written like <code>(1 . 2)</code>
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
SECD machine
(section)
Add topic