#include <base_evaluator.hpp>
Definition at line 22 of file base_evaluator.hpp.
base_evaluator_rep | ( | ) | [inline] |
Definition at line 59 of file base_evaluator.hpp.
00059 : 00060 env (global_environment ()) {} inline base_evaluator_rep::base_evaluator_rep (const evaluator& ev):
base_evaluator_rep | ( | const evaluator & | ev | ) | [inline] |
Definition at line 61 of file base_evaluator.hpp.
00061 : 00062 env (local_environment (get_environment (ev))) {}
Reimplemented from evaluator_rep.
Definition at line 346 of file base_evaluator.cpp.
References base_evaluator_rep::apply(), base_evaluator_rep::eval(), mmx::gen(), mmx::GEN_TRANSTYPE, mmx::is_tuple_type(), mmx::N(), and mmx::type().
00347 { 00348 if (fun == GEN_TRANSTYPE) return eval (gen (fun, v)); 00349 generic the_fun; 00350 if (!env->get (fun, the_fun)) { 00351 for (nat i=0; i<N(v); i++) 00352 if (is_tuple_type (type (v[i])) || is<iterator<generic> > (v[i])) 00353 return equalize (fun, v); 00354 return gen (fun, v); 00355 } 00356 return as<routine> (the_fun)->apply (v); 00357 }
Reimplemented from evaluator_rep.
Definition at line 332 of file base_evaluator.cpp.
References base_evaluator_rep::apply(), base_evaluator_rep::eval(), mmx::gen(), and mmx::GEN_TRANSTYPE.
00334 { 00335 if (fun == GEN_TRANSTYPE) return eval (gen (fun, x1, x2)); 00336 generic the_fun; 00337 if (!env->get (fun, the_fun)) { 00338 if (is_grouped (x1) || is_grouped (x2)) 00339 return equalize (fun, vec<generic> (x1, x2)); 00340 return gen (fun, x1, x2); 00341 } 00342 return as<routine> (the_fun)->apply (x1, x2); 00343 }
Reimplemented from evaluator_rep.
Definition at line 309 of file base_evaluator.cpp.
References base_evaluator_rep::apply(), and mmx::gen().
00309 { 00310 generic the_fun; 00311 if (!env->get (fun, the_fun)) { 00312 if (is_grouped (x1)) 00313 return equalize (fun, vec<generic> (x1)); 00314 return gen (fun, x1); 00315 } 00316 /* 00317 static bool busy_flag= false; 00318 if (!busy_flag) { 00319 busy_flag= true; 00320 mmerr << "Apply " << flatten_as_lisp (the_fun) << ", "; 00321 mmerr << flatten_as_lisp (x1) << ": "; 00322 mmerr << flatten_as_lisp (type_name (x1)) << "\n"; 00323 busy_flag= false; 00324 } 00325 else 00326 mmerr << "[" << flatten_as_lisp (the_fun) << "]" << flush_now; 00327 */ 00328 return as<routine> (the_fun)->apply (x1); 00329 }
Reimplemented from evaluator_rep.
Definition at line 302 of file base_evaluator.cpp.
References mmx::gen().
Referenced by base_evaluator_rep::apply(), base_evaluator_rep::construct(), and base_evaluator_rep::eval().
Reimplemented from evaluator_rep.
Definition at line 294 of file base_evaluator.cpp.
References base_evaluator_rep::apply(), and mmx::type().
Referenced by base_evaluator_rep::eval().
Reimplemented from evaluator_rep.
Definition at line 156 of file base_evaluator.cpp.
00156 { 00157 return env->contains (var); 00158 }
Reimplemented from evaluator_rep.
Definition at line 175 of file base_evaluator.cpp.
References mmx::append(), base_evaluator_rep::apply(), mmx::as(), mmx::compound_to_vector(), mmx::cons(), base_evaluator_rep::construct(), ERROR, base_evaluator_rep::eval_cdr(), mmx::gen(), mmx::GEN_APPLY, mmx::GEN_METHOD, mmx::GEN_THIS, mmx::get_alias(), mmx::is(), mmx::literal_to_string(), mmx::N(), n, mmx::range(), and mmx::vec().
Referenced by base_evaluator_rep::apply(), and base_evaluator_rep::eval_cdr().
00175 { 00176 #ifdef BASIX_ENABLE_EXCEPTIONS 00177 try { 00178 #endif 00179 if (is<literal> (x)) { 00180 generic r; 00181 if (env->get (x, r)) return r; 00182 if (env->contains (gen (GEN_METHOD, x))) { 00183 generic sym ("." * literal_to_string (x)); 00184 return eval (gen (sym, generic (GEN_THIS))); 00185 } 00186 if (x == GEN_THIS) ERROR ("not inside method"); 00187 return x; 00188 } 00189 else if (is<compound> (x)) { 00190 const vector<generic> v= compound_to_vector (x); 00191 nat n= N(v); 00192 //mmerr << "Evaluate "; 00193 //if (n>0) mmerr << as_lisp (x); 00194 //mmerr << " at " << ((void*) inside (x)) << "\n"; 00195 //if (n>0 && is<literal> (v[0])) 00196 // mmerr << "Evaluate " << n << ", " << as_lisp (x) << "\n"; 00197 switch (n) { 00198 case 0: 00199 return x; 00200 case 1: 00201 { 00202 generic fun= eval (v[0]); 00203 if (is<primitive> (fun)) 00204 return as<primitive> (fun) -> apply (x); 00205 else if (is<routine> (fun)) 00206 return as<routine> (fun) -> apply (); 00207 else if (is<alias<routine> > (fun)) 00208 return get_alias (as<alias<routine> > (fun)) -> apply (); 00209 else return apply (GEN_APPLY, fun); 00210 } 00211 case 2: 00212 { 00213 generic fun= eval (v[0]); 00214 if (is<primitive> (fun)) 00215 return as<primitive> (fun) -> apply (x); 00216 else { 00217 generic a1= eval (v[1]); 00218 //mmerr << "Argument 1 at " << ((void*) inside (a1)) << "\n"; 00219 if (is<exception> (a1)) return a1; 00220 if (is<routine> (fun)) 00221 return as<routine> (fun) -> apply (a1); 00222 else if (is<alias<routine> > (fun)) 00223 return get_alias (as<alias<routine> > (fun)) -> apply (a1); 00224 else return apply (GEN_APPLY, fun, a1); 00225 } 00226 } 00227 case 3: 00228 { 00229 generic fun= eval (v[0]); 00230 if (is<primitive> (fun)) 00231 return as<primitive> (fun) -> apply (x); 00232 else { 00233 generic a1= eval (v[1]); 00234 if (is<exception> (a1)) return a1; 00235 generic a2= eval (v[2]); 00236 if (is<exception> (a2)) return a2; 00237 if (is<routine> (fun)) 00238 return as<routine> (fun) -> apply (a1, a2); 00239 else if (is<alias<routine> > (fun)) 00240 return get_alias (as<alias<routine> > (fun)) -> apply (a1, a2); 00241 else return apply (GEN_APPLY, vec (fun, a1, a2)); 00242 } 00243 } 00244 default: 00245 { 00246 generic fun= eval (v[0]); 00247 if (is<primitive> (fun)) 00248 return as<primitive> (fun) -> apply (x); 00249 else { 00250 vector<generic> args= eval_cdr (v); 00251 if (N(args)>0 && is<exception> (args[N(args)-1])) 00252 return args[N(args)-1]; 00253 if (is<routine> (fun)) 00254 return as<routine> (fun) -> apply (args); 00255 else if (is<alias<routine> > (fun)) 00256 return get_alias (as<alias<routine> > (fun)) -> apply (args); 00257 else return apply (GEN_APPLY, cons (fun, args)); 00258 } 00259 } 00260 } 00261 } 00262 else return construct (x); 00263 #ifdef BASIX_ENABLE_EXCEPTIONS 00264 } 00265 catch (const exception& err) { 00266 generic msg= *err; 00267 generic ret= append (range (msg, 0, N(msg)-1), gen (x)); 00268 return as<generic> (exception (ret)); 00269 } 00270 #endif 00271 }
Definition at line 274 of file base_evaluator.cpp.
References base_evaluator_rep::eval(), mmx::N(), n, and mmx::range().
Referenced by base_evaluator_rep::eval().
Reimplemented from evaluator_rep.
Definition at line 166 of file base_evaluator.cpp.
00166 { 00167 return env->get (var, val); 00168 }
Reimplemented from evaluator_rep.
Definition at line 161 of file base_evaluator.cpp.
00161 { 00162 return env [var]; 00163 }
void * get_internal_data | ( | ) | const [virtual] |
Reimplemented from evaluator_rep.
Definition at line 40 of file base_evaluator.cpp.
References base_evaluator_rep::env.
00040 { 00041 return (void*) &env; 00042 }
Reimplemented from evaluator_rep.
Definition at line 77 of file base_evaluator.cpp.
References ASSERT, base_evaluator_rep::env, mmx::exact_eq(), mmx::GEN_CONVERT, mmx::GEN_DOWNGRADE, mmx::GEN_NEW, mmx::GEN_REWRITE, mmx::GEN_UPGRADE, mmx::inside(), mmx::make_abstract(), mmx::N(), and mmx::read().
00079 { 00080 /* 00081 mmout << "Overload "; 00082 mmout << as_lisp (var); 00083 if (is<routine> (val)) { 00084 routine f= as<routine> (val); 00085 vector<nat> ids= f->signature (); 00086 extern generic type_name (nat id); 00087 mmout << ": "; 00088 for (nat i=1; i<N(ids); i++) { 00089 if (i!=1) mmout << ", "; 00090 mmout << as_lisp (type_name (ids[i])); 00091 } 00092 mmout << " -> " << as_lisp (type_name (ids[0])); 00093 } 00094 mmout << "\n"; 00095 */ 00096 00097 base_evaluator_rep* me= const_cast<base_evaluator_rep*> (this); 00098 if (is<routine> (val)) { 00099 routine f= as<routine> (val); 00100 if (f->is_overloaded ()) { 00101 vector<routine> rs= f->meanings (); 00102 for (nat i=0; i<N(rs); i++) 00103 overload (var, as<generic> (rs[i]), pen); 00104 return; 00105 } 00106 if (exact_eq (var, GEN_NEW)) { 00107 const vector<nat> ids= f->signature (); 00108 ASSERT (N(ids) == 2, "constructor should take one argument"); 00109 me->env [as<generic> (ids[1])]= val; 00110 } 00111 else if (exact_eq (var, GEN_CONVERT) || exact_eq (var, GEN_UPGRADE) || 00112 exact_eq (var, GEN_DOWNGRADE) || exact_eq (var, GEN_REWRITE)) 00113 { 00114 const vector<nat> ids= f->signature (); 00115 ASSERT (N(ids) == 2, "converter should take one argument"); 00116 nat src = ids[1], dest= ids[0]; 00117 if (src == dest) return; 00118 nat trv= 0; 00119 if (exact_eq (var, GEN_DOWNGRADE) || exact_eq (var, GEN_REWRITE)) 00120 trv += 2; 00121 if (exact_eq (var, GEN_UPGRADE) || exact_eq (var, GEN_REWRITE)) 00122 trv += 1; 00123 inside (env) -> set_converter (src, dest, val, trv, pen); 00124 //mmout << "Converter: " << src << ", " << dest << ", " << val << "\n"; 00125 //mmout << "Environment: " << env << "\n"; 00126 } 00127 /* 00128 else if (N(f->signature ()) == 0) 00129 me->env [var]= val; 00130 */ 00131 else { 00132 if (!env->contains (var) || 00133 !is<routine> (env[var]) || 00134 N(f->signature ()) == 0) 00135 me->env [var]= make_abstract (overloaded_routine (var, env)); 00136 routine r= as<routine> (read (me->env, var)); 00137 if (r->ref_count != 2) { 00138 /* 00139 mmout << "Cloning " << as_lisp (var) << " = "; 00140 mmout << as_lisp (r -> function_body ()) << "\n"; 00141 mmout << "Done\n"; 00142 */ 00143 r= r->clone (); 00144 me->env [var]= as<generic> (r); 00145 //mmout << "ref_count= " << r->ref_count << "\n"; 00146 } 00147 //mmout << "Overloading\n"; 00148 r->overload (f); 00149 //mmout << "Overloaded\n"; 00150 } 00151 } 00152 else me->env [var]= val; 00153 }
void reset | ( | const generic & | var | ) | const [virtual] |
Reimplemented from evaluator_rep.
Definition at line 71 of file base_evaluator.cpp.
References base_evaluator_rep::env.
00071 { 00072 base_evaluator_rep* me= const_cast<base_evaluator_rep*> (this); 00073 mmx::reset (me->env, var); 00074 }
Reimplemented from evaluator_rep.
Definition at line 65 of file base_evaluator.cpp.
References base_evaluator_rep::env.
00065 { 00066 base_evaluator_rep* me= const_cast<base_evaluator_rep*> (this); 00067 me->env [var]= val; 00068 }
environment env [protected] |
Definition at line 24 of file base_evaluator.hpp.
Referenced by base_evaluator_rep::get_internal_data(), base_evaluator_rep::overload(), base_evaluator_rep::reset(), and base_evaluator_rep::set().