選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

94 行
2.6KB

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>Xen</title>
  5. <style type="text/css">
  6. EM.red {color:red; font-style:normal}
  7. EM.tab {font-style: normal; font-size: small; font-family: fixed}
  8. EM.def {font-weight: bold; font-style: normal}
  9. H1 {text-align: center}
  10. UL {list-style-type: none}
  11. A {text-decoration:none}
  12. A:hover {text-decoration:underline}
  13. A.quiet {color:black; text-decoration:none}
  14. A.quiet:hover {text-decoration:underline}
  15. BODY.body {background-color: #ffffff; /* white */
  16. margin-left: 0.5cm;
  17. }
  18. DIV.centered1 {padding-left: 35%;
  19. padding-bottom: 0.5cm;
  20. }
  21. DIV.topheader {margin-top: 10px;
  22. margin-bottom: 40px;
  23. border: 4px solid #00ff00; /* green */
  24. background-color: #f5f5dc; /* beige */
  25. font-family: 'Helvetica';
  26. font-size: 30px;
  27. text-align: center;
  28. padding-top: 10px;
  29. padding-bottom: 10px;
  30. }
  31. </style>
  32. </head>
  33. <body class="body">
  34. <div class="topheader">Xen</div>
  35. <p>The Xen package provides macros and procedures making it possible for the
  36. same C code to support several different embedded (or extension) languages.
  37. Currently supported are s7, Ruby, and Forth.
  38. </p>
  39. <p>Here's a program that defines a function (named "fnc" in the
  40. extension language) that takes an integer argument and increments it,
  41. a variable (named "var" in the extension language) that is initialized
  42. to 32, a constant (named "twelve") that has the value 12, then places
  43. you in a read-eval-print loop:
  44. </p>
  45. <pre>
  46. #include &lt;stdio.h&gt;
  47. #include "xen.h"
  48. static XEN orig_function(XEN argument)
  49. {
  50. XEN_ASSERT_TYPE(XEN_INTEGER_P(argument), argument, XEN_ONLY_ARG, "fnc", "an integer");
  51. fprintf(stdout, "argument is %d\n", XEN_TO_C_INT(argument));
  52. return(C_TO_XEN_INT(XEN_TO_C_INT(argument) + 1));
  53. }
  54. XEN_NARGIFY_1(function, orig_function);
  55. static XEN variable;
  56. int main(int argc, char **argv)
  57. {
  58. xen_initialize();
  59. XEN_DEFINE_VARIABLE("var", variable, C_TO_XEN_INT(32));
  60. XEN_DEFINE_CONSTANT("twelve", 12, "this is 12");
  61. XEN_DEFINE_PROCEDURE("fnc", function, 1, 0, 0, "this is our function");
  62. fprintf(stdout, "we're running: %s\n", xen_version());
  63. xen_repl(argc, argv);
  64. return(0);
  65. }
  66. </pre>
  67. <p>The "XEN_ARGIFY" step
  68. is needed for those languages that assume one calling sequence for
  69. a C-defined function; we have to wrap up the actual call in whatever
  70. sequence the extension language wants.
  71. </p>
  72. <p>Currently constants are assumed to be integers. Type checks are
  73. handled by macros such as XEN_INTEGER_P; type conversions by macros
  74. such as XEN_TO_C_INT or C_TO_XEN_INT.
  75. </p>
  76. </body>
  77. </html>