~ubuntu-branches/ubuntu/hardy/sigscheme/hardy-proposed

« back to all changes in this revision

Viewing changes to src/module-srfi8.c

  • Committer: Bazaar Package Importer
  • Author(s): NIIBE Yutaka
  • Date: 2006-05-23 21:46:41 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060523214641-6ix4gz34wpiehub8
Tags: 0.5.0-2
* debian/control (Build-Depends): Added ruby.
  Thanks to Frederik Schueler.  Closes: #368571
* debian/rules (clean): invoke 'distclean' instead of 'clean'.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*===========================================================================
 
2
 *  FileName : module-srfi8.c
 
3
 *  About    : SRFI-8 receive: Binding to multiple values
 
4
 *
 
5
 *  Copyright (C) 2005-2006 Jun Inoue
 
6
 *
 
7
 *  All rights reserved.
 
8
 *
 
9
 *  Redistribution and use in source and binary forms, with or without
 
10
 *  modification, are permitted provided that the following conditions
 
11
 *  are met:
 
12
 *
 
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.
 
21
 *
 
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
===========================================================================*/
 
34
 
 
35
#include "config.h"
 
36
 
 
37
/*=======================================
 
38
  System Include
 
39
=======================================*/
 
40
 
 
41
/*=======================================
 
42
  Local Include
 
43
=======================================*/
 
44
#include "sigscheme.h"
 
45
#include "sigschemeinternal.h"
 
46
 
 
47
/*=======================================
 
48
  File Local Struct Declarations
 
49
=======================================*/
 
50
 
 
51
/*=======================================
 
52
  File Local Macro Declarations
 
53
=======================================*/
 
54
 
 
55
/*=======================================
 
56
  Variable Declarations
 
57
=======================================*/
 
58
#include "functable-srfi8.c"
 
59
 
 
60
/*=======================================
 
61
  File Local Function Declarations
 
62
=======================================*/
 
63
 
 
64
/*=======================================
 
65
  Function Implementations
 
66
=======================================*/
 
67
void
 
68
scm_initialize_srfi8(void)
 
69
{
 
70
    scm_register_funcs(scm_srfi8_func_info_table);
 
71
}
 
72
 
 
73
ScmObj
 
74
scm_s_srfi8_receive(ScmObj formals, ScmObj expr, ScmObj body,
 
75
                    ScmEvalState *eval_state)
 
76
{
 
77
    scm_int_t formals_len, actuals_len;
 
78
    ScmObj env, actuals;
 
79
    DECLARE_FUNCTION("receive", syntax_variadic_tailrec_2);
 
80
 
 
81
    env = eval_state->env;
 
82
 
 
83
    /*
 
84
     * (receive <formals> <expression> <body>)
 
85
     */
 
86
 
 
87
    formals_len = scm_validate_formals(formals);
 
88
    if (SCM_LISTLEN_ERRORP(formals_len))
 
89
        ERR_OBJ("bad formals", formals);
 
90
 
 
91
    /* FIXME: do we have to extend the environment first?  The SRFI-8
 
92
     * document contradicts itself on this part. */
 
93
    /*
 
94
     * In my recognition, the description in SRFI-8 "The environment in which
 
95
     * the receive-expression is evaluated is extended by binding <variable1>,
 
96
     * ..." does not mean that the environment is extended for the evaluation
 
97
     * of the receive-expression. Probably it only specifies which environment
 
98
     * will be extended after the evaluation. So current implementation is
 
99
     * correct, I think.  -- YamaKen 2006-01-05
 
100
     */
 
101
    actuals = EVAL(expr, env);
 
102
 
 
103
    if (SCM_VALUEPACKETP(actuals)) {
 
104
        actuals = SCM_VALUEPACKET_VALUES(actuals);
 
105
        actuals_len = scm_finite_length(actuals);
 
106
    } else {
 
107
        actuals = LIST_1(actuals);
 
108
        actuals_len = 1;
 
109
    }
 
110
 
 
111
    if (!scm_valid_environment_extension_lengthp(formals_len, actuals_len))
 
112
        ERR_OBJ("unmatched number of args for multiple values", actuals);
 
113
    eval_state->env = env = scm_extend_environment(formals, actuals, env);
 
114
 
 
115
    return scm_s_body(body, eval_state);
 
116
}