atlas  0.6
global.h
Go to the documentation of this file.
1 /*1:*/
2 #line 47 "global.w"
3 #ifndef GLOBAL_H
4 #define GLOBAL_H/*4:*/
5 #line 154 "global.w"
6 #include <map>
7 #include "parsetree.h"
8 #include "axis-types.h" /*:4*//*57:*/
9 #line 1196 "global.w"
10 #include <string>
11 #include <sstream>/*:57*//*59:*/
12 #line 1232 "global.w"
13 #include "arithmetic.h"/*:59*//*65:*/
14 #line 1347 "global.w"
15 #include "../Atlas.h"
16 #include "matrix.h"
17 #include "ratvec.h" /*:65*/
18 #line 50 "global.w"
19 
20 namespace atlas{namespace interpreter{/*3:*/
21 #line 119 "global.w"
22 typedef std::shared_ptr<shared_value>shared_share;
23 class id_data
24 {shared_share val;type_expr tp;bool is_constant;
25 public:
26 id_data(shared_share&&val,type_expr&&t,bool is_const)
27 :val(std::move(val)),tp(std::move(t)),is_constant(is_const){}
28 #ifdef incompletecpp11
29 id_data():val(),tp(),is_constant(false){}
30 
31 id_data(const id_data&x):val(),tp(),is_constant(false){}
32 
33 id_data&operator=(const id_data&x)=delete;
34 id_data(id_data&&x)
35 :val(std::move(x.val)),tp(std::move(x.tp)),is_constant(x.is_constant){}
37 {val=std::move(x.val);tp=std::move(x.tp);is_constant=x.is_constant;
38 return*this;
39 }
40 #else
41 id_data(id_data&&x)=default;
42 id_data&operator=(id_data&&x)=default;
43 #endif
44 void swap(id_data&x){val.swap(x.val);tp.swap(x.tp);}
45 
46 const shared_share&value()const{return val;}
47 const type_expr&type()const{return tp;}
48 type_expr&type(){return tp;}
49 
50 bool is_const()const{return is_constant;}
51 };/*:3*//*5:*/
52 #line 162 "global.w"
53 class Id_table
54 {typedef std::map<id_type,id_data>map_type;
55 map_type table;
56 public:
57 Id_table(const Id_table&)=delete;
58 Id_table&operator=(const Id_table&)=delete;
59 Id_table():table(){}
60 
61 void add(id_type id,shared_value v,type_expr&&t,bool is_const);
62 
63 void add_type_def(id_type id,type_expr&&t);
64 bool remove(id_type id);
65 shared_share address_of(id_type id);
66 
67 bool present(id_type id)const
68 {return table.find(id)!=table.end();}
69 bool is_defined_type(id_type id)const;
70 const_type_p type_of(id_type id,bool&is_const)const;
71 
72 void specialise(id_type id,const type_expr&type);
73 
74 shared_value value_of(id_type id)const;
75 
76 size_t size()const{return table.size();}
77 void print(std::ostream&)const;
78 };/*:5*//*14:*/
79 #line 373 "global.w"
81 
82 typedef std::shared_ptr<const function_base>shared_function;
83 
84 
86 {shared_function val;func_type tp;
87 public:
88 overload_data(shared_function&&val,func_type&&t)
89 :val(std::move(val)),tp(std::move(t)){}
90 #ifdef incompletecpp11
91 overload_data(const overload_data&x)=delete;
92 overload_data&operator=(const overload_data&x)=delete;
94 :val(std::move(x.val)),tp(std::move(x.tp)){}
96 {val=std::move(x.val);tp=std::move(x.tp);return*this;}
97 #else
98 overload_data(overload_data&&x)=default;
100 =default;
101 #endif
102 
103 const shared_function&value()const{return val;}
104 const func_type&type()const{return tp;}
105 };/*:14*//*15:*/
106 #line 425 "global.w"
108 {
109 public:
110 #ifdef incompletecpp11
111 class variant_list:public std::vector<overload_data>
112 {typedef std::vector<overload_data>Base;
113 public:
114 variant_list():Base(){}
115 variant_list(const variant_list&x)
116 
117 :Base(){assert(x.size()==0);}
118 variant_list(variant_list&&x):Base(std::move(x)){}
119 variant_list&operator=(const variant_list&x)=delete;
120 };
121 #else
122 typedef std::vector<overload_data>variant_list;
123 #endif
124 typedef std::map<id_type,variant_list>map_type;
125 private:
126 map_type table;
127 public:
128 overload_table(const Id_table&)=delete;
129 overload_table&operator=(const Id_table&)=delete;
130 overload_table():table(){}
131 
132 const variant_list&variants(id_type id)const;
133 size_t size()const{return table.size();}
134 
135 void print(std::ostream&)const;
136 
137 void add(id_type id,shared_function v,type_expr&&t);
138 
139 bool remove(id_type id,const type_expr&arg_t);
140 };/*:15*//*60:*/
141 #line 1247 "global.w"
142 struct int_value:public value_base
143 {int val;
144 
145 explicit int_value(int v):val(v){}
147 void print(std::ostream&out)const{out<<val;}
148 int_value*clone()const{return new int_value(*this);}
149 static const char*name(){return "integer";}
150 private:
151 int_value(const int_value&v):val(v.val){}
152 };
153 
154 typedef std::shared_ptr<const int_value>shared_int;
155 typedef std::shared_ptr<int_value>own_int;
156 
157 struct rat_value:public value_base
158 {Rational val;
159 
160 explicit rat_value(Rational v):val(v){}
162 void print(std::ostream&out)const{out<<val;}
163 rat_value*clone()const{return new rat_value(*this);}
164 static const char*name(){return "integer";}
165 private:
166 rat_value(const rat_value&v):val(v.val){}
167 };
168 
169 typedef std::shared_ptr<const rat_value>shared_rat;
170 typedef std::shared_ptr<rat_value>own_rat;/*:60*//*61:*/
171 #line 1281 "global.w"
174 
175 explicit string_value(const std::string&s):val(s){}
176 explicit string_value(std::string&&s):val(std::move(s)){}
177 template<typename I>string_value(I begin,I end):val(begin,end){}
179 void print(std::ostream&out)const{out<<'"'<<val<<'"';}
180 string_value*clone()const{return new string_value(*this);}
181 static const char*name(){return "string";}
182 private:
183 string_value(const string_value&v):val(v.val){}
184 };
185 
186 typedef std::shared_ptr<const string_value>shared_string;
187 typedef std::shared_ptr<string_value>own_string;
188 
189 
190 struct bool_value:public value_base
191 {bool val;
192 
193 explicit bool_value(bool v):val(v){}
195 void print(std::ostream&out)const{out<<std::boolalpha<<val;}
196 bool_value*clone()const{return new bool_value(*this);}
197 static const char*name(){return "Boolean";}
198 private:
199 bool_value(const bool_value&v):val(v.val){}
200 };
201 
202 typedef std::shared_ptr<const bool_value>shared_bool;/*:61*//*66:*/
203 #line 1359 "global.w"
206 
207 explicit vector_value(const std::vector<int> &v):val(v){}
208 explicit vector_value(std::vector<int> &&v):val(std::move(v)){}
209 template<typename I>vector_value(I begin,I end):val(begin,end){}
211 virtual void print(std::ostream&out)const;
212 vector_value*clone()const{return new vector_value(*this);}
213 static const char*name(){return "vector";}
214 private:
215 vector_value(const vector_value&v):val(v.val){}
216 };
217 
218 typedef std::shared_ptr<const vector_value>shared_vector;
219 typedef std::shared_ptr<vector_value>own_vector;/*:66*//*67:*/
220 #line 1381 "global.w"
223 
224 explicit matrix_value(const int_Matrix&v):val(v){}
225 explicit matrix_value(int_Matrix&&v):val(std::move(v)){}
227 virtual void print(std::ostream&out)const;
228 matrix_value*clone()const{return new matrix_value(*this);}
229 static const char*name(){return "matrix";}
230 private:
231 matrix_value(const matrix_value&v):val(v.val){}
232 };
233 
234 typedef std::shared_ptr<const matrix_value>shared_matrix;
235 typedef std::shared_ptr<matrix_value>own_matrix;
236 
239 
241 :val(v){val.normalize();}
243 :val(std::move(v)){val.normalize();}
245 :val(v,d){val.normalize();}
247 :val(std::move(v),d){val.normalize();}
248 template<typename I>rational_vector_value(I begin,I end,int d)
249 :val(int_Vector(begin,end),d){val.normalize();}
251 virtual void print(std::ostream&out)const;
253 {return new rational_vector_value(*this);}
254 static const char*name(){return "rational vector";}
255 private:
257 };
258 
259 typedef std::shared_ptr<const rational_vector_value>shared_rational_vector;
260 typedef std::shared_ptr<rational_vector_value>own_rational_vector;/*:67*//*77:*/
261 #line 1691 "global.w"
262 typedef void(*wrapper_function)(expression_base::level);/*:77*//*12:*/
263 #line 346 "global.w"
264 extern Id_table*global_id_table;/*:12*//*24:*/
265 #line 637 "global.w"
266 extern overload_table*global_overload_table;/*:24*//*33:*/
267 #line 769 "global.w"
268 extern std::ostream*output_stream;/*:33*//*43:*/
269 #line 980 "global.w"
270 extern bool clean;/*:43*//*55:*/
271 #line 1182 "global.w"
272 extern int verbosity;/*:55*//*62:*/
273 #line 1318 "global.w"
274 extern const shared_bool global_false,global_true;/*:62*//*11:*/
275 #line 342 "global.w"
276 std::ostream&operator<<(std::ostream&out,const Id_table&p);/*:11*//*23:*/
277 #line 631 "global.w"
278 std::ostream&operator<<(std::ostream&out,const overload_table&p);/*:23*//*26:*/
279 #line 654 "global.w"
280 void initialise_evaluator();/*:26*//*29:*/
281 #line 684 "global.w"
282 type_expr analyse_types(const expr&e,expression_ptr&p);/*:29*//*32:*/
283 #line 752 "global.w"
284 void global_set_identifier(const struct raw_id_pat&id,expr_p e,int overload);
290 (id_type id,type_p type,raw_id_pat ip,const YYLTYPE&loc);
291 void show_ids();
292 void type_of_expr(expr_p e);
293 void show_overloads(id_type id);/*:32*//*78:*/
294 #line 1697 "global.w"
295 void install_function
296 (wrapper_function f,const char*name,const char*type_string);/*:78*//*94:*/
297 #line 2257 "global.w"
303 #line 2939 "global.w"
304 void mm_prod_wrapper(expression_base::level);/*:112*//*117:*/
305 #line 3175 "global.w"
307 void id_mat_wrapper(expression_base::level l);/*:117*//*58:*/
308 #line 1210 "global.w"
309 template<typename T>
310 std::string str(T n){std::ostringstream s;s<<n;return s.str();}
311 inline std::string str(unsigned char c)
312 {return str(static_cast<unsigned int>(c));}/*:58*//*64:*/
313 #line 1328 "global.w"
314 inline shared_bool whether(bool b){return b?global_true:global_false;}/*:64*/
315 #line 55 "global.w"
316 
317 }}
318 #endif/*:1*/
std::shared_ptr< const rational_vector_value > shared_rational_vector
Definition: global.h:259
size_t size() const
Definition: global.h:76
void global_set_identifier(const raw_id_pat &raw_pat, expr_p raw, int overload)
Definition: global.cpp:2091
char * loc
Definition: common.c:89
std::ostream * output_stream
Definition: global.cpp:21
void swap(type_expr &t) noexcept
Definition: axis-types.cpp:143
Id_table * global_id_table
Definition: global.cpp:17
vector_value * clone() const
Definition: global.h:212
std::map< id_type, id_data > map_type
Definition: global.h:54
rational_vector_value(const rational_vector_value &v)
Definition: global.h:256
int_value(const int_value &v)
Definition: global.h:151
int_Vector val
Definition: global.h:205
void type_define_identifier(id_type id, type_p t, raw_id_pat ip, const YYLTYPE &loc)
Definition: global.cpp:2131
type_expr & type()
Definition: global.h:48
std::vector< overload_data > variant_list
Definition: global.h:122
std::ostream & operator<<(std::ostream &out, const raw_type_list &l)
Definition: axis-types.cpp:218
map_type table
Definition: global.h:55
Definition: parse_types.h:51
overload_data(shared_function &&val, func_type &&t)
Definition: global.h:88
Hash_table::id_type id_type
Definition: parse_types.h:22
rational_vector_value(RatWeight &&v)
Definition: global.h:242
rational_vector_value * clone() const
Definition: global.h:252
const shared_function & value() const
Definition: global.h:103
void global_declare_identifier(id_type id, type_p t)
Definition: global.cpp:2099
uA p
Definition: lists.cpp:26
static const char * name()
Definition: global.h:149
int val
Definition: global.h:143
int verbosity
Definition: global.cpp:25
Definition: global.h:221
Definition: global.h:172
bool clean
Definition: global.cpp:23
void global_forget_overload(id_type id, type_p t)
Definition: global.cpp:2119
void show_overloads(id_type id)
Definition: global.cpp:2179
Definition: axis-types.h:116
void sizeof_vector_wrapper(expression_base::level l)
Definition: global.cpp:2264
void global_set_identifiers(const raw_let_list &d)
Definition: global.cpp:2094
void sizeof_string_wrapper(expression_base::level l)
Definition: global.cpp:2258
std::unique_ptr< expression_base > expression_ptr
Definition: axis-types.h:206
std::shared_ptr< const string_value > shared_string
Definition: global.h:186
static const char * name()
Definition: global.h:164
void type_of_expr(expr_p raw)
Definition: global.cpp:2170
rat_value(Rational v)
Definition: global.h:160
const shared_share & value() const
Definition: global.h:46
void print(std::ostream &out) const
Definition: global.h:147
Definition: global.h:53
const func_type & type() const
Definition: global.h:104
string_value(const string_value &v)
Definition: global.h:183
std::shared_ptr< rational_vector_value > own_rational_vector
Definition: global.h:260
bool_value * clone() const
Definition: global.h:196
rational_vector_value(const int_Vector &v, int d)
Definition: global.h:244
void id_mat_wrapper(expression_base::level l)
Definition: global.cpp:2297
const shared_bool global_false
Definition: global.cpp:27
matrix_value * clone() const
Definition: global.h:228
static const char * name()
Definition: global.h:229
std::shared_ptr< matrix_value > own_matrix
Definition: global.h:235
~matrix_value()
Definition: global.h:226
void mm_prod_wrapper(expression_base::level l)
Definition: global.cpp:2283
void virtual_module_size_wrapper(expression_base::level l)
Definition: atlas-types.cpp:3312
const shared_bool global_true
Definition: global.cpp:28
void show_ids()
Definition: global.cpp:2191
rat_value * clone() const
Definition: global.h:163
matrix_value(int_Matrix &&v)
Definition: global.h:225
void transpose_mat_wrapper(expression_base::level l)
Definition: global.cpp:2291
overload_table * global_overload_table
Definition: global.cpp:19
static const char * name()
Definition: global.h:181
Definition: global.h:204
bool is_const() const
Definition: global.h:50
vector_value(I begin, I end)
Definition: global.h:209
~vector_value()
Definition: global.h:210
~bool_value()
Definition: global.h:194
bool is_constant
Definition: global.h:24
std::shared_ptr< const vector_value > shared_vector
Definition: global.h:218
Definition: axis-types.h:51
string_value(std::string &&s)
Definition: global.h:176
Rational val
Definition: global.h:158
vector_value(const vector_value &v)
Definition: global.h:215
string_value * clone() const
Definition: global.h:180
rational_vector_value(int_Vector &&v, int d)
Definition: global.h:246
Definition: parser.tab.h:139
std::shared_ptr< int_value > own_int
Definition: global.h:155
size_t size() const
Definition: global.h:133
std::map< id_type, variant_list > map_type
Definition: global.h:124
Definition: sl_list.h:86
func_type tp
Definition: global.h:86
int_value * clone() const
Definition: global.h:148
Definition: axis-types.h:91
Definition: global.h:85
RatWeight val
Definition: global.h:238
vector_value(std::vector< int > &&v)
Definition: global.h:208
std::string str(T n)
Definition: global.h:310
std::shared_ptr< const int_value > shared_int
Definition: global.h:154
type_expr analyse_types(const expr &e, expression_ptr &p)
Definition: global.cpp:2056
type_expr tp
Definition: global.h:24
std::shared_ptr< const bool_value > shared_bool
Definition: global.h:202
#define out(c)
Definition: cweave.c:205
bool_value(const bool_value &v)
Definition: global.h:199
const type_expr & type() const
Definition: global.h:47
void initialise_evaluator()
Definition: global.cpp:1886
static const char * name()
Definition: global.h:213
shared_bool whether(bool b)
Definition: global.h:314
int_value(int v)
Definition: global.h:145
bool present(id_type id) const
Definition: global.h:67
rational_vector_value(const RatWeight &v)
Definition: global.h:240
Definition: global.h:157
void(* wrapper_function)(expression_base::level)
Definition: global.h:262
rational_vector_value(I begin, I end, int d)
Definition: global.h:248
RationalVector & normalize()
Definition: ratvec.cpp:135
shared_function val
Definition: global.h:86
void swap(id_data &x)
Definition: global.h:44
Definition: global.h:142
vector_value(const std::vector< int > &v)
Definition: global.h:207
matrix_value(const matrix_value &v)
Definition: global.h:231
Id_table()
Definition: global.h:59
std::shared_ptr< rat_value > own_rat
Definition: global.h:170
void print(std::ostream &out) const
Definition: global.h:162
Definition: axis.h:168
void global_forget_identifier(id_type id)
Definition: global.cpp:2113
static const char * name()
Definition: global.h:197
~string_value()
Definition: global.h:178
std::shared_ptr< vector_value > own_vector
Definition: global.h:219
id_data & operator=(id_data &&x)=default
char * name
Definition: common.c:103
void print(std::ostream &out) const
Definition: global.h:179
Definition: global.h:107
unsigned long n
Definition: axis.cpp:77
static const char * name()
Definition: global.h:254
simple_list< T, Alloc >::const_iterator end(const simple_list< T, Alloc > &l)
Definition: sl_list.h:650
Definition: Atlas.h:38
void print(char *s,...)
Definition: common.c:861
bool_value(bool v)
Definition: global.h:193
string_value(const std::string &s)
Definition: global.h:175
int_Matrix val
Definition: global.h:222
Definition: global.h:23
void matrix_ncols_wrapper(expression_base::level l)
Definition: global.cpp:2276
std::shared_ptr< const matrix_value > shared_matrix
Definition: global.h:234
std::shared_ptr< const rat_value > shared_rat
Definition: global.h:169
overload_table()
Definition: global.h:130
void print(std::ostream &out) const
Definition: global.h:195
std::shared_ptr< string_value > own_string
Definition: global.h:187
const expr & e
Definition: axis.cpp:95
Definition: common.h:36
string_value(I begin, I end)
Definition: global.h:177
Definition: cweave.c:262
rat_value(const rat_value &v)
Definition: global.h:166
~rat_value()
Definition: global.h:161
Definition: parse_types.h:156
~rational_vector_value()
Definition: global.h:250
std::string val
Definition: global.h:173
void sizeof_ratvec_wrapper(expression_base::level l)
Definition: global.cpp:2270
level
Definition: axis-types.h:188
std::shared_ptr< shared_value > shared_share
Definition: global.h:22
shared_share val
Definition: global.h:24
void install_function(wrapper_function f, const char *name, const char *type_string)
Definition: global.cpp:2246
bool val
Definition: global.h:191
std::shared_ptr< const value_base > shared_value
Definition: axis-types.h:130
id_data(shared_share &&val, type_expr &&t, bool is_const)
Definition: global.h:26
matrix_value(const int_Matrix &v)
Definition: global.h:224
Definition: global.h:190
std::shared_ptr< const function_base > shared_function
Definition: global.h:80
Vertex v
Definition: graph.cpp:116
~int_value()
Definition: global.h:146
map_type table
Definition: global.h:126