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 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
|
/***********************************************************************
*
* LUSH Lisp Universal Shell
* Copyright (C) 2002 Leon Bottou, Yann Le Cun, AT&T Corp, NECI.
* Includes parts of TL3:
* Copyright (C) 1987-1999 Leon Bottou and Neuristique.
* Includes selected parts of SN3.2:
* Copyright (C) 1991-2001 AT&T Corp.
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* This program 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, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA
*
***********************************************************************/
/***********************************************************************
* $Id: check_func.h,v 1.9 2004/04/16 14:28:03 leonb Exp $
**********************************************************************/
#ifndef CHECK_FUNC_H
#define CHECK_FUNC_H
#ifndef LUSHAPI
#define LUSHAPI
#endif
#ifdef __cplusplus
extern "C" {
#ifndef __cplusplus
}
#endif
#endif
/* ---------------------------------------- */
/* TRACING CALLS */
/* ---------------------------------------- */
struct dh_trace_stack {
char *info;
struct dh_trace_stack *next;
};
extern LUSHAPI struct dh_trace_stack *dh_trace_root;
LUSHAPI void print_dh_recent(int,FILE*);
LUSHAPI void print_dh_trace_stack(void);
#define TRACE_PUSH(s) \
struct dh_trace_stack _trace; _trace.info = s; \
_trace.next = dh_trace_root; dh_trace_root = &_trace;
#define TRACE_POP(s) \
dh_trace_root = _trace.next;
/* Tracing is enabled when running code from SN.
* To enable tracing in a standalkone program, define TRACE
*/
#ifdef NOLISP
#ifndef TRACE
#undef TRACE_PUSH
#undef TRACE_POP
#define TRACE_PUSH(s) /**/
#define TRACE_POP(s) /**/
#endif
#endif
/* ---------------------------------------- */
/* RUNTIME ERRORS */
/* ---------------------------------------- */
extern LUSHAPI char *rterr_bound;
extern LUSHAPI char *rterr_rtype;
extern LUSHAPI char *rterr_dim;
extern LUSHAPI char *rterr_loopdim;
extern LUSHAPI char *rterr_emptystr;
extern LUSHAPI char *rterr_range;
extern LUSHAPI char *rterr_srg_of;
extern LUSHAPI char *rterr_unsized_matrix;
extern LUSHAPI char *rterr_not_same_dim;
extern LUSHAPI char *rterr_out_of_memory;
extern LUSHAPI char *rterr_cannot_realloc;
extern LUSHAPI char *rterr_bad_dimensions;
#define RTERR_GEN(test,errstr) \
if (test) { run_time_error(errstr); }
#define RTERR_BOUND(test) \
RTERR_GEN(test,rterr_bound)
#define RTERR_RTYPE(test) \
RTERR_GEN(test,rterr_rtype)
#define RTERR_DIM(test) \
RTERR_GEN(test,rterr_dim)
#define RTERR_LOOPDIM(test) \
RTERR_GEN(test,rterr_loopdim)
#define RTERR_EMPTYSTR(test) \
RTERR_GEN(test,rterr_emptystr)
#define RTERR_RANGE(test) \
RTERR_GEN(test,rterr_range)
#define RTERR_SRG_OVERFLOW \
run_time_error(rterr_srg_of);
/* ---------------------------------------- */
/* CHECKING OBJECTS */
/* ---------------------------------------- */
LUSHAPI void check_obj_class(void *obj, void *classvtable);
LUSHAPI int test_obj_class(void *obj, void *classvtable);
/* ---------------------------------------- */
/* CHECKING MATRICES */
/* ---------------------------------------- */
LUSHAPI void srg_resize_compiled(struct srg* ,int ,char *, int);
LUSHAPI void srg_resize(struct srg *, int , char *, int );
LUSHAPI void srg_free(struct srg *);
#define Mis_sized(i1) \
if((i1)->flags & IDF_UNSIZED) \
run_time_error(rterr_unsized_matrix);
#define Mis_sized_is_sized(i1, i2) \
if(((i1)->flags & IDF_UNSIZED) || ((i2)->flags & IDF_UNSIZED)) \
run_time_error(rterr_unsized_matrix);
#define Msame_size1(i1,i2) \
Mis_sized_is_sized(i1, i2) \
if((i1)->dim[0] != (i2)->dim[0]) \
run_time_error(rterr_not_same_dim);
#define Msame_size2(i1,i2) \
Mis_sized_is_sized(i1, i2) \
if(((i1)->dim[0] != (i2)->dim[0]) || ((i1)->dim[1] != (i2)->dim[1])) \
run_time_error(rterr_not_same_dim);
#define Msame_size(i1,i2) \
Mis_sized_is_sized(i1, i2) \
{ int j; \
for(j=0; j<(i1)->ndim; j++) \
if((i1)->dim[j] != (i2)->dim[j]) \
run_time_error(rterr_not_same_dim);}
#define Msrg_resize(sr, new_size) \
if((sr)->size < (int)(new_size)) \
srg_resize_compiled(sr, new_size, __FILE__, __LINE__);
#define Midx_checksize0(i1) { \
int siz = (i1)->offset + 1; \
Msrg_resize((i1)->srg, siz) \
}
#define Midx_checksize1(i1) { \
int siz = 1 + (i1)->offset + ((i1)->dim[0] - 1) * (i1)->mod[0]; \
Msrg_resize((i1)->srg, siz) \
}
#define Midx_checksize(i1) { \
int j, siz=(i1)->offset+1; \
for(j=0; j<(i1)->ndim; j++) \
siz += ((i1)->dim[j] - 1) * (i1)->mod[j]; \
Msrg_resize((i1)->srg, siz); \
}
#define Mcheck0(i1) \
if ((i1)->flags & IDF_UNSIZED) { \
Midx_checksize0(i1); \
(i1)->flags &= ~IDF_UNSIZED; \
}
#define Msize_or_check0(i1, i2) \
Mis_sized(i1) \
if ((i2)->flags & IDF_UNSIZED) { \
Midx_checksize0(i2); \
(i2)->flags &= ~IDF_UNSIZED; \
}
#define Msize_or_check1(i1, i2) \
Mis_sized(i1) \
if ((i2)->flags & IDF_UNSIZED) { \
(i2)->dim[0]=(i1)->dim[0]; \
(i2)->mod[0]=1; \
Midx_checksize1(i2); \
(i2)->flags &= ~IDF_UNSIZED; \
} else \
if ((i1)->dim[0] != (i2)->dim[0]) \
run_time_error(rterr_bad_dimensions);
#define Msize_or_check2(i1, i2) \
Mis_sized(i1) \
if ((i2)->flags & IDF_UNSIZED) { \
(i2)->dim[1]=(i1)->dim[1]; \
(i2)->mod[1]=1; \
(i2)->dim[0]=(i1)->dim[0]; \
(i2)->mod[0]=(i2)->dim[1]; \
Midx_checksize(i2); \
(i2)->flags &= ~IDF_UNSIZED; \
} else \
if (((i1)->dim[0]!=(i2)->dim[0]) || ((i1)->dim[1]!=(i2)->dim[1])) \
run_time_error(rterr_bad_dimensions);
#define Msize_or_check(i1, i2) \
Mis_sized(i1) \
if ((i2)->flags & IDF_UNSIZED) { \
int j, m=1; \
for (j=(i2)->ndim-1; j>=0; --j) { \
(i2)->dim[j]=(i1)->dim[j]; \
(i2)->mod[j]=m; \
m *= (i2)->dim[j]; \
} \
Midx_checksize(i2); \
(i2)->flags &= ~IDF_UNSIZED; \
} else { /* both are dimensioned, then check */ \
int j; \
if ((i1)->ndim != (i2)->ndim) \
run_time_error(rterr_bad_dimensions); \
for (j=0; j< (i1)->ndim; j++) \
if ((i1)->dim[j] != (i2)->dim[j]) \
run_time_error(rterr_bad_dimensions); \
}
#define Msize_or_check_1D(dim0, i2) \
if ((i2)->flags & IDF_UNSIZED) { \
(i2)->dim[0]=dim0; \
(i2)->mod[0]=1; \
Midx_checksize(i2); \
(i2)->flags &= ~IDF_UNSIZED; \
} else { /* both are dimensioned, then check */ \
if ((i2)->ndim != 1 || (i2)->dim[0] != dim0) \
run_time_error(rterr_bad_dimensions); \
}
#define Msize_or_check_2D(dim0, dim1, i2) \
if ((i2)->flags & IDF_UNSIZED) { \
(i2)->dim[1]=dim1; \
(i2)->mod[1]=1; \
(i2)->dim[0]=dim0; \
(i2)->mod[0]=dim1; \
Midx_checksize(i2); \
(i2)->flags &= ~IDF_UNSIZED; \
} else { /* both are dimensioned, then check */ \
if ((i2)->ndim != 2 || (i2)->dim[0] != dim0 || (i2)->dim[1] != dim1) \
run_time_error(rterr_bad_dimensions); \
}
#define Mcheck_main(i1) \
Mis_sized(i1);
#define Mcheck_main_maout(i1, i2) \
Mis_sized(i1); \
Msize_or_check(i1,i2);
#define Mcheck_main_main_maout(i0, i1, i2) \
Mis_sized_is_sized(i0, i1); \
Msame_size(i0, i1); \
Msize_or_check(i1, i2);
#define Mcheck_main_main_maout2(i0, i1, i2) \
Mis_sized_is_sized(i0, i1); \
Msize_or_check(i1, i2);
#define Mcheck_main_main_maout_dot21(i0, i1, i2) \
Mis_sized_is_sized(i0, i1); \
Msize_or_check_1D((i0)->dim[1], i1); \
Msize_or_check_1D((i0)->dim[0], i2);
#define Mcheck_main_main_maout_dot42(i0, i1, i2) \
Mis_sized_is_sized(i0, i1); \
Msize_or_check_2D((i0)->dim[2], (i0)->dim[3], i1); \
Msize_or_check_2D((i0)->dim[0], (i0)->dim[1], i2);
#define Mcheck_main_m0out(i1, i2) \
Mis_sized(i1); \
Mcheck0(i2);
#define Mcheck_main_main_m0out(i0, i1, i2) \
Mis_sized_is_sized(i0, i1); \
Msame_size(i0, i1); \
Mcheck0(i2);
#define Mcheck_main_m0in_maout(i0, i1, i2) \
Mis_sized_is_sized(i0, i1); \
Msize_or_check(i0, i2);
#define Mcheck_m0in_m0out(i1, i2) \
Msize_or_check0(i1,i2)
#define Mcheck_m1out(i1) \
Mis_sized(i1);
#define Mcheck_m1in_m1in_m2out(i0, i1, i2) \
Mis_sized_is_sized(i0, i1); \
if ((i2)->flags & IDF_UNSIZED) { \
(i2)->dim[1]=(i1)->dim[0]; \
(i2)->mod[1]=1; \
(i2)->dim[0]=(i0)->dim[0]; \
(i2)->mod[0]=(i2)->dim[1]; \
Midx_checksize(i2); \
(i2)->flags &= ~IDF_UNSIZED; \
} else \
if (((i0)->dim[0]!=(i2)->dim[0]) || ((i1)->dim[0]!=(i2)->dim[1])) \
run_time_error(rterr_bad_dimensions);
#define Mcheck_m2in_m2in_m4out(i0, i1, i2) \
Mis_sized_is_sized(i0, i1); \
if ((i2)->flags & IDF_UNSIZED) { \
(i2)->dim[3]=(i1)->dim[1]; \
(i2)->mod[3]=1; \
(i2)->dim[2]=(i1)->dim[0]; \
(i2)->mod[2]=(i2)->dim[3]; \
(i2)->dim[1]=(i0)->dim[1]; \
(i2)->mod[1]= (i2)->dim[3] * (i2)->dim[2]; \
(i2)->dim[0]=(i0)->dim[0]; \
(i2)->mod[0]= (i2)->mod[1] * (i2)->dim[1]; \
Midx_checksize(i2); \
(i2)->flags &= ~IDF_UNSIZED; \
} else \
if (((i0)->dim[0]!=(i2)->dim[0]) || ((i0)->dim[1]!=(i2)->dim[1]) || \
((i1)->dim[0]!=(i2)->dim[2]) || ((i1)->dim[1]!=(i2)->dim[3])) \
run_time_error(rterr_bad_dimensions);
/* Mcheck_m1in_m0out, Mcheck_m2in_m0out --> Mcheck_main_m0out */
/* Mcheck_m1in_m1out, Mcheck_m2in_m2out --> Mcheck_main_maout */
/* Mcheck_m1in_m0in_m1out, Mcheck_m2in_m0in_m2out --> Mcheck_main_m0in_maout */
/* Mcheck_m1in_m1in_m1out, Mcheck_m2in_m2in_m2out --> Mcheck_main_main_maout */
LUSHAPI void check_main_maout(struct idx *i1, struct idx *i2);
LUSHAPI void check_main_maout_any(struct idx *i1, struct idx *i2);
LUSHAPI void check_main_main_maout(struct idx *i0,
struct idx *i1, struct idx *i2);
LUSHAPI void check_main_m0out(struct idx *i1, struct idx *i2);
LUSHAPI void check_main_main_m0out(struct idx *i0,
struct idx *i1, struct idx *i2);
LUSHAPI void check_main_m0in_maout(struct idx *i0,
struct idx *i1, struct idx *i2);
LUSHAPI void check_main_main_maout_dot21(struct idx *i0,
struct idx *i1, struct idx *i2);
LUSHAPI void check_main_main_maout_dot42(struct idx *i0,
struct idx *i1, struct idx *i2);
LUSHAPI void check_m1in_m1in_m2out(struct idx *i0,
struct idx *i1, struct idx *i2);
LUSHAPI void check_m2in_m2in_m4out(struct idx *i0,
struct idx *i1, struct idx *i2);
/* ---------------------------------------- */
/* THE END */
/* ---------------------------------------- */
#ifdef __cplusplus
}
#endif
#endif
|