1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <html lang="en">
- <head>
- <title>Representation of Numeric and Textual Data - avram - a virtual machine code interpreter</title>
- <meta http-equiv="Content-Type" content="text/html">
- <meta name="description" content="avram - a virtual machine code interpreter">
- <meta name="generator" content="makeinfo 4.13">
- <link title="Top" rel="start" href="index.html#Top">
- <link rel="up" href="Virtual-Machine-Specification.html#Virtual-Machine-Specification" title="Virtual Machine Specification">
- <link rel="prev" href="File-Format.html#File-Format" title="File Format">
- <link rel="next" href="Filter-Mode-Interface.html#Filter-Mode-Interface" title="Filter Mode Interface">
- <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
- <meta http-equiv="Content-Style-Type" content="text/css">
- <style type="text/css"><!--
- pre.display { font-family:inherit }
- pre.format { font-family:inherit }
- pre.smalldisplay { font-family:inherit; font-size:smaller }
- pre.smallformat { font-family:inherit; font-size:smaller }
- pre.smallexample { font-size:smaller }
- pre.smalllisp { font-size:smaller }
- span.sc { font-variant:small-caps }
- span.roman { font-family:serif; font-weight:normal; }
- span.sansserif { font-family:sans-serif; font-weight:normal; }
- --></style>
- </head>
- <body>
- <div class="node">
- <a name="Representation-of-Numeric-and-Textual-Data"></a>
- <p>
- Next: <a rel="next" accesskey="n" href="Filter-Mode-Interface.html#Filter-Mode-Interface">Filter Mode Interface</a>,
- Previous: <a rel="previous" accesskey="p" href="File-Format.html#File-Format">File Format</a>,
- Up: <a rel="up" accesskey="u" href="Virtual-Machine-Specification.html#Virtual-Machine-Specification">Virtual Machine Specification</a>
- <hr>
- </div>
- <h3 class="section">2.4 Representation of Numeric and Textual Data</h3>
- <p>As noted already, virtual code applications are specified by functions
- operating on elements of a set having the properties described in
- <a href="Raw-Material.html#Raw-Material">Raw Material</a>, which are convenient to envision as ordered binary trees or
- <a name="index-trees-158"></a><a name="index-g_t_0040code_007bnil_007d-159"></a>pairs of <code>nil</code>. However, virtual code applications normally deal
- with numeric or textual data, for example when they refer to the
- contents of a text file. It is therefore necessary for the application
- and the virtual machine emulator to agree on a way of describing textual
- or numeric data with these trees.
- <p>The purpose of this section is to explain the basic data structures used
- in the exchange of information between <code>avram</code> and a virtual code
- application. For example, an explanation is needed for statements like
- “an application invoked with the <samp><span class="option">--baz</span></samp> option is expected to
- return a pair <code>(</code><var>foo</var><code>,</code><var>bar</var><code>)</code>, where <var>foo</var> is a
- <a name="index-strings-160"></a><a name="index-character-strings-161"></a><a name="index-lists-162"></a>list of character strings <small class="dots">...</small>”, that are made subsequently in this
- document. Such statements should be understood as referring to the trees
- representing the pairs, lists, character strings, etc., according to the
- conventions explained below.
- <dl>
- <dt><em>Characters</em><dd><a name="index-character-codes-163"></a>An arbitrarily chosen set of 256 trees is used to represent the
- character set. They are listed in <a href="Character-Table.html#Character-Table">Character Table</a>. For example,
- the letter <code>A</code> is represented by
- <code>(nil,(((nil,(nil,(nil,nil))),nil),(nil,nil)))</code>. That means that
- when an application wants the letter <code>A</code> written to a text file, it
- returns something with this tree in it.
- <br><dt><em>Booleans</em><dd><a name="index-booleans-164"></a>The value of <code>false</code> is represented by <code>nil</code>, and the value of
- <code>true</code> is represented by <code>(nil,nil)</code>.
- <br><dt><em>Pairs</em><dd><a name="index-pairs-165"></a>Given any two items of data <var>x1</var> and <var>x2</var>, having the respective
- representations <var>r1</var> and <var>r2</var>, the pair <code>(</code><var>x1</var><code>,</code><var>x2</var><code>)</code> has the
- representation <code>cons(</code><var>r1</var><code>,</code><var>r2</var><code>)</code>.
- <br><dt><em>Lists</em><dd><a name="index-lists-166"></a>A list of the items <var>x1</var>, <var>x2</var> <small class="dots">...</small> <var>xn</var> with respective
- representations <var>r1</var> through <var>rn</var> is represented by the tree
- <code>cons(</code><var>r1</var><code>,cons(</code><var>r2</var><code>...cons(</code><var>rn</var><code>,nil)...))</code>. In other words,
- lists are represented as pairs whose left sides are the heads and whose
- right sides are the tails. The empty list is identified with
- <code>nil</code>. Lists of arbitrary finite length can be accommodated.
- <br><dt><em>Naturals</em><dd><a name="index-naturals-167"></a>A number of the form <var>b0</var><code> + 2</code><var>b1</var><code> + 4</code><var>b2</var><code> + ... +
- 2^n </code><var>bn</var>, where each <var>b</var><code>i</code> is <code>0</code> or <code>1</code>, is
- represented by a tree of the form
- <code>cons(</code><var>t0</var><code>,cons(</code><var>t1</var><code>...cons(</code><var>tn</var><code>,nil)...))</code>
- where each <var>t</var><code>i</code> is <code>nil</code> if the corresponding
- <var>b</var><code>i</code> is <code>0</code>, and <code>(nil,nil)</code> otherwise. Note that
- the numbers <var>b</var><code>i</code> are exactly the bits written in the binary
- expansion of the number, with <var>b0</var> being the least significant
- bit.
- <br><dt><em>Strings</em><dd><a name="index-strings-168"></a><a name="index-character-strings-169"></a>are represented as lists of characters.
- </dl>
- <p><a name="index-types-170"></a><code>avram</code> imposes no more of a “type discipline” than necessary to
- a workable interface between it and an application. This selection of
- types and constructors should not be seen as constraining what a
- compiler writer may wish to have in a source language.
- </body></html>
|