/* [<][>][^][v][top][bottom][index][help] */
DEFINITIONS
This source file includes following definitions.
- ScmSyntaxPattern
- ScmSyntaxRuleBranch
- ScmSyntaxRules
1 /*
2 * macro.h - structures used internally in macro expander
3 *
4 * Copyright (c) 2000-2005 Shiro Kawai, All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * 3. Neither the name of the authors nor the names of its contributors
18 * may be used to endorse or promote products derived from this
19 * software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
27 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *
33 * $Id: macro.h,v 1.10 2005/05/28 10:40:12 shirok Exp $
34 */
35
36 #ifndef GAUCHE_MACRO_H
37 #define GAUCHE_MACRO_H
38
39 /*
40 * SyntaxPattern object is an internal object used to expand r5rs macro.
41 */
42
43 typedef struct ScmSyntaxPatternRec {
44 SCM_HEADER;
45 ScmObj pattern; /* subpattern */
46 ScmObj vars; /* pattern variables in this subpattern */
47 short level; /* level of this subpattern */
48 short repeat; /* does this subpattern repeat? */
49 } ScmSyntaxPattern;
50
51 SCM_CLASS_DECL(Scm_SyntaxPatternClass);
52 #define SCM_CLASS_SYNTAX_PATTERN (&Scm_SyntaxPatternClass)
53
54 #define SCM_SYNTAX_PATTERN(obj) ((ScmSyntaxPattern*)(obj))
55 #define SCM_SYNTAX_PATTERN_P(obj) SCM_XTYPEP(obj, SCM_CLASS_SYNTAX_PATTERN)
56
57 /*
58 * SyntaxRules keeps a compiled rules of macro transformation.
59 */
60
61 typedef struct ScmSyntaxRuleBranchRec {
62 ScmObj pattern; /* pattern to match */
63 ScmObj templat; /* template to be expanded */
64 int numPvars; /* # of pattern variables */
65 int maxLevel; /* maximum # of nested subpatterns */
66 } ScmSyntaxRuleBranch;
67
68 typedef struct ScmSyntaxRules {
69 SCM_HEADER;
70 ScmObj name; /* name of the macro (for debug) */
71 int numRules; /* # of rules */
72 int maxNumPvars; /* max # of pattern variables */
73 ScmSyntaxRuleBranch rules[1]; /* variable length */
74 } ScmSyntaxRules;
75
76 SCM_CLASS_DECL(Scm_SyntaxRulesClass);
77 #define SCM_CLASS_SYNTAX_RULES (&Scm_SyntaxRulesClass)
78
79 #define SCM_SYNTAX_RULES(obj) ((ScmSyntaxRules*)(obj))
80 #define SCM_SYNTAX_RULES_P(obj) SCM_XTYPEP(obj, SCM_CLASS_SYNTAX_RULES)
81
82 SCM_EXTERN ScmObj Scm_CompileSyntaxRules(ScmObj name, ScmObj lietrals,
83 ScmObj rules, ScmObj mod, ScmObj env);
84
85 /*
86 * Pattern variable reference object
87 */
88 #define SCM_PVREF_TAG 0x0e
89 #define SCM_PVREF_P(obj) ((SCM_WORD(obj)&0x0f) == SCM_PVREF_TAG)
90 #define SCM_PVREF_LEVEL(obj) ((SCM_WORD(obj)>>24) & 0xff)
91 #define SCM_PVREF_COUNT(obj) ((SCM_WORD(obj)>>16) & 0xff)
92
93 #define SCM_MAKE_PVREF(level, count) \
94 SCM_OBJ((SCM_WORD(level)<<24) | (SCM_WORD(count)<<16) | SCM_PVREF_TAG)
95
96 /* Temporary */
97 SCM_EXTERN ScmObj Scm_MakeMacroTransformerOld(ScmSymbol *name,
98 ScmProcedure *proc);
99
100 #endif /* GAUCHE_MACRO_H */