Library-combinator.html 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <html lang="en">
  2. <head>
  3. <title>Library combinator - avram - a virtual machine code interpreter</title>
  4. <meta http-equiv="Content-Type" content="text/html">
  5. <meta name="description" content="avram - a virtual machine code interpreter">
  6. <meta name="generator" content="makeinfo 4.13">
  7. <link title="Top" rel="start" href="index.html#Top">
  8. <link rel="up" href="Interfaces-to-External-Code.html#Interfaces-to-External-Code" title="Interfaces to External Code">
  9. <link rel="prev" href="Interfaces-to-External-Code.html#Interfaces-to-External-Code" title="Interfaces to External Code">
  10. <link rel="next" href="Have-combinator.html#Have-combinator" title="Have combinator">
  11. <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
  12. <meta http-equiv="Content-Style-Type" content="text/css">
  13. <style type="text/css"><!--
  14. pre.display { font-family:inherit }
  15. pre.format { font-family:inherit }
  16. pre.smalldisplay { font-family:inherit; font-size:smaller }
  17. pre.smallformat { font-family:inherit; font-size:smaller }
  18. pre.smallexample { font-size:smaller }
  19. pre.smalllisp { font-size:smaller }
  20. span.sc { font-variant:small-caps }
  21. span.roman { font-family:serif; font-weight:normal; }
  22. span.sansserif { font-family:sans-serif; font-weight:normal; }
  23. --></style>
  24. </head>
  25. <body>
  26. <div class="node">
  27. <a name="Library-combinator"></a>
  28. <p>
  29. Next:&nbsp;<a rel="next" accesskey="n" href="Have-combinator.html#Have-combinator">Have combinator</a>,
  30. Previous:&nbsp;<a rel="previous" accesskey="p" href="Interfaces-to-External-Code.html#Interfaces-to-External-Code">Interfaces to External Code</a>,
  31. Up:&nbsp;<a rel="up" accesskey="u" href="Interfaces-to-External-Code.html#Interfaces-to-External-Code">Interfaces to External Code</a>
  32. <hr>
  33. </div>
  34. <h5 class="subsubsection">2.7.16.1 Library combinator</h5>
  35. <p>The simplest and fastest method of interfacing to an external library
  36. is by way of a virtual machine combinator called <code>library</code>. It
  37. takes two non-empty character strings as arguments to a virtual code
  38. program of the form implied by the following property.
  39. <dl>
  40. <dt><em>T33</em><dd>[[<code>library</code>]] (<var>x</var>,<var>y</var>) = <code>((nil,nil),((</code><var>x</var><code>,</code><var>y</var><code>),(nil,nil)))</code>
  41. </dl>
  42. <p class="noindent">Intuitively, <var>x</var> is the name of a library and <var>y</var> is the name
  43. of a function within the library. For example, if <var>x</var> is
  44. <code>'math'</code> and <var>y</var> is <code>'sqrt'</code>, then
  45. <code>library</code>(<var>x</var>,<var>y</var>) represents the function that computes
  46. the square root of a floating point number as defined by the host
  47. machine's native C implementation, normally in IEEE double precision
  48. format. Different functions and libraries may involve other argument
  49. and result types, such as complex numbers, arrays, sparse matrices, or
  50. arbitrary precision numbers. A list of currently supported external
  51. library names with their functions and calling conventions is given in
  52. <a href="External-Libraries.html#External-Libraries">External Libraries</a>.
  53. <p>On the virtual code side, all function arguments and results
  54. regardless of their types are encoded as nested pairs of <code>nil</code>,
  55. as always, and may be manipulated or stored as any other data,
  56. including storage and retrieval from files in <samp><span class="file">.avm</span></samp> virtual
  57. code format (<a href="File-Format.html#File-Format">File Format</a>). However, on the C side,
  58. various memory management and caching techniques are employed to
  59. maintain this facade while allowing the libraries to operate on data
  60. in their native format. The details are given more fully in the API
  61. documentation, particularly in <a href="Type-Conversions.html#Type-Conversions">Type Conversions</a> and
  62. <a href="External-Library-Maintenance.html#External-Library-Maintenance">External Library Maintenance</a>.
  63. <p>While this style is fast and convenient, it is limited either to
  64. libraries that have already been built into the virtual machine, or to
  65. those for which the user is prepared to implement a new interface
  66. module in C as described in <a href="Implementing-new-library-functions.html#Implementing-new-library-functions">Implementing new library functions</a>.
  67. </body></html>