syntax.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* Copyright (C) 2017 Free Software Foundation, Inc.
  2. *
  3. * This library is free software; you can redistribute it and/or
  4. * modify it under the terms of the GNU Lesser General Public License
  5. * as published by the Free Software Foundation; either version 3 of
  6. * the License, or (at your option) any later version.
  7. *
  8. * This library is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * Lesser General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Lesser General Public
  14. * License along with this library; if not, write to the Free Software
  15. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  16. * 02110-1301 USA
  17. */
  18. #ifdef HAVE_CONFIG_H
  19. # include <config.h>
  20. #endif
  21. #include "libguile/_scm.h"
  22. #include "libguile/keywords.h"
  23. #include "libguile/ports.h"
  24. #include "libguile/syntax.h"
  25. #include "libguile/validate.h"
  26. static int
  27. scm_is_syntax (SCM x)
  28. {
  29. return SCM_HAS_TYP7 (x, scm_tc7_syntax);
  30. }
  31. #define SCM_VALIDATE_SYNTAX(pos, scm) \
  32. SCM_I_MAKE_VALIDATE_MSG2 (pos, scm, scm_is_syntax, "syntax object")
  33. SCM_DEFINE (scm_syntax_p, "syntax?", 1, 0, 0,
  34. (SCM obj),
  35. "Return @code{#t} if the argument @var{obj} is a syntax object,\n"
  36. "else @code{#f}.")
  37. #define FUNC_NAME s_scm_syntax_p
  38. {
  39. return scm_from_bool (scm_is_syntax (obj));
  40. }
  41. #undef FUNC_NAME
  42. SCM_DEFINE (scm_make_syntax, "make-syntax", 3, 0, 0,
  43. (SCM exp, SCM wrap, SCM module),
  44. "Make a new syntax object.")
  45. #define FUNC_NAME s_scm_make_syntax
  46. {
  47. return scm_double_cell (scm_tc7_syntax, SCM_UNPACK (exp),
  48. SCM_UNPACK (wrap), SCM_UNPACK (module));
  49. }
  50. #undef FUNC_NAME
  51. SCM_DEFINE (scm_syntax_expression, "syntax-expression", 1, 0, 0,
  52. (SCM obj),
  53. "Return the expression contained in the syntax object @var{obj}.")
  54. #define FUNC_NAME s_scm_syntax_expression
  55. {
  56. SCM_VALIDATE_SYNTAX (1, obj);
  57. return SCM_CELL_OBJECT_1 (obj);
  58. }
  59. #undef FUNC_NAME
  60. SCM_DEFINE (scm_syntax_wrap, "syntax-wrap", 1, 0, 0,
  61. (SCM obj),
  62. "Return the wrap contained in the syntax object @var{obj}.")
  63. #define FUNC_NAME s_scm_syntax_wrap
  64. {
  65. SCM_VALIDATE_SYNTAX (1, obj);
  66. return SCM_CELL_OBJECT_2 (obj);
  67. }
  68. #undef FUNC_NAME
  69. SCM_DEFINE (scm_syntax_module, "syntax-module", 1, 0, 0,
  70. (SCM obj),
  71. "Return the module info contained in the syntax object @var{obj}.")
  72. #define FUNC_NAME s_scm_syntax_module
  73. {
  74. SCM_VALIDATE_SYNTAX (1, obj);
  75. return SCM_CELL_OBJECT_3 (obj);
  76. }
  77. #undef FUNC_NAME
  78. static SCM print_syntax_var;
  79. static void
  80. init_print_syntax_var (void)
  81. {
  82. print_syntax_var =
  83. scm_c_private_variable ("system syntax", "print-syntax");
  84. }
  85. void
  86. scm_i_syntax_print (SCM obj, SCM port, scm_print_state *pstate)
  87. {
  88. static scm_i_pthread_once_t once = SCM_I_PTHREAD_ONCE_INIT;
  89. scm_i_pthread_once (&once, init_print_syntax_var);
  90. scm_call_2 (scm_variable_ref (print_syntax_var), obj, port);
  91. }
  92. void
  93. scm_init_syntax ()
  94. {
  95. #include "libguile/syntax.x"
  96. }
  97. /*
  98. Local Variables:
  99. c-file-style: "gnu"
  100. End:
  101. */