summaryrefslogtreecommitdiff
path: root/agen5/test/snarf.test
blob: c03e40845479dc5f3ad9e7e70685200b90442429 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#! /bin/sh
#  -*- Mode: Shell-script -*-
# snarf.test --- test the extraction of scm-type definitions
#
# Time-stamp:        "2012-03-04 19:48:23 bkorb"
# Author:            Bruce Korb <bkorb@gnu.org>
##
## This file is part of AutoGen.
## AutoGen Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
##
## AutoGen is free software: you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by the
## Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## AutoGen is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
## See the GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License along
## with this program.  If not, see <http://www.gnu.org/licenses/>.
##
# ----------------------------------------------------------------------

. ./defs

# # # # # # # # # # SOURCE FILE # # # # # # # # #

echo creating ${testname}.c
cat > ${testname}.c <<_EOF_
#include "${testname}.h"
#include "${testname}.ini"
/*=gfunc test_to_example_x
 *
 * exparg: in, test input arg desc, optional, list
 *
=*/
SCM
test_scm_test_to_example_x(SCM in)
{
    return in;
}

/*=symbol mumble_check
 *
 * init_val:  SCM_BOOL_T
=*/
/*=symbol bumble_it
 *
 *  const_val:  100L
 *  global:
=*/
/*=syntax guile_syntax_ele
 *
 *  type:  scm_makacro
 *  cfn:   scm_m_undefine
=*/
_EOF_

# # # # # # # # # # PROCESS SOURCE FILE # # # # # # # # #

f=`echo ${AGexe} | ${SED} 's/ .*//'`

agsrc=`cd $top_srcdir/agen5 && pwd`
tplsrc=`cd $top_srcdir/autoopts/tpl && pwd`

cat > ${testname}.cfg <<- _EOF_
	subblock       exparg=arg_name,arg_desc,arg_optional,arg_list
	template       snarf.tpl
	srcfile
	assign         group = ${testname}_grp
	assign         init  = Chosen_init
	base-name      ${testname}
	agarg          -L$agsrc
	agarg          -L$tplsrc
	input          ${testname}.c
	autogen        ${f}
	_EOF_
unset DEBUG_ENABLED

echo "getdefs load=${testname}.cfg ${testname}.c"
${VERBOSE} && {
  AUTOGEN_TRACE=everything
  AUTOGEN_TRACE_OUT=">>${testname}-ag-log.txt"
  export AUTOGEN_TRACE AUTOGEN_TRACE_OUT
}
${GDexe} load=${testname}.cfg || \
    failure getdefs load=${testname}.cfg

${SED} -e "${sed_omit_license}" -e '/^#undef  *NEW_PROC *$/,$d' \
    ${testname}.ini > ${testname}.ini.tst1

${SED} "${sed_omit_license}" ${testname}.h > ${testname}.h.tst1

# # # # # # # # # # EXPECTED INI FILE # # # # # # # # #

echo creating ${testname}.ini.OK1
cat > ${testname}.ini.OK1 <<'_EOF_'
#include "snarf.h"
typedef SCM (*scm_callback_t)(void);
void Chosen_init(void);

extern SCM snarf_grp_scm_sym_bumble_it          = SCM_BOOL_F;
static SCM snarf_grp_scm_sym_mumble_check       = SCM_BOOL_F;
#if GUILE_VERSION >= 108000
#define NEW_PROC(_As, _Ar, _Ao, _Ax, _An)   \
  scm_c_define_gsubr((char*)(_As),          \
                   _Ar, _Ao, _Ax, (scm_callback_t)(void*)ag_scm_ ## _An)
#else
#define NEW_PROC(_As, _Ar, _Ao, _Ax, _An)                                   \
  gh_new_procedure((char*)(_As), (scm_callback_t)(void*)ag_scm_ ## _An,     \
                   _Ar, _Ao, _Ax)
#endif

/*
 * snarf_grp Initialization procedure.
 */
void
Chosen_init(void)
{
static char const g_nm[55] =
/*     0 */ "test->example!\0"
/*    15 */ "guile-syntax-ele\0"
/*    32 */ "bumble-it\0"
/*    42 */ "mumble-check";

    NEW_PROC(g_nm +   0, 0, 0, 1, test_to_example_x);
    scm_make_synt(g_nm+15, scm_makacro, scm_m_undefine);
    snarf_grp_scm_sym_bumble_it = scm_permanent_object(SCM_CAR (scm_intern0 (g_nm+32)));
    snarf_grp_scm_sym_mumble_check = scm_permanent_object(SCM_CAR (scm_intern0 (g_nm+42)));
}
_EOF_

cmp ${testname}.ini.tst1 ${testname}.ini.OK1 || \
    failure "`diff ${testname}.ini.tst1 ${testname}.ini.OK1`"

# # # # # # # # # # EXPECTED HEADER FILE # # # # # # #

echo creating ${testname}.h.OK
cat > ${testname}.h.OK <<_EOF_
#ifndef GUILE_PROCS_SNARF_H_GUARD
#define GUILE_PROCS_SNARF_H_GUARD 1
#if GUILE_VERSION >= 108000
# include <libguile.h>
#else
# include <guile/gh.h>
#endif

typedef enum {
    GH_TYPE_UNDEFINED = 0,
    GH_TYPE_BOOLEAN,
    GH_TYPE_SYMBOL,
    GH_TYPE_CHAR,
    GH_TYPE_VECTOR,
    GH_TYPE_PAIR,
    GH_TYPE_NUMBER,
    GH_TYPE_STRING,
    GH_TYPE_PROCEDURE,
    GH_TYPE_LIST,
    GH_TYPE_INEXACT,
    GH_TYPE_EXACT
} teGuileType;

extern SCM snarf_grp_scm_test_to_example_x(SCM);
extern SCM snarf_grp_scm_sym_bumble_it;

#endif /* GUILE_PROCS_SNARF_H_GUARD */
_EOF_

cmp ${testname}.h.* || \
    failure "`diff ${testname}.h.*`"

# # # # # # # # # # PROCESS SOURCE FILE AGAIN # # # # # # # # #

cp ${testname}.cfg  ${testname}.cfg1

echo 'assign debug-enabled = true' >> ${testname}.cfg
DEBUG_ENABLED=true
export DEBUG_ENABLED

${GDexe} load=${testname}.cfg || \
    failure getdefs load=${testname}.cfg

${SED} -e "${sed_omit_license}" \
    -e '/^#undef  *NEW_PROC$/,$d' \
    ${testname}.ini > ${testname}.ini.tst2

${SED} "${sed_omit_license}" ${testname}.h > ${testname}.h.tst2

# # # # # # # # # # EXPECTED INI FILE # # # # # # # # #

echo creating ${testname}.ini.OK2
cat > ${testname}.ini.OK2 <<'_EOF_'
#include "snarf.h"
typedef SCM (*scm_callback_t)(void);
void Chosen_init(void);

extern SCM snarf_grp_scm_sym_bumble_it          = SCM_BOOL_F;
static SCM snarf_grp_scm_sym_mumble_check       = SCM_BOOL_F;
#ifdef DEBUG_ENABLED
static SCM
agrelay_scm_test_to_example_x(SCM scm0)
{
    if (OPT_VALUE_TRACE >= TRACE_EVERYTHING) {
        static char const proc_z[] =
            "Called ag_scm_test_to_example_x()\n";
        fwrite(proc_z, sizeof(proc_z) - 1, 1, trace_fp);
    }
    return ag_scm_test_to_example_x(scm0);
}

#if GUILE_VERSION >= 108000
#define NEW_PROC(_As, _Ar, _Ao, _Ax, _An)   \
  scm_c_define_gsubr((char*)(_As),          \
                   _Ar, _Ao, _Ax, (scm_callback_t)(void*)agrelay_scm_ ## _An)
#else
#define NEW_PROC(_As, _Ar, _Ao, _Ax, _An)                                    \
  gh_new_procedure((char*)(_As), (scm_callback_t)(void*)agrelay_scm_ ## _An, \
                   _Ar, _Ao, _Ax)
#endif

#else /* DEBUG_ENABLED *not* */
#if GUILE_VERSION >= 108000
#define NEW_PROC(_As, _Ar, _Ao, _Ax, _An)   \
  scm_c_define_gsubr((char*)(_As),          \
                   _Ar, _Ao, _Ax, (scm_callback_t)(void*)ag_scm_ ## _An)
#else
#define NEW_PROC(_As, _Ar, _Ao, _Ax, _An)                                   \
  gh_new_procedure((char*)(_As), (scm_callback_t)(void*)ag_scm_ ## _An,     \
                   _Ar, _Ao, _Ax)
#endif
#endif /* DEBUG_ENABLED */

/*
 * snarf_grp Initialization procedure.
 */
void
Chosen_init(void)
{
static char const g_nm[55] =
/*     0 */ "test->example!\0"
/*    15 */ "guile-syntax-ele\0"
/*    32 */ "bumble-it\0"
/*    42 */ "mumble-check";

    NEW_PROC(g_nm +   0, 0, 0, 1, test_to_example_x);
    scm_make_synt(g_nm+15, scm_makacro, scm_m_undefine);
    snarf_grp_scm_sym_bumble_it = scm_permanent_object(SCM_CAR (scm_intern0 (g_nm+32)));
    snarf_grp_scm_sym_mumble_check = scm_permanent_object(SCM_CAR (scm_intern0 (g_nm+42)));
}
_EOF_

cmp ${testname}.ini.tst2 ${testname}.ini.OK2 || \
    failure "`diff ${testname}.ini.tst2 ${testname}.ini.OK2`"

cleanup

## 
## Local Variables:
## mode: shell-script
## indent-tabs-mode: nil
## sh-indentation: 2
## sh-basic-offset: 2
## End:

# end of snarf.test