Calling-existing-library-functions.html 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <html lang="en">
  2. <head>
  3. <title>Calling existing library functions - 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="External-Library-Maintenance.html#External-Library-Maintenance" title="External Library Maintenance">
  9. <link rel="prev" href="External-Library-Maintenance.html#External-Library-Maintenance" title="External Library Maintenance">
  10. <link rel="next" href="Implementing-new-library-functions.html#Implementing-new-library-functions" title="Implementing new library functions">
  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="Calling-existing-library-functions"></a>
  28. <p>
  29. Next:&nbsp;<a rel="next" accesskey="n" href="Implementing-new-library-functions.html#Implementing-new-library-functions">Implementing new library functions</a>,
  30. Previous:&nbsp;<a rel="previous" accesskey="p" href="External-Library-Maintenance.html#External-Library-Maintenance">External Library Maintenance</a>,
  31. Up:&nbsp;<a rel="up" accesskey="u" href="External-Library-Maintenance.html#External-Library-Maintenance">External Library Maintenance</a>
  32. <hr>
  33. </div>
  34. <h4 class="subsection">3.9.1 Calling existing library functions</h4>
  35. <p>Whatever data types a library function manipulates, its argument and
  36. its result are each ultimately encoded each by a single list as
  37. explained in <a href="Type-Conversions.html#Type-Conversions">Type Conversions</a>. This representation allows all
  38. library functions to be invoked by a uniform calling convention as
  39. detailed below.
  40. <div class="defun">
  41. &mdash; Function: list <b>avm_library_call</b> (<var>list library_name, list function_name, list argument, int *fault</var>)<var><a name="index-avm_005flibrary_005fcall-654"></a></var><br>
  42. <blockquote><p>This function serves as an interpreter of external library functions
  43. by taking a <var>library_name</var>, a <var>function_name</var>, and an
  44. <var>argument</var> to the result returned by the corresponding library
  45. function for the given <var>argument</var>.
  46. <p>The library and function names should be encoded as lists of character
  47. representations, the same as the arguments that would be used with the
  48. <code>library</code> combinator if it were being invoked by virtual code
  49. <a name="index-backward-compatability-655"></a>(with attention to the backward compatibility issue explained in
  50. <a href="Characters-and-Strings.html#Characters-and-Strings">Characters and Strings</a>).
  51. <p>If an error occurs in the course of evaluating a library function, the
  52. integer referenced by <var>fault</var> will be assigned a non-zero value,
  53. and the result will be a list of character string representations
  54. explaining the error, such as <code>&lt;'memory overflow'&gt;</code>, for example.
  55. Otherwise, the list returned will encode the result of the library
  56. function in a way that depends on the particular function being evaluated.
  57. </p></blockquote></div>
  58. <div class="defun">
  59. &mdash; Function: list <b>avm_have_library_call</b> (<var>list library_name, list function_name, int *fault</var>)<var><a name="index-avm_005fhave_005flibrary_005fcall-656"></a></var><br>
  60. <blockquote><p>This function implements the <code>have</code> combinator described in
  61. <a href="Have-combinator.html#Have-combinator">Have combinator</a>, which tests for the availability of a library
  62. function. The <var>library_name</var> and <var>function_name</var> parameters
  63. are as explained above for <code>avm_library_call</code>, and <code>fault</code>
  64. could signal an error similarly for this function as well.
  65. <p>The result returned will be an error message in the event of an error,
  66. or a list of pairs of strings otherwise. The list will be empty if the
  67. library function is not available. If the library function is
  68. available, the list will contain a single pair, as in
  69. <pre class="example"> &lt;(library_name,function_name)&gt;
  70. </pre>
  71. <p>In addition, the list representation of the character string
  72. <code>'*'</code> can be specified as either the library name or the function
  73. name or both. This string is interpreted as a wild card and will cause
  74. all matching pairs of library and function names to be returned in the
  75. list.
  76. </p></blockquote></div>
  77. <div class="defun">
  78. &mdash; Function: void <b>avm_initialize_libfuns</b> ()<var><a name="index-avm_005finitialize_005flibfuns-657"></a></var><br>
  79. <blockquote><p>This function initializes some static data structures used by the two
  80. functions above. It may be called optionally before the first call to
  81. either of them, but will be called automatically if not.
  82. </p></blockquote></div>
  83. <div class="defun">
  84. &mdash; Function: void <b>avm_count_libfuns</b> ()<var><a name="index-avm_005fcount_005flibfuns-658"></a></var><br>
  85. <blockquote><p>This function can be used as an aid to detecting memory leaks. It
  86. reclaims any data structures allocated by
  87. <code>avm_initialize_libfuns</code> and should be called towards the end of
  88. a run some time prior to <code>avm_count_lists</code> <a href="Simple-Operations.html#Simple-Operations">Simple Operations</a>, if the latter is being used.
  89. </p></blockquote></div>
  90. </body></html>