Beispiel #1
0
int Assignement::execute(Env* e, Store* s) {
	Val v = eval(s,e);
	
	if(v.getType() == EMPTY) {
		return 1;
	}
	return 0;
}
Beispiel #2
0
Val Call::eval(Store* s, Env* e) {
	function::Function *f = NULL; 
	NFunction *nf = NULL; 
	Val v = e->get(this->name);
	if(VERBOSE)
		cout << "call => " << name << endl;
		
	if(v.getType() == FUNCTION) {
		if(v.to_function()->getType() == NATIVE_FUNCTION) {
			nf = dynamic_cast<NFunction*>(v.to_function());
		}
		else {
			f = dynamic_cast<function::Function*>(v.to_function());
		}
	}
	else {		
		f = ::getProgFunction(name);
		nf = ::getNativeFunction(name);
	}
	
	
	
	if(f != NULL) {
		Env *ne = new Env(f->getNbVar());
		if(argument.size() != f->getArity()) {
			cout << "wrong arity during calling " << name << ", expected " << f->getArity() << ", " <<  argument.size() << " given " << endl;
			exit(1);
		}
		for(unsigned int i = 0; i < argument.size(); i++) {			
			ne->set(i, argument[i]->eval(s,e), f->getVarName(i));			
		}
		f->execute(ne, s);
		Val v = ne->get(f->getNbVar()); 
		delete ne;
		return v;		
	}
	if(nf != NULL) {
		return nf->eval(s,e,argument, this->line(), this->file());
	}
	cout << "undefined symbol "  << name << endl;
	return Val();
}
Beispiel #3
0
				inline static auto is(const Val& mV) noexcept
				{
					return mV.getType() == Val::Type::Arr && mV.getArr().size() == TS && TplIsHelper::areArrItemsOfType<TItem>(mV);
				}
Beispiel #4
0
				inline static auto is(const Val& mV) noexcept
				{
					return mV.getType() == Val::Type::Arr && mV.getArr().size() == sizeof...(TArgs) && TplIsHelper::isTpl<0, TArgs...>(mV);
				}
Beispiel #5
0
				inline static auto is(const Val& mV) noexcept { return mV.getType() == Val::Type::Arr && mV.getArr().size() == 2 && mV[0].isNoNum<T1>() && mV[1].isNoNum<T2>(); }
Beispiel #6
0
				inline static auto is(const Val& mV) noexcept { return mV.getType() == Val::Type::Str; }
Beispiel #7
0
				inline static auto is(const Val& mV) noexcept { return mV.getType() == Val::Type::Str && mV.getStr().size() == TS; }