Primitive-types.html 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <html lang="en">
  2. <head>
  3. <title>Primitive types - 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="Type-Conversions.html#Type-Conversions" title="Type Conversions">
  9. <link rel="prev" href="Type-Conversions.html#Type-Conversions" title="Type Conversions">
  10. <link rel="next" href="One-dimensional-arrays.html#One-dimensional-arrays" title="One dimensional arrays">
  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="Primitive-types"></a>
  28. <p>
  29. Next:&nbsp;<a rel="next" accesskey="n" href="One-dimensional-arrays.html#One-dimensional-arrays">One dimensional arrays</a>,
  30. Previous:&nbsp;<a rel="previous" accesskey="p" href="Type-Conversions.html#Type-Conversions">Type Conversions</a>,
  31. Up:&nbsp;<a rel="up" accesskey="u" href="Type-Conversions.html#Type-Conversions">Type Conversions</a>
  32. <hr>
  33. </div>
  34. <h5 class="subsubsection">3.1.4.1 Primitive types</h5>
  35. <p>A pair of functions in support of this abstraction is prototyped in
  36. <samp><span class="file">listfuns.h</span></samp>. These functions will be of interest mainly to
  37. developers wishing to implement an interface to a new library module
  38. and make it accessible on the virtual side by way of the
  39. <code>library</code> combinator (<a href="Library-combinator.html#Library-combinator">Library combinator</a>).
  40. <div class="defun">
  41. &mdash; Function: void <b>*avm_value_of_list</b> (<var>list operand, list *message, int *fault</var>)<var><a name="index-g_t_002aavm_005fvalue_005fof_005flist-440"></a></var><br>
  42. <blockquote><p>This function takes an <var>operand</var> representing a value used by a
  43. library function in the format described above (<a href="Type-Conversions.html#Type-Conversions">Type Conversions</a>) and returns a pointer to the value.
  44. <p>The <code>value</code> field in the <var>operand</var> normally will point to the
  45. block of memory holding the value, and the <var>operand</var> itself will
  46. be a list of character representations whose binary encodings spell
  47. out the value as explained above.
  48. <p>The <code>value</code> field need not be initialized on entry but it will be
  49. initialized as a side effect of being computed by this function. If it
  50. has been initialized due to a previous call with the same
  51. <var>operand</var>, this function is a fast constant time operation.
  52. <p>The caller should not free the pointer returned by this function
  53. because a reference to its value will remain in the
  54. <var>operand</var>. When the <var>operand</var> itself is freed by
  55. <code>avm_dispose</code> (<a href="Simple-Operations.html#Simple-Operations">Simple Operations</a>), the value will go with it.
  56. <p>If an error occurs during the evaluation of this function, the integer
  57. referenced by <var>fault</var> will be set to a non-zero value, and the
  58. list referenced by <var>message</var> will be assigned a representation of
  59. a list of strings describing the error. The <var>message</var> is freshly
  60. created and should be freed by the caller with <code>avm_dispose</code>
  61. when no longer needed.
  62. <p>Possible error messages are <code>&lt;'missing value'&gt;</code>, in the case of
  63. <a name="index-missing-value-441"></a>an empty <var>operand</var>, <code>&lt;'invalid value'&gt;</code> in the case of an
  64. <a name="index-invalid-value-442"></a><var>operand</var> that is not a list of character representations, and
  65. <code>&lt;'memory overflow'&gt;</code> if there was insufficient space to allocate
  66. the result.
  67. </p></blockquote></div>
  68. <div class="defun">
  69. &mdash; Function: list <b>avm_list_of_value</b> (<var>void *contents, size_t size, int *fault</var>)<var><a name="index-avm_005flist_005fof_005fvalue-443"></a></var><br>
  70. <blockquote><p>This function performs the inverse operation of
  71. <code>avm_value_of_list</code>, taking the address of an area of
  72. contiguously stored data and its <var>size</var> in bytes to a list
  73. representation. The length of the list returned is equal to the number
  74. of bytes of data, <var>size</var>, and each item of the list is a character
  75. representation for the corresponding byte as given by <a href="Character-Table.html#Character-Table">Character Table</a>.
  76. <p>A copy of the memory area is made so that the original is no longer
  77. needed and may be freed by the caller. A pointer to this copy is
  78. returned by subsequent calls to <code>avm_value_of_list</code> when the
  79. result returned by this function is used as the <var>operand</var>
  80. parameter.
  81. <p>If there is insufficient memory to allocate the result, the integer
  82. referenced by <var>fault</var> is set to a non-zero value, and a copy of
  83. the message <code>&lt;'memory overflow'&gt;</code> represented as a list is
  84. returned. This function could also cause a segmentation fault if it is
  85. <a name="index-segmentation-fault-444"></a>passed an invalid pointer or a <var>size</var> that overruns the storage
  86. area. However, it is acceptable to specify a <var>size</var> that is less
  87. than the actual size of the given memory area to construct a list
  88. representing only the first part of it. The <var>size</var> must always be
  89. greater than zero.
  90. </p></blockquote></div>
  91. </body></html>