Example #1
0
void PySimple1::getGap(double ylast, double dy, double dy_old)
{
	// For stability in Closure spring, may limit "dy" step size to avoid
	// overshooting on the closing of this gap.
	//
	TGap_y = ylast + dy;
	if(TGap_y > TClose_yright) {dy = 0.75*(TClose_yright - ylast);}
	if(TGap_y < TClose_yleft)  {dy = 0.75*(TClose_yleft  - ylast);}

	// Limit "dy" step size if it is oscillating in sign and not shrinking
	//
	if(dy*dy_old < 0.0 && fabs(dy/dy_old) > 0.5) dy = -dy_old/2.0;
	
	// Combine the Drag and Closure elements in parallel, starting by
	// resetting TGap_y in case the step size was limited.
	//
	TGap_y   = ylast + dy;
	getClosure(ylast,dy);
	getDrag(ylast,dy);
	TGap_p = TDrag_p + TClose_p;
	TGap_tang = TDrag_tang + TClose_tang;

	// Ensure that |p|<pmax.
	//
	if(fabs(TGap_p)>=pult) TGap_p =(TGap_p/fabs(TGap_p))*(1.0-PYtolerance)*pult;

	return;
}
Example #2
0
Lexeme *evalFuncCall(Lexeme *tree, Lexeme *env) {
  //printf("Eval func %s\n",displayLexeme(*tree));
  Lexeme *closure = getClosure(tree,env);
  //printf("Closure: %s\n",displayLexeme(*closure));
  if(strcmp(closure->type,BUILTIN) == 0) {
    //printf("Here1\n");
    //printf("builtin: %s\n",closure->sval);
    return closure->builtin(cdr(tree),env);
  }
  //printf("eval prams\n");

  Lexeme *params = getParams(closure);
  //printf("Eval args\n");
  Lexeme *eargs = evalFuncArgs(cdr(tree),params,env);
  params = stripOparen(params);
  //displayTree(eargs,"");
  //printf("make scope\n");

  Lexeme *newScope = extend(params,eargs,getDefScope(closure));;
  //printf("New scope for funcCall:\n");
  //displayEnv(newScope);
  //printf("Closure bod:\n");
  //displayTree(getBody(closure),"");
  //printf("Func call to %s fin\n",displayLexeme(*tree));

  return eval(getBody(closure),newScope);
}
void FuncScopeVariableEnvironment::flagStatic(CStrRef name, int64 hash) {
  if (!m_staticEnv) {
    void *closure = getClosure();
    if (UNLIKELY(closure != NULL)) {
      // statics for closures live on a closure
      c_GeneratorClosure *typedClosure = (c_GeneratorClosure*) closure;
      m_staticEnv = &typedClosure->m_statics;
    } else {
      bool isContClosure =
        ParserBase::IsContinuationFromClosureName(m_func->name().c_str());
      if (UNLIKELY(isContClosure)) {
        ObjectData *cont = getContinuation();
        ASSERT(cont != NULL);
        c_GenericContinuation *typedCont = (c_GenericContinuation*) cont;
        m_staticEnv = &typedCont->m_statics;
      } else {
        m_staticEnv = m_func->getStaticVars(*this);
      }
    }
  }
  ASSERT(m_staticEnv != NULL);
  if (!m_staticEnv->exists(name)) {
    m_staticEnv->getVar(name, SgNormal) = m_func->getStaticValue(*this, name);
  }
  getVar(name, SgNormal).assignRef(m_staticEnv->getVar(name, SgNormal));
}
Example #4
0
void QzSimple2::getGap(double zlast, double dz, double dz_old)
{
	// For stability in Closure spring, limit "dz" step size to avoid
	// overshooting on the "closing" or "opening" of the gap.
	//
	if(zlast > 0.0 && (zlast + dz) < -QZtolerance) dz = -QZtolerance - zlast;
	if(zlast < 0.0 && (zlast + dz) >  QZtolerance) dz =  QZtolerance - zlast;
	TGap_z = zlast + dz;

	// Combine the Suction and Closure elements in parallel
	//
	getClosure(zlast,dz);
	getSuction(zlast,dz);
	TGap_Q = TSuction_Q + TClose_Q;
	TGap_tang = TSuction_tang + TClose_tang;

	return;
}
Example #5
0
/***************************************
 *                                     *
 *             Evaluate                *
 *                                     *
 ***************************************/
COMB_EXPR
*Evaluate(COMB_EXPR *expr, ST_TYPE *resultType)
{
     V_INSTR         *value        = NULL;
     int              machineOps   = 0;
     CLOSURE         *closure      = NULL;
     COMB_EXPR       *result       = NULL;
     ST_TYPE         *type         = resultType;

#if mcDebug
     printMsg(MSG, "Machine: Evaluating combinator expression...");
#endif

     if (expr->tag == CTT_CLOSURE) {
	  closure = getClosure(expr->info.closure);

	  V      = closure->clo->info.closure.v;
	  PC     = closure->clo->info.closure.c;
	  A      = closure->rec->info.recMacroFrame.frame;
	  R1     = closure->rec;

	  pushD1(DPcont);
	  D1->info.code = &_HALT;

	  machineOps = _Machine(&value);
	  type = closure->type;
     }
     else {
	  MachineReset();
	  PC         = _CompileHalt(expr);
	  machineOps = _Machine(&value);
     }

#if mcDebug
     printf("Done\n");
#endif

     if (value)
	  result = deCompile(value, type);
     else /* here we have a bang */
	  result = deCompile(_BANG, type);

     return(result);
}