123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd">
- <html>
- <!-- Created on December 10, 2012 by texi2html 1.82
- texi2html was written by:
- Lionel Cons <[email protected]> (original author)
- Karl Berry <[email protected]>
- Olaf Bachmann <[email protected]>
- and many others.
- Maintained by: Many creative people.
- Send bugs and suggestions to <[email protected]>
- -->
- <head>
- <title>avram - a virtual machine code interpreter: 3.1.7 Indirection</title>
- <meta name="description" content="avram - a virtual machine code interpreter: 3.1.7 Indirection">
- <meta name="keywords" content="avram - a virtual machine code interpreter: 3.1.7 Indirection">
- <meta name="resource-type" content="document">
- <meta name="distribution" content="global">
- <meta name="Generator" content="texi2html 1.82">
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <style type="text/css">
- <!--
- a.summary-letter {text-decoration: none}
- blockquote.smallquotation {font-size: smaller}
- pre.display {font-family: serif}
- pre.format {font-family: serif}
- pre.menu-comment {font-family: serif}
- pre.menu-preformatted {font-family: serif}
- pre.smalldisplay {font-family: serif; font-size: smaller}
- pre.smallexample {font-size: smaller}
- pre.smallformat {font-family: serif; font-size: smaller}
- pre.smalllisp {font-size: smaller}
- span.roman {font-family:serif; font-weight:normal;}
- span.sansserif {font-family:sans-serif; font-weight:normal;}
- ul.toc {list-style: none}
- -->
- </style>
- </head>
- <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
- <a name="Indirection"></a>
- <table cellpadding="1" cellspacing="1" border="0">
- <tr><td valign="middle" align="left">[<a href="Deconstruction-Functions.html#Deconstruction-Functions" title="Previous section in reading order"> < </a>]</td>
- <td valign="middle" align="left">[<a href="The-Universal-Function.html#The-Universal-Function" title="Next section in reading order"> > </a>]</td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left">[<a href="Library-Reference.html#Library-Reference" title="Beginning of this chapter or previous chapter"> << </a>]</td>
- <td valign="middle" align="left">[<a href="Lists.html#Lists" title="Up section"> Up </a>]</td>
- <td valign="middle" align="left">[<a href="Character-Table.html#Character-Table" title="Next chapter"> >> </a>]</td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left">[<a href="avram.html#Top" title="Cover (top) of document">Top</a>]</td>
- <td valign="middle" align="left">[<a href="avram_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
- <td valign="middle" align="left">[<a href="Function-Index.html#Function-Index" title="Index">Index</a>]</td>
- <td valign="middle" align="left">[<a href="avram_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
- </tr></table>
- <hr size="1">
- <a name="Indirection-1"></a>
- <h3 class="subsection">3.1.7 Indirection</h3>
- <p>In some cases it is necessary to build a tree from the top down rather
- <a name="index-pointers-4"></a>
- than from the bottom up, when it is not known in advance what’s on the
- bottom. Although the <code>list</code> type is a pointer itself, these
- situations call for a type of pointers to lists, which are declared as
- the <code>branch</code> type in ‘<tt>branches.h</tt>’. For example, if <code>b</code> is
- declared as a <code>branch</code> and <code>l</code> is declared as a <code>list</code>,
- it would be possible to write <code>b = &l</code>.
- </p>
- <p>Facilities are also provided for maintaining queues of branches, which
- <a name="index-queues-2"></a>
- are declared as the <code>branch_queue</code> type. This type is a pointer to
- a structure with two fields, <code>above</code> and <code>following</code>, where
- <code>above</code> is a <code>branch</code> and <code>following</code> is a
- <code>branch_queue</code>.
- </p>
- <p>These functions are used internally elsewhere in the library and might
- not be necessary for most client programs to use directly.
- </p>
- <dl>
- <dt><a name="index-avm_005finitialize_005fbranches"></a><u>Function:</u> void <b>avm_initialize_branches</b><i> ()</i></dt>
- <dd><p>This must be done once before any of the other branch related functions is
- used, and creates some internal data structures. Results of the other
- functions are undefined if this one isn’t called first.
- </p></dd></dl>
- <dl>
- <dt><a name="index-avm_005fcount_005fbranches"></a><u>Function:</u> void <b>avm_count_branches</b><i> ()</i></dt>
- <dd><p>This function can be used at the end of a run to detect unreclaimed
- storage used for branches or branch queues. If any storage remains
- unreclaimed, a message about unreclaimed branches is written to standard
- error.
- </p></dd></dl>
- <dl>
- <dt><a name="index-avm_005fanticipate"></a><u>Function:</u> void <b>avm_anticipate</b><i> (branch_queue *<var>front</var>, branch_queue *<var>back</var>, branch <var>operand</var>)</i></dt>
- <dd><p>This function provides a simple queueing facility for
- branches. Similarly to the case with <code>avm_enqueue</code>, <code>front</code>
- and <code>back</code> should be initialized to <code>NULL</code> before the first
- call. Each call to this function will enqueue one item to the back,
- assuming enough memory is available, as the following example shows.
- </p>
- <table><tr><td> </td><td><pre class="example">front = NULL;
- back = NULL;
- l = avm_join(NULL,NULL);
- anticipate(&front,&back,&(l->head));
- anticipate(&front,&back,&(l->tail));
- </pre></td></tr></table>
- <p>After the above code is executed, these postconditions will hold.
- </p>
- <table><tr><td> </td><td><pre class="example">front->above == &(l->head)
- front->following->above == &(l->tail)
- front->following == back
- back->following == NULL
- </pre></td></tr></table>
- <p>The name “anticipate” is used because ordinarily the queue contains
- positions in a tree to be filled in later. As usual, only unshared trees should be
- modified in place.
- </p></dd></dl>
- <dl>
- <dt><a name="index-avm_005frecoverable_005fanticipate"></a><u>Function:</u> void <b>avm_recoverable_anticipate</b><i> (branch_queue *<var>front</var>, branch_queue *<var>back</var>, branch <var>operand</var>, int *<var>fault</var>)</i></dt>
- <dd><p>This function is similar to <code>avm_anticipate</code>, except that it will
- not exit with an error message in the event of an overflow error, but
- will simply set <code>*<var>fault</var></code> to a non-zero value and return to the
- caller. If an overflow occurs, nothing about the queue is changed.
- </p></dd></dl>
- <dl>
- <dt><a name="index-avm_005fenqueue_005fbranch"></a><u>Function:</u> void <b>avm_enqueue_branch</b><i> (branch_queue *<var>front</var>, branch_queue *<var>back</var>, int <var>received_bit</var>)</i></dt>
- <dd><p>A slightly higher level interface to the <code>avm_anticipate</code> function
- is provided by this function, which is useful for building a tree from
- <a name="index-trees-5"></a>
- a string of input bits in a format similar to the one described in
- <a href="Concrete-Syntax.html#Concrete-Syntax">Concrete Syntax</a>.
- </p>
- <p>This function should be called the first time with <code>front</code> and
- <code>back</code> having been initialized to represent a queue containing a
- <a name="index-queues-3"></a>
- single branch pointing to a list known to the caller. The list itself
- need not be allocated or initialized. An easy way of doing so would be
- the following.
- </p>
- <table><tr><td> </td><td><pre class="example">front = NULL;
- back = NULL;
- avm_anticipate(&front,&back,&my_list);
- </pre></td></tr></table>
- <p>On each call to <code>avm_enqueue_branch</code>, the <code><var>received_bit</var></code>
- parameter is examined. If it is zero, nothing will be added to the
- queue, the list referenced by the front branch will be assigned
- <code>NULL</code>, and the front branch will be removed from the queue. If
- <code><var>received_bit</var></code> is a non-zero value, the list referenced by
- the front branch will be assigned to point to a newly created unshared
- list node, and two more branches will be appended to the queue. The
- first branch to be appended will point to the head of the newly created
- list node, and the second branch to be appended will point to the tail.
- </p>
- <p>If the sequence of bits conforms to the required concrete syntax, this
- function can be called for each of them in turn, and at the end of the
- sequence, the queue will be empty and the list referenced by the initial
- branch (i.e., <code>my_list</code>) will be the one specified by the bit
- string. If the sequence of bits does not conform to the required
- concrete syntax, the error can be detected insofar as the emptying of
- the queue will not coincide exactly with the last bit.
- </p>
- <p>The caller should check for the queue becoming prematurely empty due to
- syntax errors, because no message is reported by
- <code>avm_enqueue_branch</code> in that event, and subsequent attempts to
- enqueue anything are ignored. However, in the event of a memory overflow,
- an error message is reported and the process is terminated.
- </p></dd></dl>
- <dl>
- <dt><a name="index-avm_005frecoverable_005fenqueue_005fbranch"></a><u>Function:</u> void <b>avm_recoverable_enqueue_branch</b><i> (branch_queue *<var>front</var>, branch_queue *<var>back</var>, int <var>received_bit</var>, int *<var>fault</var>)</i></dt>
- <dd><p>This function is similar to <code>avm_enqueue_branch</code> but will leave
- error handling to the caller in the event of insufficient memory to
- enqueue another branch. Instead of printing an error message and
- exiting, it will dispose of the queue, set the <code><var>fault</var></code> flag
- to a non-zero value, and return. Although the queue will be reclaimed,
- the lists referenced by the branches in it will persist. The list nodes
- themselves can be reclaimed by disposing of the list whose address was
- stored originally in the front branch.
- </p></dd></dl>
- <dl>
- <dt><a name="index-avm_005fdispose_005fbranch_005fqueue"></a><u>Function:</u> void <b>avm_dispose_branch_queue</b><i> (branch_queue <var>front</var>)</i></dt>
- <dd><p>This function deallocates a branch queue by chasing the <code>following</code>
- fields in each one. It does nothing to the lists referenced by the
- branches in the queue.
- </p>
- <p>Rather than using <code>free</code> directly, client programs should use this
- function for deallocating branch queues, because it allows better
- performance by interacting with a local internal cache of free memory,
- and because it performs necessary bookkeeping for
- <code>avm_count_branches</code>.
- </p></dd></dl>
- <dl>
- <dt><a name="index-avm_005fdispose_005fbranch"></a><u>Function:</u> void <b>avm_dispose_branch</b><i> (branch_queue <var>old</var>)</i></dt>
- <dd><p>This disposes of a single branch queue node rather than a whole queue.
- Otherwise, the same comments as those above apply.
- </p></dd></dl>
- <hr size="1">
- <table cellpadding="1" cellspacing="1" border="0">
- <tr><td valign="middle" align="left">[<a href="Deconstruction-Functions.html#Deconstruction-Functions" title="Previous section in reading order"> < </a>]</td>
- <td valign="middle" align="left">[<a href="The-Universal-Function.html#The-Universal-Function" title="Next section in reading order"> > </a>]</td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left">[<a href="Library-Reference.html#Library-Reference" title="Beginning of this chapter or previous chapter"> << </a>]</td>
- <td valign="middle" align="left">[<a href="Lists.html#Lists" title="Up section"> Up </a>]</td>
- <td valign="middle" align="left">[<a href="Character-Table.html#Character-Table" title="Next chapter"> >> </a>]</td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left">[<a href="avram.html#Top" title="Cover (top) of document">Top</a>]</td>
- <td valign="middle" align="left">[<a href="avram_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
- <td valign="middle" align="left">[<a href="Function-Index.html#Function-Index" title="Index">Index</a>]</td>
- <td valign="middle" align="left">[<a href="avram_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
- </tr></table>
- <p>
- <font size="-1">
- This document was generated on <i>December 10, 2012</i> using <a href="http://www.nongnu.org/texi2html/"><i>texi2html 1.82</i></a>.
- </font>
- <br>
- </p>
- </body>
- </html>
|