values.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* Copyright (C) 2000, 2001, 2006, 2008 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
  5. * License as published by the Free Software Foundation; either
  6. * version 2.1 of the License, or (at your option) any later version.
  7. *
  8. * This library is distributed in the hope that it will be useful,
  9. * but 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 02110-1301 USA
  16. */
  17. #ifdef HAVE_CONFIG_H
  18. # include <config.h>
  19. #endif
  20. #include "libguile/_scm.h"
  21. #include "libguile/eval.h"
  22. #include "libguile/feature.h"
  23. #include "libguile/gc.h"
  24. #include "libguile/numbers.h"
  25. #include "libguile/ports.h"
  26. #include "libguile/root.h"
  27. #include "libguile/strings.h"
  28. #include "libguile/struct.h"
  29. #include "libguile/validate.h"
  30. #include "libguile/values.h"
  31. SCM scm_values_vtable;
  32. static SCM
  33. print_values (SCM obj, SCM pwps)
  34. {
  35. SCM values = scm_struct_ref (obj, SCM_INUM0);
  36. SCM port = SCM_PORT_WITH_PS_PORT (pwps);
  37. scm_print_state *ps = SCM_PRINT_STATE (SCM_PORT_WITH_PS_PS (pwps));
  38. scm_puts ("#<values ", port);
  39. scm_iprin1 (values, port, ps);
  40. scm_puts (">", port);
  41. return SCM_UNSPECIFIED;
  42. }
  43. SCM_DEFINE (scm_values, "values", 0, 0, 1,
  44. (SCM args),
  45. "Delivers all of its arguments to its continuation. Except for\n"
  46. "continuations created by the @code{call-with-values} procedure,\n"
  47. "all continuations take exactly one value. The effect of\n"
  48. "passing no value or more than one value to continuations that\n"
  49. "were not created by @code{call-with-values} is unspecified.")
  50. #define FUNC_NAME s_scm_values
  51. {
  52. long n;
  53. SCM result;
  54. SCM_VALIDATE_LIST_COPYLEN (1, args, n);
  55. if (n == 1)
  56. result = SCM_CAR (args);
  57. else
  58. {
  59. result = scm_make_struct (scm_values_vtable, SCM_INUM0,
  60. scm_list_1 (args));
  61. }
  62. return result;
  63. }
  64. #undef FUNC_NAME
  65. void
  66. scm_init_values (void)
  67. {
  68. SCM print = scm_c_define_subr ("%print-values", scm_tc7_subr_2,
  69. print_values);
  70. scm_values_vtable
  71. = scm_permanent_object (
  72. scm_make_vtable_vtable (scm_from_locale_string ("pr"),
  73. SCM_INUM0, SCM_EOL));
  74. SCM_SET_STRUCT_PRINTER (scm_values_vtable, print);
  75. scm_add_feature ("values");
  76. #include "libguile/values.x"
  77. }
  78. /*
  79. Local Variables:
  80. c-file-style: "gnu"
  81. End:
  82. */