Пример #1
0
/** \brief Load all the initial dictionary words.
 */
void
init_dictionary(int dictsize) {
    init_compiler(dictsize);
    memory_words();

    compile_primitives();
    compile_core_constants();
    core_words();
    core_extension_words();
    compile_dictionary_words();
    controlflow_words();
    more_core_words();

    compile_double();
    string_words();
    exception_words();
    file_words();
    format_words();
    compile_stack_words();

    implementation_words();
    vocabulary_words();
    interpreter_words();

    platform_words();
    /* FIX - NEED TO DO THESE */
//   Primitive( "d<",     &lesser );      /* ( d1 d2 -- f ) */
//   Primitive( "d>",     &lesser );      /* ( d1 d2 -- f ) */

//   Primitive( "u*",      &um_star );   /* ( x y -- x*y ) */
//   Primitive( "du*",     &um_star );   /* ( x y -- x*y ) */
//   Primitive( "du/mod",  &um_star );   /* ( x y -- x*y ) */
//   Primitive( "du<",     &um_star );   /* ( x y -- x*y ) */

//   Primitive( "m+",      &um_star );   /* ( x y -- x*y ) */
//   Primitive( "m-",      &um_star );   /* ( x y -- x*y ) */
//   Primitive( "m*",      &um_star );   /* ( x y -- x*y ) */
//   Primitive( "m*/",     &um_star );   /* ( x y -- x*y ) */
//   Primitive( "m/",      &um_star );   /* ( x y -- x*y ) */
//   Primitive( "m/mod",   &um_star );   /* ( x y -- x*y ) */
    /* FIX - NEED TO DO THESE */

    /* FIX  - these two words are no longer used - why are they here ?? */
//   Primitive( "um*",  &um_star );   /* ( x y -- x*y ) */
//   Colon( "udm*" );  /* ( d.lo d.hi n -- d.lo' d.hi' ) */
//          c("tuck"); c("um*"); c("drop"); c("-rot"); c("um*");
//          c("rot"); c("+"); End();

    Colon( ".version" );
    DotQuote("Portable ANS Forth - [email protected]");
    c("cr");
    End();

    Colon( "rstrace" );
    DotQuote("( R: ");
    c("rp@");
    c("rp0");
    c("@");
    Do();
    c("i");
    c(".");
    c("space");
    c("/cell");
    PlusLoop();
    DotQuote(" )");
    c("cr");
    End();

    Variable( "argument-hook" );
    /* To( Tick("ndrop"), "argument-hook" ); */
    ACF x = find("unnest");
    To( (Cell)x, "argument-hook" );

    Colon( "cold" );
    c(".version");
    c("cold-chain");
    /* included may be replaced with path-included which reads
       FORTH_PATH environment variable to look in selected
       directories */
    c("debug");
    c("@");
    If();
    DotQuote("Loading Forth files...");
    Then();
    /* StringLiteral("base.fth"); c("included"); */
    DotQuote("loading base.fth");
    c("cr");
    StringLiteral("base.fth");
    Tick("included");
    c("catch");
    c("?aborted");
    If();
    DotQuote("Failed to load.");
    c("cr");
    Then();

    c("debug");
    c("@");
    If();
    DotQuote("done.");
    c("cr");
    Then();
    c("hex");
#if 0
    c("argument-hook");
    c("@");
    Tick("execute");
    c("catch");
    c("?aborted");
    If();
    DotQuote("argument-hook failed");
    c("cr");
    Then();
#endif
    c("read-eval-loop");
    End();

    Colon( "warm" );
    DotQuote( "Warm Started." );
    c("cr");
    c("rstrace");
    c("quit");
    End();

    /* header */
    Colon( "name," );
    c("dup");
    c("1+");
    c("talign");
    c("allot");
    c("dup");
    c("here");
    c("1-");
    c("c!");
    c("here");
    c("1-");
    c("over");
    c("-");
    c("swap");
    c("cmove");
    End();

    Colon( "header" );
    c("name,");
    c("link");
    c("do-create");
    c(",");
    End();
    Colon( "create" );
    c("parse-word");
    c("header");
    End();

    Colon( "codefield" );  /* ( codefield -- ) */
    c("lastacf");
    c("!");
    End();

    Colon( ":" );
    c("create");
    c("hide");
    c("do-colon");
    c("codefield");
    c("]");
    End();
    Colon( ";" );
    c("compile");
    c("unnest");
    c("[");
    c("reveal");
    End();
    immediate();
}
double define_var(string s, double d){
        if(is_declared(s)) error("declared twice");
        names.push_back(Variable(s,d));
        return d;
}
Пример #3
0
Variable ParserScope::doGetField(const Variant &key, bool /*modifiable*/, bool /*createIfNeeded*/)
{
    if (key.type() == Variant::stringType) {
        auto it = reserved.find(key.toString());
        if (it != reserved.end()) {
            const auto id = it->second;
            switch (id) {
                case A_PEEK:
                return collector().lambda(
                    [this](const VariableArgs& args, const VariableKeywordArgs&) ->Variable {
                    if (parser() && args.size() >= 1) {
                        Variant typeArg = args[0].value();

                        if (typeArg.type() == Variant::objectType) {
                            std::streamoff offset = args.size() > 1 ? args[1].value().toInteger() : 0;
                            const ObjectType& type = typeArg.toObjectType();
                            std::unique_ptr<Object> child(parser()->readVariable(type, offset));
                            if (child) {
                                return collector().copy(child->value());
                            }
                        }
                    }
                    return Variable();
                }, memory());

                case A_READ:
                return collector().lambda(
                    [this](const VariableArgs& args, const VariableKeywordArgs&) ->Variable {
                    if (parser()) {
                        Variant typeArg = args[0].value();
                        if (typeArg.type() == Variant::objectType) {
                            const ObjectType& type = typeArg.toObjectType();
                            std::unique_ptr<Object> child(parser()->readVariable(type));
                            if (child) {
                                parser()->object().setPos(parser()->object().pos()+child->size());
                                return collector().copy(child->value());
                            }
                        }
                    }
                    return Variable();
                }, memory());

                case A_FIND_BYTE_PATTERN:
                return collector().lambda(
                    [this](const VariableArgs& args, const VariableKeywordArgs&) ->Variable {
                        if (args.size() < 1) {
                            return Variable();
                        }
                        const Variant& value = args[0].value();
                        if (value.type() != Variant::stringType) {
                            return Variable();
                        }
                        if (parser()) {
                            return collector().copy(parser()->findBytePattern(value.toString()));
                        }

                        return Variable();
                    }
                );
            }
        }
    }
    return Variable();
}
Пример #4
0
CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION
AD<Base> CondExpOp(
	enum  CompareOp cop       ,
	const AD<Base> &left      ,
	const AD<Base> &right     ,
	const AD<Base> &if_true   ,
	const AD<Base> &if_false  )
{
	AD<Base> returnValue;
	CPPAD_ASSERT_UNKNOWN( Parameter(returnValue) );

	// check first case where do not need to tape
	if( IdenticalPar(left) & IdenticalPar(right) )
	{	switch( cop )
		{
			case CompareLt:
			if( left.value_ < right.value_ )
				returnValue = if_true;
			else	returnValue = if_false;
			break;

			case CompareLe:
			if( left.value_ <= right.value_ )
				returnValue = if_true;
			else	returnValue = if_false;
			break;

			case CompareEq:
			if( left.value_ == right.value_ )
				returnValue = if_true;
			else	returnValue = if_false;
			break;

			case CompareGe:
			if( left.value_ >= right.value_ )
				returnValue = if_true;
			else	returnValue = if_false;
			break;

			case CompareGt:
			if( left.value_ > right.value_ )
				returnValue = if_true;
			else	returnValue = if_false;
			break;

			default:
			CPPAD_ASSERT_UNKNOWN(0);
			returnValue = if_true;
		}
		return returnValue;
	}

	// must use CondExp incase Base is an AD type and recording
	returnValue.value_ = CondExpOp(cop,
		left.value_, right.value_, if_true.value_, if_false.value_);

	ADTape<Base> *tape = CPPAD_NULL;
	if( Variable(left) )
		tape = left.tape_this();
	if( Variable(right) )
		tape = right.tape_this();
	if( Variable(if_true) )
		tape = if_true.tape_this();
	if( Variable(if_false) )
		tape = if_false.tape_this();

	// add this operation to the tape
	if( tape != CPPAD_NULL )
		tape->RecordCondExp(cop,
			returnValue, left, right, if_true, if_false);

	return returnValue;
}
Пример #5
0
// (var, val, c)をvar_tableに追加する
double Symbol_table::define_name(string var, double val, bool c){
	if(is_declared(var)) error(var, " declared twice");
	var_table.push_back(Variable(var, val, c));
}
Пример #6
0
NNC_Polyhedron Model::edge_cvx(const EDGE &edge, const NNC_Polyhedron &pre_poly) {
  
    int num_p = param_list.params.size();
    int num_v = var_list.vars.size();
    //int dim = 2*num_v + num_p + 1;
  
    const EDGE *it = &edge;
    NNC_Polyhedron cvx = pre_poly;
    string dest = it->dest;
  
    vector<Variable> Vars;
    int total = 0;
    for ( int i = 0; i < num_p; i++)
	Vars.push_back(Variable(total++));
    for ( int i = 0; i < num_v; i++)
	Vars.push_back(Variable(total++));
  
    // guard
    for ( vector<EXPR>::const_iterator iit = it->guard.begin(); iit != it->guard.end(); iit++) {
	Linear_Expression le;
	for ( int i = 0; i < num_p; i++) {
	    le += Vars[i] * iit->find(param_list.params[i].name);
	}
	for ( unsigned i = 0; i < known_param_list.params.size(); i++) {
	    le += atof (known_param_list.params[i].value.c_str()) * 
		iit->find(known_param_list.params[i].name);
	}
	for ( int i = 0; i < num_v; i++) {
	    le += Vars[num_p + i] * iit->find(var_list.vars[i]);
	}
    
	int right = atof(iit->value.c_str());
	Constraint cs;
	if ( iit->op == "<") cs = ( le < right);
	if ( iit->op == "=") cs = ( le == right);
	if ( iit->op == "<=") cs = ( le <= right);
	if ( iit->op == ">") cs = ( le > right);
	if ( iit->op == ">=") cs = ( le >= right);
	cvx.add_constraint(cs);
  
    }
  
    // guard => updates
    for ( int i = 0; i < num_v; i++)
	Vars.push_back(Variable(total++));

    for ( int i = 0; i < num_v; i++) {

	int i2 = total - num_v + i;
	int i1 = num_p + i;
	bool u_flag = false;
	UPDATE update;

	for ( vector<UPDATE>::const_iterator uit = it->updates.begin(); 
	      uit != it->updates.end(); uit++) {
	    if (var_list.vars[i] == uit->left) {
		u_flag = true;
		update = *uit;
		break;
	    }
	}

	Constraint cs;	
	if (!u_flag) {
	    cs = (Vars[i2] == Vars[i1]);
	    cvx.add_constraint(cs);
	    continue;
	}

	Linear_Expression le;
	for ( int j = 0; j < num_p; j++) {
	    le += Vars[j] * update.find(param_list.params[j].name);
	}
	for ( unsigned j = 0; j < known_param_list.params.size(); j++) {
	    le += atof (known_param_list.params[j].value.c_str()) * 
		update.find(known_param_list.params[j].name);
	}
	for ( int j = 0; j < num_v; j++) {
	    le += Vars[num_p + j] * update.find(var_list.vars[j]);
	}
	le += update.get_cons();

	cs = (Vars[i2] == le);
	cvx.add_constraint(cs);

    }
  
    // guard => assign => reduce 
    Variables_Set vs;
    for ( int i = total - 2*num_v; i < total - num_v; i++) {
	vs.insert(Vars[i]);
    }
    cvx.remove_space_dimensions(vs);
    cvx.add_space_dimensions_and_embed(num_v);
    //total -= (num_v);
    //Vars.clear();
    //for ( int i = 0; i < total; i++)
    //  Vars.push_back(Variable(i));

    return cvx;

}
Пример #7
0
VariableExpression::VariableExpression( text::attributes::SpeechPart sp, uint index ) :
	variable( Variable( sp, index ) ) {
}
Пример #8
0
void Shader::SetSampler(const String& name, UINT index, ID3D11SamplerState* sampler)
{
	Variable(name)->AsSampler()->SetSampler(index, sampler);
}
Пример #9
0
void Shader::SetShaderResource(const String& name, ID3D11ShaderResourceView* shaderResource)
{
	Variable(name)->AsShaderResource()->SetResource(shaderResource);
}
Пример #10
0
void Shader::SetMatrix(const String& name, const Matrix& matrix)
{
	Variable(name)->AsMatrix()->SetMatrix(matrix);
}
Пример #11
0
void Shader::SetVector(const String& name, const Vector4& vector)
{
	Variable(name)->AsVector()->SetFloatVector(vector);
}
Пример #12
0
arithmtype Function(void)
{
	char tcFonc[ 20 ], *pFonc;
	int Res = 0;

	/* which function ? */
	pFonc = tcFonc;
	while((unsigned int)(pFonc-tcFonc)<sizeof(tcFonc)-1 && *Expr>='A' && *Expr<='Z')
	{
		*pFonc++ = *Expr;
		Expr++;
	}
	*pFonc = '\0';

	/* functions with one parameter = variable */
	if ( !strcmp(tcFonc, "ABS") )
	{
		Expr++; /* ( */
		Res = Variable( );
		if ( Res<0 )
			Res = Res * -1;
		Expr++; /* ) */
		return Res;
	}

	/* functions with many parameters = many variables separated per ',' */
	if ( !strcmp(tcFonc, "MINI") )
	{
		Res = 0x7FFFFFFF;
		do
		{
			int iValVar;
			Expr++; /* ( -ou- , */
			iValVar = Variable( );
			if ( iValVar<Res )
				Res = iValVar;
		}
		while( *Expr!=')' );
		Expr++; /* ) */
		return Res;
	}
	if ( !strcmp(tcFonc, "MAXI") )
	{
		Res = 0x80000000;
		do
		{
			int iValVar;
			Expr++; /* ( -or- , */
			iValVar = Variable( );
			if ( iValVar>Res )
				Res = iValVar;
		}
		while( *Expr!=')' );
		Expr++; /* ) */
		return Res;
	}
	if ( !strcmp(tcFonc, "MOY") /*original french term!*/ || !strcmp(tcFonc, "AVG") /*added latter!!!*/ )
	{
		int NbrVars = 0;
		do
		{
			int ValVar;
			Expr++; /* ( -or- , */
			ValVar = Variable( );
			NbrVars++;
			Res = Res + ValVar;
		}
		while( *Expr!=')' );
		Expr++; /* ) */
		Res = Res/NbrVars;
		return Res;
	}

	/* functions with parameter = term */
//	int iValeurTerm = Term();
//	if ( !strcmp(tcFonc, "") )
//	{
//	}


	ErrorDesc = "Unknown function";
	SyntaxError();

	return 0;
}
Пример #13
0
AD<Base> operator - (const AD<Base> &left , const AD<Base> &right)
{	ADTape<Base> *tape = AD<Base>::tape_ptr();
	bool var_left, var_right;
# ifdef NDEBUG
	if( tape == CPPAD_NULL )
	{	var_left =  false;
		var_right = false;
	}
	else
	{
		var_left  = left.id_  == tape->id_;
		var_right = right.id_ == tape->id_;
	}
# else
	var_left  = Variable(left);
	var_right = Variable(right);
	CPPAD_ASSERT_KNOWN(
		(! var_left) || left.id_ == tape->id_ ,
		"- left operand is a variable for a different thread"
	);
	CPPAD_ASSERT_KNOWN(
		(! var_right) || right.id_ == tape->id_ ,
		"- right operand is a variable for a different thread"
	);
# endif

	AD<Base> result;
	result.value_  = left.value_ - right.value_;
	CPPAD_ASSERT_UNKNOWN( Parameter(result) );

	if( var_left )
	{	if( var_right )
		{	// result = variable - variable
			CPPAD_ASSERT_UNKNOWN( NumRes(SubvvOp) == 1 );
			CPPAD_ASSERT_UNKNOWN( NumArg(SubvvOp) == 2 );

			// put operand addresses in tape
			tape->Rec_.PutArg(left.taddr_, right.taddr_);
			// put operator in the tape
			result.taddr_ = tape->Rec_.PutOp(SubvvOp);
			// make result a variable
			result.id_ = tape->id_;
		}
		else if( IdenticalZero(right.value_) )
		{	// result = variable - 0
			result.make_variable(left.id_, left.taddr_);
		}
		else
		{	// result = variable - parameter
			CPPAD_ASSERT_UNKNOWN( NumRes(SubvpOp) == 1 );
			CPPAD_ASSERT_UNKNOWN( NumArg(SubvpOp) == 2 );

			// put operand addresses in tape
			size_t p = tape->Rec_.PutPar(right.value_);
			tape->Rec_.PutArg(left.taddr_, p);
			// put operator in the tape
			result.taddr_ = tape->Rec_.PutOp(SubvpOp);
			// make result a variable
			result.id_ = tape->id_;
		}
	}
	else if( var_right )
	{	// result = parameter - variable
		CPPAD_ASSERT_UNKNOWN( NumRes(SubpvOp) == 1 );
		CPPAD_ASSERT_UNKNOWN( NumArg(SubpvOp) == 2 );

		// put operand addresses in tape
		size_t p = tape->Rec_.PutPar(left.value_);
		tape->Rec_.PutArg(p, right.taddr_);
		// put operator in the tape
		result.taddr_ = tape->Rec_.PutOp(SubpvOp);
		// make result a variable
		result.id_ = tape->id_;
	}
	return result;
}
Пример #14
0
VariableArray::VariableArray(const size_t size, const ::std::string& name) : VariableArrayContents() {
    for (size_t i = 0; i < size; ++i) {
        push_back(Variable(GADGETLIB2_FMT("%s[%d]", name.c_str(), i)));
    }
}
Пример #15
0
void Model::update_cvx(const EDGE &edge, NNC_Polyhedron &cvx) {

  
    int dim = var_list.vars.size();
  
    const EDGE *it = &edge;
  
    vector<Variable> Vars;
    for ( int i = 0; i <= dim; i++)
	Vars.push_back(Variable(i));

    int p, c;
    Variables_Set vs;

    for ( int i = 0; i < dim; i++) {

	bool u_flag = false;
	UPDATE update;

	for ( vector<UPDATE>::const_iterator uit = it->updates.begin(); 
	      uit != it->updates.end(); uit++) {
	    if (var_list.vars[i] == uit->left) {
		u_flag = true;
		update = *uit;
		break;
	    }
	}

	if (!u_flag) {
	    continue;
	}

        if ( i < dim/2) {
          cvx.unconstrain(Vars[i]);
          Constraint cs1 = (Vars[i] == 0);
          cvx.add_constraint(cs1);
          i = dim/2 - 1;

          continue;
	}


        cvx.expand_space_dimension(Vars[i], 1);

        cvx.unconstrain(Vars[i]);

	Linear_Expression le;
	for ( unsigned j = 0; j < known_param_list.params.size(); j++) {
	    le += atof (known_param_list.params[j].value.c_str()) * 
		update.find(known_param_list.params[j].name);
	}
	for ( int j = dim; j <= dim; j++) {
	    le += Vars[j] * update.find(var_list.vars[i]);
	}
	le += update.get_cons();

	Constraint cs2 = (Vars[i] == le);
	cvx.add_constraint(cs2);


        cvx.remove_higher_space_dimensions(dim);
        return;

    }
  
}
Пример #16
0
void Shader::SetScalor(const String& name, float scalor)
{
	Variable(name)->AsScalar()->SetFloat(scalor);
}
Пример #17
0
NNC_Polyhedron Model::location_cvx(const Location *l, const NNC_Polyhedron *pre_cvx) {
  
    // a path leading to "target" is found
    if( l->is_bad && type != REACH) {

	if ( type == FAST_REACH) {
	    //cout << "The target location is reached\n";
	    //return NNC_Polyhedron(0, EMPTY);
	    //exit (0);
	    fast_reach = true;
	}
	else {
	    NNC_Polyhedron bad = *pre_cvx;
	    bad.remove_higher_space_dimensions(param_list.params.size());
	    //if (bad.is_empty()) 
	    //return NNC_Polyhedron(0, EMPTY);
	    restore_bad_paths(bad);
	    return NNC_Polyhedron(0, EMPTY);
	}

    }
  
    NNC_Polyhedron cvx (*pre_cvx);
    int num_p = param_list.params.size();
    int num_v = var_list.vars.size();
    //int dim = 2*num_v + num_p + 1;
  
    vector<Variable> Vars;
    int total = 0;
    for (int i = 0; i < num_p; i++)
	Vars.push_back(Variable(total++));
    for (int i = 0; i < num_v; i++)
	Vars.push_back(Variable(total++));

    // invariant
    for ( vector<EXPR>::const_iterator it = l->invar.begin(); it != l->invar.end(); it++) {
	Linear_Expression le;
	for ( int i = 0; i < num_p; i++) {
	    le += Vars[i] * it->find(param_list.params[i].name);
	}
	for ( unsigned i = 0; i < known_param_list.params.size(); i++) {
	    le += atof (known_param_list.params[i].value.c_str()) *
		it->find(known_param_list.params[i].name);
	}
	for ( int i = 0; i < num_v; i++) {
	    le += Vars[num_p + i] * it->find(var_list.vars[i]);
	}
    
	int right = atof(it->value.c_str());
    
	Constraint cs;
	if ( it->op == "<") cs = ( le < right);
	if ( it->op == "=") cs = ( le == right);
	if ( it->op == "<=") cs = ( le <= right);
	if ( it->op == ">") cs = ( le > right);
	if ( it->op == ">=") cs = ( le >= right);
	cvx.add_constraint(cs);
    }
  
    // invar => time elapse
    Vars.push_back(Variable(total++));
    Constraint cs = (Vars[total-1] >= 0);	
    cvx.add_constraint(cs);
  
    for ( int i = 0; i < num_v; i++)
	Vars.push_back(Variable(total++));
    for ( int i = 0; i < num_v; i++) {
	int i2 = total - num_v + i;
	int i1 = num_p + i;
	int i_co = l->rate.find(var_list.vars[i]);
    
	Constraint cs = (Vars[i1] + i_co * Vars[num_p + num_v] == Vars[i2]);
	cvx.add_constraint(cs);
    }
  
    // invar => time elapse => invar
    for ( vector<EXPR>::const_iterator it = l->invar.begin(); it != l->invar.end(); it++) {
	Linear_Expression le;
	for ( int i = 0; i < num_p; i++) {
	    le += Vars[i] * it->find(param_list.params[i].name);
	}
	for ( unsigned i = 0; i < known_param_list.params.size(); i++) {
	    le += atof (known_param_list.params[i].value.c_str()) * 
		it->find(known_param_list.params[i].name);
	}
	for ( int i = 0; i < num_v; i++) {
	    le += Vars[total - num_v + i] * it->find(var_list.vars[i]);
	}
    
	int right = atof(it->value.c_str());
	Constraint cs;
	if ( it->op == "<") cs = ( le < right);
	if ( it->op == "=") cs = ( le == right);
	if ( it->op == "<=") cs = ( le <= right);
	if ( it->op == ">") cs = ( le > right);
	if ( it->op == ">=") cs = ( le >= right);
	cvx.add_constraint(cs);

    }
  
    // invar => time elapse => invar => reduce
    Variables_Set vs;
    for ( int i = total - 2*num_v - 1; i < total - num_v; i++) {
	vs.insert(Vars[i]);
    }
    cvx.remove_space_dimensions(vs);
    cvx.add_space_dimensions_and_embed(num_v+1);
    //total -= (num_2v + 1);
    //Vars.clear();
    //for ( int i = 0; i < total; i++)
    //  Vars.push_back(Variable(i));

    return cvx;

}
Пример #18
0
void Shader::SetRenderTargett(const String& name, ID3D11RenderTargetView* renderTarget)
{
	Variable(name)->AsRenderTargetView()->SetRenderTarget(renderTarget);
}
Пример #19
0
bool Model::forward_release(const shared_ptr<pair_sc>& state, unsigned ti) {

  if (state->tk_new)  return false;

  Variable v(ti-1);

  NNC_Polyhedron poly = state->cvx;

  // current state contains p_i == T_i
  Constraint cs = ( v == atoi(known_param_list.params[3*(ti-1)].value.c_str()));
  poly.add_constraint(cs);
  if( ! poly.is_empty())
    return false;

  // ti arrived earlier

  shared_ptr<pair_sc> origin = state->prior;
  bool idle_flag = false;

  while( origin != nullptr) {
    if ( ! origin->valid) return true;

    if (busy_period(origin->signature)) {
      poly = origin->cvx;
      Constraint cs = ( v == atoi(known_param_list.params[3*(ti-1)].value.c_str()));
      poly.add_constraint(cs);
      if ( ! poly.is_empty())
        return true;

      if (origin->tk_new) 
        break;
        
    }
    else {
      poly = origin->cvx;
      Constraint cs = ( v == atoi(known_param_list.params[3*(ti-1)].value.c_str()));
      poly.add_constraint(cs);
      if ( ! poly.is_empty()) {
        if (idle_flag)  { 
          //cout << " release not in latest idle period\n"; 
          return true;
        }

        idle_flag = true;
        vector<Variable> vs;
        for ( int i = 1; i < N; i++) 
          if ( (origin->signature & (unsigned)pow(2, i-1)) ==0 && (state->signature & (unsigned)pow(2, i-1)) !=0)
                  vs.push_back(Variable(i-1));
        poly = state->cvx;
        for (int i = 0; i < vs.size(); i++) {
          cs = (vs[i]==0);
          poly.add_constraint(cs);
          if (poly.is_empty()){ 
            //cout << " release in latest idle period\n"; 
            return true;
          }
        }

      }
    }
      

    origin = origin->prior;
  }

  //ti arrived before tk
  vector<Variable> vs;
  for ( int i = 1; i < N; i++) 
    if ( (origin->prior->signature & (unsigned)pow(2, i-1)) ==0 && (state->signature & (unsigned)pow(2, i-1)) !=0)
            vs.push_back(Variable(i-1));
  poly = state->cvx;
  for (int i = 0; i < vs.size(); i++) {
    cs = (vs[i]==0);
    poly.add_constraint(cs);
    if (poly.is_empty()){ 
      //cout << " release before tk arrives\n"; 
      return true;
    }
  }

  return false;
}
Пример #20
0
void Shader::SetRasterizer(const String& name, UINT index, ID3D11RasterizerState* rasterizer)
{
	Variable(name)->AsRasterizer()->SetRasterizerState(index, rasterizer);
}
Пример #21
0
VariableExpression::VariableExpression( const Pattern & pt, uint index ) :
	variable( Variable( pt, index ) ) {
}
Пример #22
0
void Shader::SetDepthStencilView(const String& name, ID3D11DepthStencilView* depthStencilView)
{
	Variable(name)->AsDepthStencilView()->SetDepthStencil(depthStencilView);
}
Пример #23
0
void ADTape<Base>::RecordCondExp(
	enum CompareOp  cop         ,
	AD<Base>       &returnValue ,
	const AD<Base> &left        ,
	const AD<Base> &right       ,
	const AD<Base> &if_true     ,
	const AD<Base> &if_false    )
{	size_t   ind0, ind1, ind2, ind3, ind4, ind5;
	size_t   returnValue_taddr;

	// taddr_ of this variable
	CPPAD_ASSERT_UNKNOWN( NumRes(CExpOp) == 1 );
	returnValue_taddr = Rec_.PutOp(CExpOp);

	// ind[0] = cop
	ind0 = addr_t( cop );

	// ind[1] = base 2 representaion of the value
	// [Var(left), Var(right), Var(if_true), Var(if_false)]
	ind1 = 0;

	// Make sure returnValue is in the list of variables and set its taddr
	if( Parameter(returnValue) )
		returnValue.make_variable(id_, returnValue_taddr );
	else	returnValue.taddr_ = returnValue_taddr;

	// ind[2] = left address
	if( Parameter(left) )
		ind2 = Rec_.PutPar(left.value_);
	else
	{	ind1 += 1;
		ind2 = left.taddr_;
	}

	// ind[3] = right address
	if( Parameter(right) )
		ind3 = Rec_.PutPar(right.value_);
	else
	{	ind1 += 2;
		ind3 = right.taddr_;
	}

	// ind[4] = if_true address
	if( Parameter(if_true) )
		ind4 = Rec_.PutPar(if_true.value_);
	else
	{	ind1 += 4;
		ind4 = if_true.taddr_;
	}

	// ind[5] =  if_false address
	if( Parameter(if_false) )
		ind5 = Rec_.PutPar(if_false.value_);
	else
	{	ind1 += 8;
		ind5 = if_false.taddr_;
	}

	CPPAD_ASSERT_UNKNOWN( NumArg(CExpOp) == 6 );
	CPPAD_ASSERT_UNKNOWN( ind1 > 0 );
	Rec_.PutArg(ind0, ind1, ind2, ind3, ind4, ind5);

	// check that returnValue is a dependent variable
	CPPAD_ASSERT_UNKNOWN( Variable(returnValue) );
}
Пример #24
0
void Shader::SetDepthStencil(const String& name, UINT index, ID3D11DepthStencilState* depthStencil)
{
	Variable(name)->AsDepthStencil()->SetDepthStencilState(index, depthStencil);
}
Пример #25
0
double define_name(string var, double val)
{
  if (is_declared(var)) error(var, " declared twice");
  var_table.push_back(Variable(var, val));
  return val;
}
Пример #26
0
void Shader::SetBlend(const String& name, UINT index, ID3D11BlendState* blendState)
{
	Variable(name)->AsBlend()->SetBlendState(index, blendState);
}
Пример #27
0
 Variable Object::CreateVariable(const NodeId& newVariableId, const QualifiedName& browseName, const VariableType& type)
 {
   return Variable(GetServices());
 }
Пример #28
0
tValType add_variable(string s,tValType val){
	if (is_declared(s)) error(s, " is declared");
	var_table.push_back(Variable(s,val));
	return val;
}
Пример #29
0
Variable &
Item::getVariable( const std::string &nm )
{
	auto v = myVariables.emplace( std::make_pair( nm, Variable( nm ) ) );
	return v.first->second;
}
Пример #30
0
bool Player::getProperty(const std::string_view prop, Variable& var) const
{
	if (prop.empty() == true)
	{
		return false;
	}
	auto props = Utils::splitStringIn2(prop, '.');
	auto propHash = str2int16(props.first);
	if (getLevelObjProp(propHash, props.second, var) == true)
	{
		return true;
	}
	switch (propHash)
	{
	case str2int16("name"):
		var = Variable(Name());
		break;
	case str2int16("simpleName"):
		var = Variable(SimpleName());
		break;
	case str2int16("d"):
	case str2int16("description"):
	{
		updateNameAndDescriptions();
		size_t idx = Utils::strtou(props.second);
		if (idx >= descriptions.size())
		{
			idx = 0;
		}
		var = Variable(descriptions[idx]);
		break;
	}
	case str2int16("eval"):
		var = Variable((int64_t)Formula::evalString(props.second, *this));
		break;
	case str2int16("evalMin"):
		var = Variable((int64_t)Formula::evalMinString(props.second, *this));
		break;
	case str2int16("evalMax"):
		var = Variable((int64_t)Formula::evalMaxString(props.second, *this));
		break;
	case str2int16("evalf"):
		var = Variable(Formula::evalString(props.second, *this));
		break;
	case str2int16("evalMinf"):
		var = Variable(Formula::evalMinString(props.second, *this));
		break;
	case str2int16("evalMaxf"):
		var = Variable(Formula::evalMaxString(props.second, *this));
		break;
	case str2int16("totalKills"):
		var = Variable((int64_t)Class()->TotalKills());
		break;
	case str2int16("hasMaxStats"):
		var = Variable(hasMaxStats());
		break;
	case str2int16("hasProperty"):
		var = Variable(hasInt(props.second));
		break;
	case str2int16("canUseSelectedItem"):
	{
		if (selectedItem == nullptr)
		{
			return false;
		}
		var = Variable(canUseObject(*selectedItem));
		break;
	}
	case str2int16("canUseSelectedSpell"):
	{
		if (selectedSpell == nullptr)
		{
			return false;
		}
		var = Variable(canUseObject(*selectedSpell->spell));
		break;
	}
	case str2int16("canUseItem"):
	{
		std::string_view props2;
		size_t invIdx;
		size_t itemIdx;
		if (inventories.parseInventoryAndItem(
			props.second, props2, invIdx, itemIdx) == true)
		{
			auto item = inventories[invIdx].get(itemIdx);
			if (item != nullptr)
			{
				var = Variable(canUseObject(*item));
				break;
			}
		}
		return false;
	}
	case str2int16("hasEquipedItemType"):
		var = Variable(hasEquipedItemType(props.second));
		break;
	case str2int16("hasEquipedItemSubType"):
		var = Variable(hasEquipedItemSubType(props.second));
		break;
	case str2int16("hasSelectedItem"):
		var = Variable(selectedItem != nullptr);
		break;
	case str2int16("hasItem"):
	{
		std::string_view props2;
		size_t invIdx;
		size_t itemIdx;
		if (inventories.parseInventoryAndItem(
			props.second, props2, invIdx, itemIdx) == true)
		{
			var = Variable(inventories[invIdx].get(itemIdx) != nullptr);
			break;
		}
		return false;
	}
	case str2int16("hasItemClass"):
		var = Variable(inventories.hasItem(str2int16(props.second)));
		break;
	case str2int16("hasSpell"):
	{
		var = Variable(getSpell(std::string(props.second)) != nullptr);
		break;
	}
	case str2int16("hasSelectedSpell"):
	{
		var = Variable(selectedSpell != nullptr);
		break;
	}
	case str2int16("isItemSlotInUse"):
	{
		std::string_view props2;
		size_t invIdx;
		size_t itemIdx;
		if (inventories.parseInventoryAndItem(
			props.second, props2, invIdx, itemIdx) == true)
		{
			var = Variable(inventories[invIdx].isSlotInUse(itemIdx));
			break;
		}
		return false;
	}
	case str2int16("isStanding"):
		var = Variable(playerStatus == PlayerStatus::Stand);
		break;
	case str2int16("isWalking"):
		var = Variable(playerStatus == PlayerStatus::Walk);
		break;
	case str2int16("isAttacking"):
		var = Variable(playerStatus == PlayerStatus::Attack);
		break;
	case str2int16("isDead"):
		var = Variable(playerStatus == PlayerStatus::Dead);
		break;
	case str2int16("selectedItem"):
	{
		if (selectedItem != nullptr)
		{
			return selectedItem->getProperty(props.second, var);
		}
		return false;
	}
	case str2int16("item"):
	{
		std::string_view props2;
		size_t invIdx;
		size_t itemIdx;
		if (inventories.parseInventoryAndItem(
			props.second, props2, invIdx, itemIdx) == true)
		{
			auto item = inventories[invIdx].get(itemIdx);
			if (item != nullptr)
			{
				return item->getProperty(props2, var);
			}
		}
		return false;
	}
	case str2int16("inventory"):
	{
		auto props2 = Utils::splitStringIn2(props.second, '.');
		auto invIdx = GameUtils::getPlayerInventoryIndex(props2.first);
		if (invIdx < inventories.size())
		{
			return inventories[invIdx].getProperty(props2.second, var);
		}
		return false;
	}
	case str2int16("itemQuantity"):
	{
		auto classIdHash16 = str2int16(props.second);
		uint32_t itemQuantity = 0;
		if (itemQuantityCache.getValue(classIdHash16, itemQuantity) == false)
		{
			if (inventories.getQuantity(classIdHash16, itemQuantity) == true)
			{
				itemQuantityCache.updateValue(classIdHash16, itemQuantity);
			}
		}
		var = Variable((int64_t)itemQuantity);
		break;
	}
	case str2int16("selectedSpell"):
	{
		if (selectedSpell != nullptr)
		{
			return selectedSpell->getProperty(props.second, var);
		}
		return false;
	}
	case str2int16("spell"):
	{
		auto props2 = Utils::splitStringIn2(props.second, '.');
		auto spell = getSpellInstance(std::string(props2.first));
		if (spell != nullptr)
		{
			return spell->getProperty(props2.second, var);
		}
		return false;
	}
	default:
	{
		Number32 value;
		if (getNumberByHash(propHash, props.second, value) == true)
		{
			var = Variable(value.getInt64());
			break;
		}
		return false;
	}
	}
	return true;
}