1
/*===========================================================================
2
* Filename : module-srfi43.c
3
* About : SRFI-43 Vector library
5
* Copyright (c) 2007-2008 SigScheme Project <uim-en AT googlegroups.com>
9
* Redistribution and use in source and binary forms, with or without
10
* modification, are permitted provided that the following conditions
13
* 1. Redistributions of source code must retain the above copyright
14
* notice, this list of conditions and the following disclaimer.
15
* 2. Redistributions in binary form must reproduce the above copyright
16
* notice, this list of conditions and the following disclaimer in the
17
* documentation and/or other materials provided with the distribution.
18
* 3. Neither the name of authors nor the names of its contributors
19
* may be used to endorse or promote products derived from this software
20
* without specific prior written permission.
22
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
23
* IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
26
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
29
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
31
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
===========================================================================*/
37
#include "sigscheme.h"
38
#include "sigschemeinternal.h"
40
/*=======================================
41
File Local Macro Definitions
42
=======================================*/
43
#define QUOTE(obj) (LIST_2(SYM_QUOTE, (obj)))
45
/*=======================================
46
File Local Type Definitions
47
=======================================*/
49
/*=======================================
50
File Local Function Declarations
51
=======================================*/
52
SCM_EXPORT ScmObj scm_s_let_vector_start_plus_end(ScmObj callee, ScmObj vec,
54
ScmObj start_plus_end,
56
ScmEvalState *eval_state);
58
/*=======================================
60
=======================================*/
61
#include "functable-srfi43.c"
63
SCM_GLOBAL_VARS_BEGIN(static_srfi43);
65
static ScmObj l_sym_vector_parse_start_plus_end;
66
static ScmObj l_sym_check_type, l_sym_vectorp;
68
SCM_GLOBAL_VARS_END(static_srfi43);
69
#define l_sym_vector_parse_start_plus_end \
70
SCM_GLOBAL_VAR(static_srfi43, l_sym_vector_parse_start_plus_end)
71
#define l_sym_check_type SCM_GLOBAL_VAR(static_srfi43, l_sym_check_type)
72
#define l_sym_vectorp SCM_GLOBAL_VAR(static_srfi43, l_sym_vectorp)
73
SCM_DEFINE_STATIC_VARS(static_srfi43);
75
/*=======================================
77
=======================================*/
79
scm_initialize_srfi43(void)
81
SCM_GLOBAL_VARS_INIT(static_srfi43);
83
scm_register_funcs(scm_functable_srfi43);
85
scm_require_module("srfi-8");
86
scm_require_module("srfi-23");
87
scm_require_module("sscm-ext"); /* for let-optionals* */
88
scm_load_system_file("srfi-43.scm");
90
l_sym_vector_parse_start_plus_end = scm_intern("vector-parse-start+end");
91
l_sym_check_type = scm_intern("check-type");
92
l_sym_vectorp = scm_intern("vector?");
94
scm_define_alias("let*-optionals", "let-optionals*");
97
/* let-vector-start+end is not a part of SRFI-43. */
99
scm_s_let_vector_start_plus_end(ScmObj callee, ScmObj vec,
100
ScmObj args, ScmObj start_plus_end,
102
ScmEvalState *eval_state)
104
ScmObj env, start_name, end_name, proc_check_type, check_type_args;
106
DECLARE_FUNCTION("let-vector-start+end", syntax_variadic_tailrec_4);
108
if (!LIST_2_P(start_plus_end))
109
ERR_OBJ("invalid start+end form", start_plus_end);
110
/* The responsibility of type checks for other args are delegated to
111
* 'check-type' and 'receive'. */
113
env = eval_state->env;
115
proc_check_type = EVAL(l_sym_check_type, env);
116
check_type_args = LIST_3(EVAL(l_sym_vectorp, env),
119
vec = scm_call(proc_check_type, check_type_args);
121
start_name = QUOTE(CAR(start_plus_end));
122
end_name = QUOTE(CADR(start_plus_end));
123
receive_expr = CONS(l_sym_vector_parse_start_plus_end,
124
LIST_5(QUOTE(vec), args, start_name, end_name, callee));
125
return scm_s_srfi8_receive(start_plus_end, receive_expr, body, eval_state);