1 |
/* |
2 |
* Ascend Instance Tree Type Implementation Macros |
3 |
* by Tom Epperly & Ben Allan |
4 |
* 9/3/89 |
5 |
* Version: $Revision: 1.7 $ |
6 |
* Version control file: $RCSfile: instmacro.h,v $ |
7 |
* Date last modified: $Date: 1997/07/18 12:30:46 $ |
8 |
* Last modified by: $Author: mthomas $ |
9 |
* |
10 |
* This file is part of the Ascend Language Interpreter. |
11 |
* |
12 |
* Copyright 1996 Bejamin Allan |
13 |
* based on instance.c |
14 |
* Copyright (C) 1990, 1993, 1994 Thomas Guthrie Epperly |
15 |
* |
16 |
* The Ascend Language Interpreter is free software; you can redistribute |
17 |
* it and/or modify it under the terms of the GNU General Public License as |
18 |
* published by the Free Software Foundation; either version 2 of the |
19 |
* License, or (at your option) any later version. |
20 |
* |
21 |
* The Ascend Language Interpreter is distributed in hope that it will be |
22 |
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
23 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
24 |
* General Public License for more details. |
25 |
* |
26 |
* You should have received a copy of the GNU General Public License |
27 |
* along with the program; if not, write to the Free Software Foundation, |
28 |
* Inc., 675 Mass Ave, Cambridge, MA 02139 USA. Check the file named |
29 |
* COPYING. |
30 |
*/ |
31 |
|
32 |
#ifndef __INSTMACRO_H_SEEN__ |
33 |
#define __INSTMACRO_H_SEEN__ |
34 |
|
35 |
/** @file |
36 |
* Ascend Instance Tree Type Implementation Macros. |
37 |
* <pre> |
38 |
* When #including instmacro.h, make sure these files are #included first: |
39 |
* #include "utilities/ascConfig.h" |
40 |
* |
41 |
*--------------------------------------------------------------------------- |
42 |
* This header for instance and instantiator consumption only. |
43 |
* Clients keep your hands off! |
44 |
*--------------------------------------------------------------------------- |
45 |
* </pre> |
46 |
*/ |
47 |
|
48 |
/* temporary global variables used for debugging only */ |
49 |
#ifndef NDEBUG |
50 |
/* fundies */ |
51 |
extern struct RealInstance *g_r_inst; |
52 |
extern struct IntegerInstance *g_i_inst; |
53 |
extern struct BooleanInstance *g_b_inst; |
54 |
extern struct SetInstance *g_s_inst; |
55 |
extern struct SymbolInstance *g_sym_inst; |
56 |
/* constants */ |
57 |
extern struct RealConstantInstance *g_rc_inst; |
58 |
extern struct IntegerConstantInstance *g_ic_inst; |
59 |
extern struct BooleanConstantInstance *g_bc_inst; |
60 |
extern struct SetConstantInstance *g_sc_inst; |
61 |
extern struct SymbolConstantInstance *g_symc_inst; |
62 |
/* atoms */ |
63 |
extern struct RealAtomInstance *g_ra_inst; |
64 |
extern struct IntegerAtomInstance *g_ia_inst; |
65 |
extern struct BooleanAtomInstance *g_ba_inst; |
66 |
extern struct SetAtomInstance *g_sa_inst; |
67 |
extern struct SymbolAtomInstance *g_syma_inst; |
68 |
/* other */ |
69 |
extern struct ModelInstance *g_mod_inst; |
70 |
extern struct RelationInstance *g_rel_inst; |
71 |
extern struct LogRelInstance *g_lrel_inst; |
72 |
extern struct WhenInstance *g_when_inst; |
73 |
#endif |
74 |
|
75 |
/* init parent list size */ |
76 |
#define AVG_CONSTANT_PARENTS 2L |
77 |
/**< size to which all parent lists are initialized for real constants */ |
78 |
#define AVG_ICONSTANT_PARENTS 20L |
79 |
/**< size to which all parent lists are initialized for int constants */ |
80 |
#define AVG_PARENTS 2L |
81 |
/**< size to which all parent lists are initialized */ |
82 |
#define AVG_CASES 2L |
83 |
/**< size to which all cases lists are initialized (WHEN instance) */ |
84 |
#define AVG_WHEN 2L |
85 |
/**< size to which all when lists are initialized (models, relations) */ |
86 |
#define AVG_RELATIONS 7L |
87 |
/**< size to which all relation lists are initialized */ |
88 |
#define AVG_LOGRELS 7L |
89 |
/**< size to which all logical relation lists are initialized */ |
90 |
#define AVG_ARY_CHILDREN 7L |
91 |
/**< size to which all array children lists are initialized */ |
92 |
#define UNDEFAULTEDREAL 0.0 |
93 |
|
94 |
#define MAX_EXTRELATIONS 50 |
95 |
/**< maximum number of different ext relations for a given simulation */ |
96 |
|
97 |
/* type coercion definitions */ |
98 |
/* any */ |
99 |
#define INST(i) ((struct Instance *)(i)) |
100 |
/* other */ |
101 |
#define SIM_INST(i) ((struct SimulationInstance *)(i)) |
102 |
#define RELN_INST(i) ((struct RelationInstance *)(i)) |
103 |
#define LRELN_INST(i) ((struct LogRelInstance *)(i)) |
104 |
#define ARY_INST(i) ((struct ArrayInstance *)(i)) |
105 |
#define MOD_INST(i) ((struct ModelInstance *)(i)) |
106 |
#define W_INST(i) ((struct WhenInstance *)(i)) |
107 |
/* fundies */ |
108 |
#define R_INST(i) ((struct RealInstance *)(i)) |
109 |
#define I_INST(i) ((struct IntegerInstance *)(i)) |
110 |
#define B_INST(i) ((struct BooleanInstance *)(i)) |
111 |
#define S_INST(i) ((struct SetInstance *)(i)) |
112 |
#define SYM_INST(i) ((struct SymbolInstance *)(i)) |
113 |
/* constants */ |
114 |
#define CI_INST(i) ((struct CommonConstantInstance *)(i)) |
115 |
#define RC_INST(i) ((struct RealConstantInstance *)(i)) |
116 |
#define IC_INST(i) ((struct IntegerConstantInstance *)(i)) |
117 |
#define BC_INST(i) ((struct BooleanConstantInstance *)(i)) |
118 |
#define SYMC_INST(i) ((struct SymbolConstantInstance *)(i)) |
119 |
/* atoms */ |
120 |
#define CA_INST(i) ((struct CommonAtomInstance *)(i)) |
121 |
#define RA_INST(i) ((struct RealAtomInstance *)(i)) |
122 |
#define BA_INST(i) ((struct BooleanAtomInstance *)(i)) |
123 |
#define IA_INST(i) ((struct IntegerAtomInstance *)(i)) |
124 |
#define SA_INST(i) ((struct SetAtomInstance *)(i)) |
125 |
#define SYMA_INST(i) ((struct SymbolAtomInstance *)(i)) |
126 |
#define SOL_INST(i) ((struct SolverAtomInstance *)(i)) |
127 |
|
128 |
#define D_INST(i) ((struct GlobalDummyInstance *)(i)) |
129 |
/** constant inst assigned? */ |
130 |
#define CIASS(i) (CI_INST(i)->vflag & ci_ASSIGNED) |
131 |
/** boolean constant value */ |
132 |
#define BCV(i) ((BC_INST(i)->vflag & ci_BVAL) == ci_BVAL) |
133 |
|
134 |
/* parent macros for fundamental atoms real, integer, boolean, and set */ |
135 |
#define R_PARENT(i) \ |
136 |
INST((unsigned long)i-(unsigned long)R_INST(i)->parent_offset) |
137 |
#define I_PARENT(i) \ |
138 |
INST((unsigned long)i-(unsigned long)I_INST(i)->parent_offset) |
139 |
#define B_PARENT(i) \ |
140 |
INST((unsigned long)i-(unsigned long)B_INST(i)->parent_offset) |
141 |
#define S_PARENT(i) \ |
142 |
INST((unsigned long)i-(unsigned long)S_INST(i)->parent_offset) |
143 |
#define SYM_PARENT(i) \ |
144 |
INST((unsigned long)i-(unsigned long)SYM_INST(i)->parent_offset) |
145 |
|
146 |
/** this should probably be conditionally defined by LONGCHILDREN |
147 |
* so that if LONGCHILDREN, just returns ivalue. |
148 |
*/ |
149 |
#define NextHighestEven(ivalue) (((ivalue) & 1) ? ((ivalue)+1) : (ivalue)) |
150 |
|
151 |
/* child array macros */ |
152 |
#define CHILD_ADR(iptr,type,c)\ |
153 |
((struct Instance **)((unsigned long)iptr+(unsigned long)sizeof(type))+c) |
154 |
#define SIM_CHILD(i,c) CHILD_ADR(i,struct SimulationInstance,c) |
155 |
#define MOD_CHILD(i,c) CHILD_ADR(i,struct ModelInstance,c) |
156 |
#define RA_CHILD(i,c) CHILD_ADR(i,struct RealAtomInstance,c) |
157 |
#define BA_CHILD(i,c) CHILD_ADR(i,struct BooleanAtomInstance,c) |
158 |
#define IA_CHILD(i,c) CHILD_ADR(i,struct IntegerAtomInstance,c) |
159 |
#define SA_CHILD(i,c) CHILD_ADR(i,struct SetAtomInstance,c) |
160 |
#define SYMA_CHILD(i,c) CHILD_ADR(i,struct SymbolAtomInstance,c) |
161 |
#define REL_CHILD(i,c) CHILD_ADR(i,struct RelationInstance,c) |
162 |
#define LREL_CHILD(i,c) CHILD_ADR(i,struct LogRelInstance,c) |
163 |
|
164 |
#define CLIST(in,type) (struct Instance **)((unsigned long)(in)+sizeof(type)) |
165 |
#define BASE_ADDR(in,num,type) INST((CLIST(in,type)) + NextHighestEven(num)) |
166 |
|
167 |
/**< |
168 |
* @todo The whole use of BASE_ADDR needs to be reinvestigated. in particular |
169 |
* we need RealInstance children to be aligned to 8 bytes, not 2 bytes |
170 |
* which is all NextHighestEven gives us. |
171 |
*/ |
172 |
|
173 |
#ifdef NDEBUG |
174 |
#define NotAtom(i) IsCompoundInstance(i) |
175 |
#else |
176 |
#define NotAtom(i) NotAtomF(i) |
177 |
#endif |
178 |
extern int NotAtomF(struct Instance *); |
179 |
/**< |
180 |
* <!-- macro NotAtom(i) --> |
181 |
* <!-- NotAtomF(i) --> |
182 |
* Returns 1 if instance is compound (i.e. not relation, ATOM, constant, |
183 |
* when. that means array or MODEL.) else returns 0. |
184 |
*/ |
185 |
|
186 |
#endif /* __INSTMACRO_H_SEEN__ */ |
187 |
|