Ejemplo n.º 1
0
Archivo: eval.cpp Proyecto: hyln9/nV
bool SearchSubValues(var &result, var head, var body)
{
	std::map<Var,def_t>::const_iterator
		iter = SubValues.find(Head(head));
	if(iter != SubValues.end())
	{
		const def_t &definitions = iter->second;
		if (definitions.is_vec()) {
			def_t::vec_t::const_iterator
				iter2 = definitions.vec->begin();
			var t = Vec(Body(head),body);
			while(iter2 != definitions.vec->end())
			{
				map_t m;
				if(MatchQ(m,iter2->second.first,t))
				{
					result = Eval(Subs(m,iter2->second.second));
					return true;
				}
				++iter2;
			}
		} else {
			def_t::map_t::const_iterator
				iter2 = definitions.map->begin();
			var t = Vec(Body(head),body);
			while(iter2 != definitions.map->end())
			{
				map_t m;
				if(MatchQ(m,iter2->second.first,t))
				{
					result = Eval(Subs(m,iter2->second.second));
					return true;
				}
				++iter2;
			}
		}
		
	}
	return false;
}
Ejemplo n.º 2
0
Archivo: query.hpp Proyecto: Yurry/espp
MatchQ operator==(const Field<T> &field, T &&val)
{
    return MatchQ(field, std::move(val));
}
Ejemplo n.º 3
0
Archivo: eval.cpp Proyecto: hyln9/nV
bool SearchDownValues(var &result, var head, var body)
{
	std::map<Var,def_t>::const_iterator
		iter = DownValues.find(head);
	if(iter != DownValues.end())
	{
		const def_t &definitions = iter->second;
		if (Verbose >= 2) {
			wcerr << _W("Search downvalue for ");
			Println(Ex(head, body), wcerr);
		}
		if (definitions.is_vec()) {
			def_t::vec_t::const_iterator
				iter2 = definitions.vec->begin();
			while(iter2 != definitions.vec->end())
			{
				if (Verbose >= 2) {
					wcerr << _W("# Try ");
					Print(iter2->first);
					wcerr << _W(" :> ");
					Print(iter2->second.second);
					wcerr << std::endl;
				}
				map_t m;
				if(MatchQ(m,iter2->second.first,body))
				{
					if (TraceRuleSymbols.count(head) != 0)
					{
						// FIXME: rewrite this after we implement the kernel message infrastructure
						Print(head);
						wcout << _W("::tracer : ");
						Print(Ex(head, body));
						wcout << _W(" :> ");
						Print(iter2->second.second);
						wcout << "\n";
					}
					result = Eval(Subs(m,iter2->second.second));
					if (ExQ(result, TAG(Condition))) {
						++iter2;
						continue;
					}
					if (Verbose >= 2) {
						wcerr << _W("Result is ");
						Println(result, wcerr);
					}
					return true;
				}
				++iter2;
			}
		} else {
			def_t::map_t::const_iterator
				iter2 = definitions.map->begin();
			if (Verbose >= 2) {
				wcerr << _W("Search downvalue for ");
				Println(Ex(head, body), wcerr);
			}
			while(iter2 != definitions.map->end())
			{
				if (Verbose >= 2) {
					wcerr << _W("# Try ");
					Print(iter2->first);
					wcout << _W(" :> ");
					Print(iter2->second.second);
					wcout << std::endl;
				}
				map_t m;
				if(MatchQ(m,iter2->second.first,body))
				{
					if (TraceRuleSymbols.count(head) != 0)
					{
						// FIXME: rewrite this after we implement the kernel message infrastructure
						Print(head);
						wcout << _W("::tracer : ");
						Print(Ex(head, body));
						wcout << _W(" :> ");
						Print(iter2->second.second);
						wcout << "\n";
					}
					result = Eval(Subs(m,iter2->second.second));
					if (ExQ(result, TAG(Condition))) {
						++iter2;
						continue;
					}
					if (Verbose >= 2) {
						wcerr << _W("Result is ");
						Println(result, wcerr);
					}
					return true;
				}
				++iter2;
			}
		}
	}
	return false;
}