syntax.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* Copyright 2017-2018
  2. Free Software Foundation, Inc.
  3. This file is part of Guile.
  4. Guile is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Lesser General Public License as published
  6. by the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. Guile is distributed in the hope that it will be useful, but WITHOUT
  9. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  11. License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with Guile. If not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #ifdef HAVE_CONFIG_H
  16. # include <config.h>
  17. #endif
  18. #include "eval.h"
  19. #include "gsubr.h"
  20. #include "keywords.h"
  21. #include "modules.h"
  22. #include "ports.h"
  23. #include "threads.h"
  24. #include "variable.h"
  25. #include "syntax.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 "syntax.x"
  96. }