Example #1
0
/**
 * Cast the element to an if.
 *
 * @param element The element to cast.
 * @param success Is the cast successful?
 */
If CastToIf(Element const& element, bool& success)
{
    std::shared_ptr<Element_> element_ = element.ElementHandle();
    std::shared_ptr<If_> i = std::dynamic_pointer_cast<If_>(element_);
    success = (0 != i.get());
    return success ? If(i, element.GetSourceLocation()) : If();
}
Example #2
0
/**
 * Cast the element to an if.
 *
 * @param element The element to cast.
 * @param success Is the cast successful?
 */
If CastToIf(Element const& element, bool& success)
{
    Element_* element_ = const_cast<Element_*>(element.ElementHandle());
    If_* i = dynamic_cast<If_*>(element_);
    success = (0 != i);
    return success ? If(i, element.GetSourceLocation()) : If();
}
Example #3
0
void InitializeQChemLogic() {

  OptionRegister& reg = OptionRegister::instance();

  NodeT *node, *node2;
  Rule rule;

  node = &reg.get("BASIS");
  node2 = &reg.get("BASIS2");
  node2->addRule(
     If (*node2 == S("6-311+G**"), node->shouldBe("6-311++G(3df,3pd)")));
  node2->addRule(
     If (*node2 == S("rcc-pVTZ"), node->shouldBe("cc-pVTZ")));
  node2->addRule(
     If (*node2 == S("rcc-pVQZ"), node->shouldBe("cc-pVQZ")));
  node2->addRule(
     If (*node2 == S("6-311+G**") || 
         *node2 == S("rcc-pVTZ") || 
         *node2 == S("rcc-pVQZ"), 
          reg.get("DUAL_BASIS_ENERGY").shouldBe("true"),
          reg.get("DUAL_BASIS_ENERGY").shouldBe("false")));


  node = &reg.get("CORRELATION");
   node->addRule(
      If(isPostHF, 
         reg.get("EXCHANGE").shouldBe("HF"))
   );


}
Example #4
0
int main( )
{
    execute( Seq(
        If( True( ), Print( String( "hello " ) ), Print( True( ) ) ),
        If( Or( False( ), Neg( True( ) ) ), Print( Unit( ) ), Print( String( "world!\n" ) ) ) ) );
    execute( Seq(
        When( True( ), Print( String( "hello " ) ) ),
        Unless( False( ), Print( String( "world!\n" ) ) ) ) );
    execute( Print( Print( Seq( Print( True( ) ), Print( False( ) ) ) ) ) );
    execute( Print( Concat( String( "4" ), Show( True( ) ) ) ) );
    assert( value_to_bool( execute( IsDefined( String( "not defined" ) ) ) ) == false );
    execute(
        Seq( Set( String( "SomeVar" ), String( "12" ) ),
             Seq( Print( Get( String( "SomeVar" ) ) ),
                  Seq( Set( Concat( String( "S" ), String( "omeVar" ) ), String( "345\n" ) ),
                       Print( Get( Concat( String( "Some" ), String( "Var" ) ) ) ) ) ) ) );
    execute( Seq(
        If( True( ), Set( String( "hello " ), String( "hellos \n" ) ), Print( True( ) ) ), Print( Get( String( "hello " ) ) ) ) );
    execute( Seq( Scope( Set( String( "hi" ), True( ) ) ), Print( IsDefined( String( "hi" ) ) ) ) );
    assert(
        value_to_bool( execute( Seq( Seq( Set( String( "var" ), False( ) ), Scope( Set( String( "var" ), True( ) ) ) ), Get( String( "var" ) ) ) ) ) );
    execute(
        Seq(
            Seq( Set( String( "b1" ), True( ) ), Set( String( "b2" ), True( ) ) ),
            While(
                Or( Get( String( "b1" ) ), Get( String( "b2" ) ) ),
                If( Get( String( "b1" ) ),
                    Seq( Set( String( "b1" ), False( ) ), Print( String( "Hello" ) ) ),
                    Seq( Set( String( "b2" ), False( ) ), Print( String( "World" ) ) ) ) ) ) );
}
Example #5
0
File: main.c Project: rennone/C
void mouse(int button, int state, int x, int y)
{
  switch(button){
  case GLUT_LEFT_BUTTON:
    if (state == GLUT_DOWN){
      glutIdleFunc(spinDisplay);
      if(direction == 1)
	direction = -1;
      else
	direction = 1;
    }
    break;
    
  case GLUT_MIDDLE_BUTTON:
    If (state == GLUT_DOWN)
      glutIdleFunc(NULL);
    break;
    
  case GLUT_RIGHT_BUTTON:
    if (state == GLUT_DOWN)
      exit(0);
    break;
    
  default:
    break;
  }
}
Example #6
0
void posix_words() {
    Primitive( "getwd", &_getwd );
    Colon( "pwd" ); c("getwd"); c("type"); c("cr"); End();

    Primitive( "(getenv)", &_getenv );
    Primitive( "(setenv)", &_setenv );
    Colon( "getenv" ); c("parse-word"); c("(getenv)"); End();
    Colon( "setenv" ); c("parse-word"); c("parse-word"); c("(setenv)"); End();
    Colon( "printenv" );
          c("parse-word"); c("2dup"); c("type");
          Literal((Cell)'='); c("emit");
          c("(getenv)"); If(); c("type"); Then(); c("cr"); End();

    Primitive( "(system)", &_system );
    Primitive( "(exec)",   &_exec );

    /* mmap() protection */
    Constant( "PROT_EXEC",  (Cell)PROT_EXEC );
    Constant( "PROT_READ",  (Cell)PROT_READ );
    Constant( "PROT_WRITE", (Cell)PROT_WRITE );
    Constant( "PROT_NONE",  (Cell)PROT_NONE );

    /* mmap() Flags */
    Constant( "MAP_FIXED",   (Cell)MAP_FIXED );
    Constant( "MAP_SHARED",  (Cell)MAP_SHARED );
    Constant( "MAP_PRIVATE", (Cell)MAP_PRIVATE );

    Primitive( "mmap", &do_mmap );

    Primitive( "getpid", &_getpid );
    Primitive( "getppid", &_getppid );

    /* Signals for kill */
    Constant( "SIGHUP",    (Cell)SIGHUP );
    Constant( "SIGINT",    (Cell)SIGINT );
    Constant( "SIGQUIT",   (Cell)SIGQUIT );
    Constant( "SIGILL",    (Cell)SIGILL );
    Constant( "SIGTRAP",   (Cell)SIGTRAP );
    Constant( "SIGABRT",   (Cell)SIGABRT );
    Constant( "SIGIOT",    (Cell)SIGIOT );
    Constant( "SIGBUS",    (Cell)SIGBUS );
    Constant( "SIGFPE",    (Cell)SIGFPE );
    Constant( "SIGKILL",   (Cell)SIGKILL );
    Constant( "SIGUSR1",   (Cell)SIGUSR1 );
    Constant( "SIGSEGV",   (Cell)SIGSEGV );
    Constant( "SIGUSR2",   (Cell)SIGUSR2 );
    Constant( "SIGPIPE",   (Cell)SIGPIPE );
    Constant( "SIGALRM",   (Cell)SIGALRM );
    Constant( "SIGTERM",   (Cell)SIGTERM );
    // Constant( "SIGSTKFLT", (Cell)SIGSTKFLT );
    // Constant( "SIGCLD",    (Cell)SIGCLD );
    Constant( "SIGCHLD",   (Cell)SIGCHLD );
    Constant( "SIGCONT",   (Cell)SIGCONT );
    Constant( "SIGSTOP",   (Cell)SIGSTOP );
    Constant( "SIGTSTP",   (Cell)SIGTSTP );

    Primitive( "kill", &_kill );
}
Example #7
0
string Ports::IsBoundTo(Edge pE, Interface::tDirection pDir) {
	iterator It;
	for (It = Begin() ; It!= End() ; It++) {
		if ( If(It).GetDirection() == pDir && BoundTo(Name(It)) == pE ) {
			return Name(It) ;
		}
	}
	return string("") ;
}
Example #8
0
static void lia_dput (Lia_obj longi, int decimal_flag)
     /* Input/Output: longi. */
     /* Puts decimal (or hexadecimal) representation of longi[] into cbbuf[].
        Code is sort of weird (recursive!) to avoid additional buffer space.
        NOTE: - longi[] will destroyed.
              - longi[] > 0 is assumed.
        Internal use only! */
{
  unsigned long part;
  char string[5];
  lia_sdiv (longi, &part, longi, If (decimal_flag, 1000L, 0x1000L));
  sprint (string, If (decimal_flag, "%03lu", "%03lx"), part);
  if ((longi[0] > 2) or (longi[1] > 0))
    lia_dput (longi, decimal_flag);
  lia_cput (string[0]);
  lia_cput (string[1]);
  lia_cput (string[2]);
}
Example #9
0
//=========================================================
bool Parser::Else () {
    PrintRule rule("Else");
    if (Accept(TokenType::Else) == false) {
        return false;
    }
    if (!If() && !Scope()) {
        throw ParsingException("Failed to parse Else");
    }
    return rule.Accept();
}
Example #10
0
std::vector<std::string> Ports::GetNotBoundInOut() {
	iterator It;
	std::vector<std::string> RetVal;
	for (It = Begin() ; It != End() ; It++) {
		if ( (!IsBound(Name(It))) && (If(It).GetDirection() == Interface::INOUT)) {
			RetVal.push_back(Name(It)) ;
		}
	}
	return RetVal ;
}
Example #11
0
/**
 * Parse out the token stream.
 *
 * @param in -- The input token stream.
 * @return the element that was parsed.
 */
Element If_::Parse_( Parser const& 
                   , TokenStream& in
                   , std::vector<Element> const& elements) const
{
    in.Consume();

    std::shared_ptr<If_> s ( new If_() );
    s->SetCondition(elements[0]);
    s->SetTrue(elements[1]);
    s->SetFalse(elements[2]);

    return If(s, SourceLocation());
}
Example #12
0
File: dt.c Project: pkuwwt/Detri
Dt_input_scan *dt_input_scan (const char data_path[])
     /* ... scans the ASCII input file data_path for the fields in the return
        structure (see dt.h file).  See also dt_input_load() which actually
        loads the data and sets the has_weights field if necessary. */
     /* NOTE: The returned address, which points to the return structure,
              is a constant.  DO NOT FREE() IT and consider the fields
              of the structure as read-only. */
{
  static Dt_input_scan data;
  FILE *inp = basic_fopen (data_path, "r");
  char *r;
  ;
  /* default values */
  data.name = STRDUP (data_path);
  data.title = NULL;
  data.lines = 0;
  data.n = 0;
  data.scale = 1.0;     /* ie, no scaling */
  data.fix_w = 0;    
  data.fix_a = 0;
  data.decimals = 10;  /* ie, int coordinates */
  data.has_weights = 0;  /* ie, unknown; see dt_input_load() */
  ;
  /* scan the file */
  print ("Scanning ASCII file \"%s\" ... ",
         If (basic_fopen_zpath, basic_fopen_zpath, data_path));
  flush ();
  while ((r = basic_cb_getline (inp)))
    {
      data.lines ++;
      if (basic_strip (r) AND (r[0] != '#'))
        { /* a data line: <x> <y> <z> */
          data.n ++;
        }
      else if (is_command (&data, r, "title", 5))
        { /* # title: %s */
          r = basic_strip (index (r, 'e') + 1);
          if (r)
            {
              int i = -1;
              data.title = STRDUP (r);
              do { i ++; } until (data.title[i] == '\n');
              data.title[i] = 0;
            }
        }
      else if (is_command (&data, r, "scale", 5))
int main(void){

  double tolerance = 1.e-10;          
  double a = 1.0;               // y(x0).
  double x0 = 0.0;              // x0 the initial condition.
  double h = 0.1;               // step size
  int number_of_steps = 10;     // and number of steps, i.e. 

  double exact;
  double error;
  double h_next;
  double h_used;
  double x;
  double x_start;
  double x_stop;
  double y0 = a;
  double y1;
  int i;
  int err;
 
  x_start = x0;
  x = x_start;

  for (i = 0; i < number_of_steps; i++) {

    h_used = h;
    x_stop = x_start + h;

    do {

      while (Gragg_Bulirsch_Stoer( f, y0, &y1, x, h_used, &h_next, 1.0,
				   tolerance, 0)) h_used /= 4.0;
      x += h_used;
      y0 = y1;
      if ( x + h_next > x_stop ) h_used = x + h_next - x_stop;
      else h_used = h_next;
    } while ( x < x_stop - 1.e-10 );
                  
    exact = If(x);
    error = exact - y1;
    printf("%3d   %8.2le  %20.15le", i+1, x, y1);
    printf("   %20.15le  %+9.4le\n", exact,error);
    x_start = x;
  }
}
Example #14
0
/* <Statement> ::= <Compound> | <Assign> | <If> | <Return> | <Write> | <Read> | <While> */
bool SyntaxAnalyzer::Statement()
{
    
	if(Compound())
    {
		logger.Log("<Statement> ::= <Compund>");
        return true;
    }
	else if(Assign())
    {
        logger.Log("<Statement> ::= <Assign>");
        return true;
    }
	else if(If())
    {
		logger.Log("<Statement> ::= <If>");
        return true;
    }
	else if(Return())
    {
		logger.Log("<Statement> ::= <Return>");
        return true;
    }
	else if(Write())
    {
		logger.Log("<Statement> ::= <Write>");
        return true;
    }
	else if(Read())
    {
		logger.Log("<Statement> ::= <Read>");
        return true;
    }
	else if(While())
    {
		logger.Log("<Statement> ::= <While>");
        return true;
    }
    else
    {
        return false;
    }
}
Example #15
0
    virtual ResultExpr EvaluateSyscall(int sysno) const override {
        switch (sysno) {
            // Simulate opening the plugin file.
#ifdef __NR_open
        case __NR_open:
#endif
        case __NR_openat:
            return Trap(OpenTrap, mPlugin);

        // ipc::Shmem
        case __NR_mprotect:
            return Allow();
        case __NR_madvise: {
            Arg<int> advice(2);
            return If(advice == MADV_DONTNEED, Allow())
                   .Else(InvalidSyscall());
        }

        default:
            return SandboxPolicyCommon::EvaluateSyscall(sysno);
        }
    }
Example #16
0
bool Parser::Stmt()
{
	if ("identifier" == tok) {
		if (!Assign()) return false;
		else {
			std::cout << "Stmt => Assign\n";
			return true;
		}
	} else if ("read" == lex) {
		if (!Read()) return false;
		else {
			std::cout << "Stmt => Read\n";
			return true;
		}
	} else if ("write" == lex) {
		if (!Write()) return false;
		else {
			std::cout << "Stmt => Write\n";
			return true;
		}
	} else if ("if" == lex) {
		if (!If()) return false;
		else {
			std::cout << "Stmt => If\n";
			return true;
		}
	} else if ("while" == lex) {
		if (!While()) return false;
		else {
			std::cout << "Stmt => While\n";
			return true;
		}
	} else {
		std::cout << "Error with statement\n";
		return false;
	}
}
Example #17
0
// 函数块
void CodeGenerator::Block() {
    while(!isNext("}")) {
        CodeToken T = getToken();
        string value = T.value;
        if(value == "if") {
            If();
        } else if(value == "while") {
            While();
        } else if(value == "for") {
            For();
        } else if(value == "read") {
            match("("); addQuad("read", getToken().value, "$", "$"); match(")"); match(";");
        } else if(value == "write") {
            match("("); addQuad("write", getToken().value, "$", "$"); match(")"); match(";");
        } else if(value == "return") {
            addQuad("return", itos(getToken().num), "$", "$");   match(";");
        } else if(CodeToString(T) == "id") {
            CurToken--;
            Assign();
        } else {
            puts("函数块错误!!"); printf("in %d", CurLine()); exit(0);
        }
    }
}
Example #18
0
    virtual Maybe<ResultExpr> EvaluateSocketCall(int aCall) const override {
        switch(aCall) {
        case SYS_RECVFROM:
        case SYS_SENDTO:
            return Some(Allow());

        case SYS_SOCKETPAIR: {
            // See bug 1066750.
            if (!kSocketCallHasArgs) {
                // We can't filter the args if the platform passes them by pointer.
                return Some(Allow());
            }
            Arg<int> domain(0), type(1);
            return Some(If(domain == AF_UNIX &&
                           (type == SOCK_STREAM || type == SOCK_SEQPACKET), Allow())
                        .Else(InvalidSyscall()));
        }

#ifdef ANDROID
        case SYS_SOCKET:
            return Some(Error(EACCES));
#else // #ifdef DESKTOP
        case SYS_RECV:
        case SYS_SEND:
        case SYS_SOCKET: // DANGEROUS
        case SYS_CONNECT: // DANGEROUS
        case SYS_SETSOCKOPT:
        case SYS_GETSOCKNAME:
        case SYS_GETPEERNAME:
        case SYS_SHUTDOWN:
            return Some(Allow());
#endif
        default:
            return SandboxPolicyCommon::EvaluateSocketCall(aCall);
        }
    }
Example #19
0
void InputDialog::initializeQuiLogic() {

  OptionRegister& reg = OptionRegister::instance();

  // These are just for convenience
  QString QtTrue(QString::number(Qt::Checked));
  QString QtFalse(QString::number(Qt::Unchecked));

  QtNode *node, *node2;
  Rule rule;


   // Setup -> Energy
   node = &reg.get("EXCHANGE");
   node->addRule(
      If(*node == S("User-defined"),  
         Disable(m_ui.correlation)
      )
   );
   node->addRule(
     If(isCompoundFunctional, 
        Disable(m_ui.correlation), 
        Enable(m_ui.correlation) 
     )
   );

   node = &reg.get("CORRELATION");
   node->addRule(
      If(*node == S("MP2"), 
         Enable(m_ui.cd_algorithm), 
         Disable(m_ui.cd_algorithm) 
      )
   );
   node->addRule(
      If(*node == S("RIMP2"),  
         Enable(m_ui.auxiliary_basis), 
         Disable(m_ui.auxiliary_basis) 
      )
   );
   node = &reg.get("ECP");
   node->addRule(
      If(*node != S("None"), 
         reg.get("BASIS").makeSameAs(node) 
      )
   );

   node = &reg.get("BASIS2");
   node->addRule(
      If(*node != S("None"), 
         reg.get("ECP").shouldBe("None") 
      )
   );
 


   // Setup -> Frequencies
   node = &reg.get("ANHARMONIC");
   node->addRule(
      If(*node == QtTrue,
         Enable(m_ui.vci), 
         Disable(m_ui.vci) 
      )
   );


   // Setup -> Ab Initio MD
   node = &reg.get("AIMD_METHOD");
   node->addRule(
      If(*node == S("BOMD"), 
         Disable(m_ui.deuterate), 
         Enable(m_ui.deuterate) 
      )
   );
   node = &reg.get("AIMD_INITIAL_VELOCITIES");
   node->addRule(
      If(*node == QString("Thermal"), 
         Enable(m_ui.aimd_temperature), 
         Disable(m_ui.aimd_temperature) 
      )
   );


   // Setup -> Transition State
   node = &reg.get("JOB_TYPE");
   node->addRule(
      If(*node == S("Transition State"),  
         Enable(m_ui.geom_opt_mode), 
         Disable(m_ui.geom_opt_mode) 
      )
   );




   // Advanced -> SCF Control
   node = &reg.get("SCF_ALGORITHM");
   node->addRule(
      If(*node == S("DM"),  
         Enable(m_ui.pseudo_canonical), 
         Disable(m_ui.pseudo_canonical) 
      )
   );
   node->addRule(
      If(*node == S("DIIS_DM") || *node == S("DIIS_GDM"),  
         Enable(m_ui.diis_max_cycles)
         + Enable(m_ui.diis_switch_thresh), 
         Disable(m_ui.diis_max_cycles) 
         + Disable(m_ui.diis_switch_thresh) 
      )
   );
   node->addRule(
      If(*node == S("RCA") || *node == S("RCA_DIIS"),  
         Enable(m_ui.rca_print) 
         + Enable(m_ui.rca_max_cycles),
         Disable(m_ui.rca_print) 
         + Disable(m_ui.rca_max_cycles) 
      )
   );
   node->addRule(
      If(*node == S("RCA_DIIS"),  
         Enable(m_ui.rca_switch_thresh), 
         Disable(m_ui.rca_switch_thresh)
      )
   );


   // Advanced -> SCF Control -> DFT
   node = &reg.get("XC_GRID");
   node->addRule(
      If(*node == S("SG-0") || *node == S("SG-1"),  
         Disable(m_ui.qui_radial_grid),
         Enable(m_ui.qui_radial_grid)
      )
   );

   node = &reg.get("DFT_D");
   node->addRule(
      If(*node == S("Chai Head-Gordon"),
         Enable(m_ui.dft_d_a),
         Disable(m_ui.dft_d_a)
      )
   );



   node = &reg.get("INCDFT");
   node->addRule(
      If(*node == QtFalse,  
         Disable(m_ui.incdft_dendiff_thresh)
         + Disable(m_ui.incdft_dendiff_varthresh)
         + Disable(m_ui.incdft_griddiff_thresh)
         + Disable(m_ui.incdft_griddiff_varthresh), 

         Enable(m_ui.incdft_dendiff_thresh)
         + Enable(m_ui.incdft_dendiff_varthresh)
         + Enable(m_ui.incdft_griddiff_thresh)
         + Enable(m_ui.incdft_griddiff_varthresh)
      )
   );


   // Advanced -> SCF Control -> DFT -> Constrained DFT
   node = &reg.get("CDFT");
   node->addRule(
      If(*node == QtTrue, 
         Enable(m_ui.cdft_prediis)
         + Enable(m_ui.cdft_postdiis)
         + Enable(m_ui.cdft_thresh), 

         Disable(m_ui.cdft_prediis) 
         + Disable(m_ui.cdft_postdiis) 
         + Disable(m_ui.cdft_thresh) 
      )
   );


   // Advanced -> SCF Control -> Print Options
   node = &reg.get("QUI_PRINT_ORBITALS");
   node2 = &reg.get("PRINT_ORBITALS");
   node->addRule(
      If(*node == QtTrue,
         Enable(m_ui.print_orbitals) + node2->shouldBe("5"),
         Disable(m_ui.print_orbitals)
      )
   );


   // Advanced -> SCF Control -> PAO
   node = &reg.get("PAO_METHOD");
   node->addRule(
      If(*node == S("PAO"), 
         Disable(m_ui.epao_iterate)
         + Disable(m_ui.epao_weights),
         Enable(m_ui.epao_iterate) 
         + Enable(m_ui.epao_weights) 
      )
   );


   // Advanced -> Wavefunction Analysis
   node = &reg.get("DMA");
   node->addRule(
      If(*node == QtTrue, 
         Enable(m_ui.dma_midpoints), 
         Disable(m_ui.dma_midpoints) 
      )
   );

  
   // Advanced -> Wavefunction Analysis -> Plots
   node = &reg.get("PLOTS_GRID");
   node->addRule(
      If(*node == S("None"),  
         Disable(m_ui.plots_property)
         + Disable(m_ui.qui_plots_points), 
         Enable(m_ui.plots_property)
         + Enable(m_ui.qui_plots_points) 
      )
   );
   node->addRule(
      If(*node == S("User-defined"),  
         boost::bind(&InputDialog::printSection, this, "plots", true),
         boost::bind(&InputDialog::printSection, this, "plots", false)
      )
   );
   node->addRule(
      If(*node == S("Read from file"),  
         Enable(m_ui.qui_plots_points), 
         Disable(m_ui.qui_plots_points) 
      )
   );


   // Advanced -> Wavefunction Analysis -> Intracules
   node = &reg.get("INTRACULE");
   node->addRule(
      If(*node == QtTrue,
         Enable(m_ui.intracule_method)
         + Enable(m_ui.intracule_grid)
         + Enable(m_ui.intracule_j_series_limit)
         + Enable(m_ui.intracule_i_series_limit)
         + Enable(m_ui.intracule_wigner_series_limit)
         + Enable(m_ui.intracule_conserve_memory),

         Disable(m_ui.intracule_method)
         + Disable(m_ui.intracule_grid)
         + Disable(m_ui.intracule_j_series_limit)
         + Disable(m_ui.intracule_i_series_limit)
         + Disable(m_ui.intracule_wigner_series_limit)
         + Disable(m_ui.intracule_conserve_memory) 
      )
   );


   // Advanced -> Large Molecule Methods -> CFMM
   node = &reg.get("GRAIN");
   node->addRule(
      If(*node == S("Off"), 
         Disable(m_ui.cfmm_order)
         + Disable(m_ui.lin_k),  
         Enable(m_ui.cfmm_order) 
         + Enable(m_ui.lin_k) 
      )
   );
   // These are around the other way as the default is cfmm on
   node = &reg.get("QUI_CFMM");
   node->addRule(
      If(*node == QtFalse, 
         Disable(m_ui.cfmm_grain)
         + Disable(m_ui.cfmm_order)
         + Disable(m_ui.lin_k), 
         Enable(m_ui.cfmm_grain) 
         + Enable(m_ui.cfmm_order) 
         + Enable(m_ui.lin_k) 
      )
   );
/*
   node = &reg.get("JOB_TYPE");
   node->addRule(
      If(requiresDerivatives, 
         SetValue(m_ui.cfmm_order,25),
         SetValue(m_ui.cfmm_order,15)
      )
   );
*/


   // Advanced -> Large Molecule Methods -> FTC
   node = &reg.get("FTC");
   node->addRule(
      If(*node == QtTrue, 
         Enable(m_ui.ftc_fast)
         + Enable(m_ui.ftc_class_thresh_order)
         + Enable(m_ui.ftc_class_thresh_mult), 
         Disable(m_ui.ftc_fast) 
         + Disable(m_ui.ftc_class_thresh_order) 
         + Disable(m_ui.ftc_class_thresh_mult) 
      )
   );


   // Advanced -> Large Molecule Methods -> CASE
   node = &reg.get("INTEGRAL_2E_OPR");
   node->addRule(
     If(*node == QtTrue, 
        Enable(m_ui.omega), 
        Disable(m_ui.omega) 
     )
   );


   // Advanced -> QMMM
   node = &reg.get("QMMM");
   node->addRule(
     If(*node == QtTrue, 
        Enable(m_ui.qmmm_charges)
        + Enable(m_ui.qmmm_print)
        + Enable(m_ui.link_atom_projection),
        Disable(m_ui.qmmm_charges)
        + Disable(m_ui.qmmm_print)
        + Disable(m_ui.link_atom_projection)
     )
   );

   node2 = &reg.get("JOB_TYPE");
   rule = If(*node == QtTrue && *node2 == S("Frequencies"),
             Enable(m_ui.qmmm_full_hessian),
             Disable(m_ui.qmmm_full_hessian)
          );
   
   node->addRule(rule);
   node2->addRule(rule);


   node  = &reg.get("QUI_SECTION_EXTERNAL_CHARGES");
   node->addRule(
      If(*node == QtTrue, 
        reg.get("SYMMETRY_INTEGRAL").shouldBe(QtFalse)
        + reg.get("SYMMETRY_IGNORE").shouldBe(QtTrue)
      )
   );

   node2 = &reg.get("JOB_TYPE");
   rule = If(*node == QtTrue && *node2 == S("Geometry"),
          reg.get("GEOM_OPT_IPROJ").shouldBe(QtFalse)
          );
   node->addRule(rule);
   node2->addRule(rule);


   // Advanced -> Correlated Methods
   node = &reg.get("QUI_FROZEN_CORE");
   node->addRule(
      If(*node == QtTrue,
         Disable(m_ui.n_frozen_core)
         + Disable(m_ui.n_frozen_virtual), 
         Enable(m_ui.n_frozen_core)
         + Enable(m_ui.n_frozen_virtual)
      ) 
   );


   // Advanced -> Correlated Methods -> Coupled-Cluster
   /*node = &reg.get("CC_PROPERTIES");
   node->addRule(
      If(*node == QtTrue,
         Enable(m_ui.cc_two_particle_properties)
         + Enable(m_ui.cc_amplitude_response)
         + Enable(m_ui.cc_full_response), 
         Disable(m_ui.cc_two_particle_properties)
         + Disable(m_ui.cc_amplitude_response)
         + Disable(m_ui.cc_full_response)
      ) 
   );

   node = &reg.get("CC_MP2NO_GUESS");
   node->addRule(
      If(*node == QtTrue,
         Enable(m_ui.cc_mp2no_grad) + Enable(m_ui.threads), 
         Disable(m_ui.cc_mp2no_grad) + Disable(m_ui.threads)
      ) 
   );//*/


   // Advanced -> Correlated Methods -> Coupled-Cluster -> Convergence
   /*node = &reg.get("CC_DIIS");
   node->addRule(
      If(*node == S("Switch"),
         Enable(m_ui.cc_diis12_switch), 
         Disable(m_ui.cc_diis12_switch)
      ) 
   );//*/


   // Advanced -> Correlated Methods -> Active Space
   node = &reg.get("CC_RESTART");
   node->addRule(
      If(*node == QtTrue,
         Enable(m_ui.cc_restart_no_scf), 
         Disable(m_ui.cc_restart_no_scf)
      ) 
   );


   // Advanced -> Excited States -> CIS
   node = &reg.get("JOB_TYPE");
   node->addRule(
      If(*node == S("Geometry") || *node == S("Frequencies") 
                                || *node == S("Forces"), 
         Enable(m_ui.cis_state_derivative), 
         Disable(m_ui.cis_state_derivative) 
      )
   );
   node = &reg.get("CIS_GUESS_DISK");
   node->addRule(
      If(*node == QtTrue,
         Enable(m_ui.cis_guess_disk_type), 
         Disable(m_ui.cis_guess_disk_type) 
      )
   );


   // Advanced -> Excited States -> TD DFT
   node = &reg.get("CIS_RAS");
   node->addRule(
      If(*node == QtTrue, 
         Enable(m_ui.cis_ras_type)
         + Enable(m_ui.cis_ras_cutoff_occupied)
         + Enable(m_ui.cis_ras_cutoff_virtual)
         + Enable(m_ui.cis_ras_print),
         Disable(m_ui.cis_ras_type) 
         + Disable(m_ui.cis_ras_cutoff_occupied) 
         + Disable(m_ui.cis_ras_cutoff_virtual) 
         + Disable(m_ui.cis_ras_print) 
      )
   );


   // Advanced -> Excited States -> EOM -> Properties
 /*  node = &reg.get("CC_EOM_PROPERTIES");
   node->addRule(
      If(*node == QtTrue, 
         Enable(m_ui.cc_eom_transition_properties)
         + Enable(m_ui.cc_eom_amplitude_response)
         + Enable(m_ui.cc_eom_full_response)
         + Enable(m_ui.cc_eom_two_particle_properties), 
         Disable(m_ui.cc_eom_transition_properties) 
         + Disable(m_ui.cc_eom_amplitude_response) 
         + Disable(m_ui.cc_eom_full_response) 
         + Disable(m_ui.cc_eom_two_particle_properties) 
      )
   );//*/


   // Advanced -> Excited States -> XOPT
   /*node = &reg.get("QUI_XOPT1");
   node2 = &reg.get("QUI_XOPT2");
   node->addRule(
      If(*node == QtTrue,
         Enable(m_ui.qui_xopt_spin1)
         + Enable(m_ui.qui_xopt_state1)
         + Enable(m_ui.qui_xopt_irrep1)
         + Enable(m_ui.qui_xopt_spin2)
         + Enable(m_ui.qui_xopt_state2)
         + Enable(m_ui.qui_xopt_irrep2)
         + Enable(m_ui.xopt_seam_only),
         Disable(m_ui.qui_xopt_spin1)
         + Disable(m_ui.qui_xopt_state1)
         + Disable(m_ui.qui_xopt_irrep1)
         + Disable(m_ui.qui_xopt_spin2)
         + Disable(m_ui.qui_xopt_state2)
         + Disable(m_ui.qui_xopt_irrep2)
         + Disable(m_ui.xopt_seam_only)
      )
   );
   node->addRule(
      If(*node == QtTrue,  
        node2->shouldBe(QtTrue), 
        node2->shouldBe(QtFalse)
      )
   );//*/


   // Advanced -> Solvation Models -> ChemSol
   node = &reg.get("CHEMSOL");
   node->addRule(
      If(*node == QtTrue, 
         Enable(m_ui.chemsol_nn)
         + Enable(m_ui.chemsol_print)
         + Enable(m_ui.chemsol_efield)
         + Enable(m_ui.chemsol_read_vdw), 
         Disable(m_ui.chemsol_nn) 
         + Disable(m_ui.chemsol_print)
         + Disable(m_ui.chemsol_efield)
         + Disable(m_ui.chemsol_read_vdw) 
      )
   );



   // Section logic ----------------------------------------------------------
   node = &reg.get("QUI_TITLE");
   node->addRule(
      If(*node == S(""), 
         boost::bind(&InputDialog::printSection, this, "comment", false),
         boost::bind(&InputDialog::printSection, this, "comment", true)
      )
   );

   node = &reg.get("EXCHANGE");
   node->addRule(
      If(*node == S("User-defined"), 
         boost::bind(&InputDialog::printSection, this, "xc_functional", true),
         boost::bind(&InputDialog::printSection, this, "xc_functional", false)
      )
   );

   node = &reg.get("CHEMSOL_READ_VDW");
   node->addRule(
      If(*node == S("User-defined"), 
         boost::bind(&InputDialog::printSection, this, "van_der_waals", true),
         boost::bind(&InputDialog::printSection, this, "van_der_waals", false)
      )
   );

   node = &reg.get("ECP");
   node->addRule( 
      If(*node == S("User-defined"), 
         boost::bind(&InputDialog::printSection, this, "ecp", true),
         boost::bind(&InputDialog::printSection, this, "ecp", false)
      ) 
   );
           
   node = &reg.get("BASIS");
   node->addRule(
      If(*node == S("User-defined") || *node == S("Mixed"),
         boost::bind(&InputDialog::printSection, this, "basis", true),
         boost::bind(&InputDialog::printSection, this, "basis", false)
      )
   );

   node = &reg.get("AIMD_INITIAL_VELOCITIES");
   node2 = &reg.get("JOB_TYPE");
   rule = If(*node2 == S("Ab Initio MD") && *node == S("Read"),
             boost::bind(&InputDialog::printSection, this, "velocity", true),
             boost::bind(&InputDialog::printSection, this, "velocity", false)
          );
   node->addRule(rule);
   node2->addRule(rule);

   node = &reg.get("CIS_RAS_TYPE");
   node->addRule(
      If(*node == S("User-defined"),
         boost::bind(&InputDialog::printSection, this, "solute", true),
         boost::bind(&InputDialog::printSection, this, "solute", false)
      )
   );

   node = &reg.get("ISOTOPES");
   node->addRule(
      If (*node == QtTrue,
         boost::bind(&InputDialog::printSection, this, "isotopes", true),
         boost::bind(&InputDialog::printSection, this, "isotopes", false)
      )
   );
  
   node = &reg.get("JOB_TYPE");
   node->addRule(
      If (*node == S("Geometry") || *node == S("Reaction Path")
       || *node == S("Transition State"),
         boost::bind(&InputDialog::printSection, this, "opt", true),
         boost::bind(&InputDialog::printSection, this, "opt", false)
      )
   );


   //node = &reg.get("QMMM");
   node = &reg.get("QUI_SECTION_EXTERNAL_CHARGES");
   node->addRule(
      If (*node == QtTrue,
         boost::bind(&InputDialog::updateLJParameters, this)
         + boost::bind(&InputDialog::printSection, this, "lj_parameters", true),
         boost::bind(&InputDialog::printSection, this, "lj_parameters", false)
      )
   );




}
Example #20
0
File: dt.c Project: pkuwwt/Detri
Dt* dt_load (const char path_name[])
{
  Dt *dt = MALLOC (Dt, 1);
  Trist *s = MALLOC (Trist, 1);
  ;
  { /* using binary format */
    FILE *f = basic_fopen (path_name, "r");
    print ("Reading Delaunay triangulation from binary file \"%s\" ...\n",
           If (basic_fopen_zpath, basic_fopen_zpath, path_name));
    ;
    Read1f (dt->type);
    Read1f (dt->bpt);
    Read1f (dt->n);
    Read1f (dt->redundant);
    Read1f (dt->hull_ef);
    Read1f (dt->last_hull);
    Read1f (dt->num);
    Read1f (dummy_word);
    ;
    Read1f (s->magic);
    Read1f (dummy_word);
    Read1f (s->last_triangle);
    Read1f (s->max_triangle);
    Read1f (s->max_org);
    Read1f (dummy_word);
    Read1f (s->used_triangles);
    Read1f (s->next_reusable_triangle);
    s->data_size = 0;
    s->data = NULL;
    ;
    dt->trist = s;
    ;
    /* just checking... */
    if (s->magic != MAGIC)
      basic_error ("dt_load: wrong magic number (%d != %d)\n",
                   s->magic, MAGIC);
    if (dt->bpt != (short) sizeof (Trist_record))
      basic_error ("dt_load: wrong Trist record size (%d != %d)\n",
                   dt->bpt, (short) sizeof (Trist_record));
    if (NOT (    (dt->n == dt->trist->max_org)
             AND (dt->n == dt->num.v + dt->redundant)))
      basic_error ("dt_load: corrupted header\n");
    if (dt->redundant)
      {
        print ("%15d redundant vertices dumped.\n", dt->redundant);
        print ("%15d actual vertices remain.\n", dt->num.v);
      }
    ;
    s->triangle = MALLOC (Trist_record, s->max_triangle + 1);
    binfread (s->triangle, s->max_triangle + 1, f);
    ;
    if (offset > 0)
      {
        dt->sos_offset = offset;
        s->max_org += offset;
        trist_set(s);
        trist_modify_vertices (offset);
        offset = 0;
      }
    else
      dt->sos_offset = 0;
#ifdef __DEBUG__
    trist_io_check (s, dt->num);
#endif
    basic_fclose (f);
  }
  return (dt);
}
Example #21
0
TreeNode* Parser::Statement()
{
	kdDebug(0)<<"Parser::Statement()"<<endl;
	while (currentToken.type == tokEOL) getToken(); // statements can allways start on newlines
	switch (currentToken.type)
	{
		case tokLearn         : return Learn();            break;

		case tokIf            : return If();               break;
		case tokFor           : return For();              break;
		case tokForEach       : return ForEach();          break;
		case tokWhile         : return While();            break;
		case tokRun           : return ExternalRun();      break;
		case tokReturn        : return Return();           break;
		case tokBreak         : return Break();            break;
		case tokUnknown       : return Other();            break; //assignment or function call

		case tokClear         : return Clear();            break;
		case tokGo            : return Go();               break;
		case tokGoX           : return GoX();              break;
		case tokGoY           : return GoY();              break;
		case tokForward       : return Forward();          break;
		case tokBackward      : return Backward();         break;
		case tokDirection     : return Direction();        break;
		case tokTurnLeft      : return TurnLeft();         break;
		case tokTurnRight     : return TurnRight();        break;
		case tokCenter        : return Center();           break;
		case tokSetPenWidth   : return SetPenWidth();      break;
		case tokPenUp         : return PenUp();            break;
		case tokPenDown       : return PenDown();          break;
		case tokSetFgColor    : return SetFgColor();       break;
		case tokSetBgColor    : return SetBgColor();       break;
		case tokResizeCanvas  : return ResizeCanvas();     break;
		case tokSpriteShow    : return SpriteShow();       break;
		case tokSpriteHide    : return SpriteHide();       break;
		case tokSpritePress   : return SpritePress();      break;
		case tokSpriteChange  : return SpriteChange();     break;

		case tokPrint         : return Print();            break;
		case tokInputWindow   : return InputWindow();      break;
		case tokMessage       : return Message();          break;
		case tokFontType      : return FontType();         break;
		case tokFontSize      : return FontSize();         break;
		case tokRepeat        : return Repeat();           break;
		case tokRandom        : return Random();           break;
		case tokWait          : return Wait();             break;
		case tokWrapOn        : return WrapOn();           break;
		case tokWrapOff       : return WrapOff();          break;
		case tokReset         : return Reset();            break;
		
		case tokEOF           : return EndOfFile();        break;
		
		case tokEnd           : Error(currentToken, i18n("Cannot understand ']'"), 1050);
		                        getToken();
		                        return new TreeNode(currentToken, Unknown);
		                        break;

		case tokBegin         : Error(currentToken, i18n("Cannot understand '['"), 1050);
		                        getToken();
		                        return new TreeNode(currentToken, Unknown);
		                        break;

		default               : break;
	}
	if (currentToken.type != tokEnd)
	{
		Error(currentToken, i18n("Cannot understand '%1'").arg(currentToken.look), 1060);
	}

	getToken();
	return new TreeNode(currentToken, Unknown); // fall-though for unknowns
}
Example #22
0
    virtual ResultExpr EvaluateSyscall(int sysno) const override {
        switch (sysno) {
        // Timekeeping
        case __NR_clock_gettime: {
            Arg<clockid_t> clk_id(0);
            return If(clk_id == CLOCK_MONOTONIC, Allow())
                   .ElseIf(clk_id == CLOCK_REALTIME, Allow())
                   .Else(InvalidSyscall());
        }
        case __NR_gettimeofday:
#ifdef __NR_time
        case __NR_time:
#endif
        case __NR_nanosleep:
            return Allow();

        // Thread synchronization
        case __NR_futex:
            // FIXME: This could be more restrictive....
            return Allow();

        // Asynchronous I/O
        case __NR_epoll_wait:
        case __NR_epoll_pwait:
        case __NR_epoll_ctl:
        case __NR_ppoll:
        case __NR_poll:
            return Allow();

        // Used when requesting a crash dump.
        case __NR_pipe:
            return Allow();

            // Metadata of opened files
CASES_FOR_fstat:
            return Allow();

        // Simple I/O
        case __NR_write:
        case __NR_read:
        case __NR_writev: // see SandboxLogging.cpp
            return Allow();

            // Memory mapping
CASES_FOR_mmap:
        case __NR_munmap:
            return Allow();

            // Signal handling
#if defined(ANDROID) || defined(MOZ_ASAN)
        case __NR_sigaltstack:
#endif
CASES_FOR_sigreturn:
CASES_FOR_sigprocmask:
CASES_FOR_sigaction:
            return Allow();

        // Send signals within the process (raise(), profiling, etc.)
        case __NR_tgkill: {
            Arg<pid_t> tgid(0);
            return If(tgid == getpid(), Allow())
                   .Else(InvalidSyscall());
        }

#if defined(ANDROID) && ANDROID_VERSION < 16
        // Polyfill with tgkill; see above.
        case __NR_tkill:
            return Trap(TKillCompatTrap, nullptr);
#endif

        // Yield
        case __NR_sched_yield:
            return Allow();

        // Thread creation.
        case __NR_clone:
            return ClonePolicy();

            // More thread creation.
#ifdef __NR_set_robust_list
        case __NR_set_robust_list:
            return Allow();
#endif
#ifdef ANDROID
        case __NR_set_tid_address:
            return Allow();
#endif

        // prctl
        case __NR_prctl:
            return PrctlPolicy();

        // NSPR can call this when creating a thread, but it will accept a
        // polite "no".
        case __NR_getpriority:
        // But if thread creation races with sandbox startup, that call
        // could succeed, and then we get one of these:
        case __NR_setpriority:
            return Error(EACCES);

        // Stack bounds are obtained via pthread_getattr_np, which calls
        // this but doesn't actually need it:
        case __NR_sched_getaffinity:
            return Error(ENOSYS);

        // Read own pid/tid.
        case __NR_getpid:
        case __NR_gettid:
            return Allow();

        // Discard capabilities
        case __NR_close:
            return Allow();

            // Machine-dependent stuff
#ifdef __arm__
        case __ARM_NR_breakpoint:
        case __ARM_NR_cacheflush:
        case __ARM_NR_usr26: // FIXME: do we actually need this?
        case __ARM_NR_usr32:
        case __ARM_NR_set_tls:
            return Allow();
#endif

        // Needed when being debugged:
        case __NR_restart_syscall:
            return Allow();

        // Terminate threads or the process
        case __NR_exit:
        case __NR_exit_group:
            return Allow();

#ifdef MOZ_ASAN
        // ASAN's error reporter wants to know if stderr is a tty.
        case __NR_ioctl: {
            Arg<int> fd(0);
            return If(fd == STDERR_FILENO, Allow())
                   .Else(InvalidSyscall());
        }

        // ...and before compiler-rt r209773, it will call readlink on
        // /proc/self/exe and use the cached value only if that fails:
        case __NR_readlink:
        case __NR_readlinkat:
            return Error(ENOENT);

            // ...and if it found an external symbolizer, it will try to run it:
            // (See also bug 1081242 comment #7.)
CASES_FOR_stat:
            return Error(ENOENT);
#endif

        default:
            return SandboxPolicyBase::EvaluateSyscall(sysno);
        }
    }
Example #23
0
static bool SIFTDetector(const Image<unsigned char>& I,
  std::vector<SIOPointFeature>& feats,
  std::vector<Descriptor<type,128> >& descs,
  bool bDezoom = false,
  bool bRootSift = false,
  float dPeakThreshold = 0.04f)
{
  // First Octave Index.
  int firstOctave = (bDezoom == true) ? -1 : 0;
  // Number of octaves.
  int numOctaves = 6;
  // Number of scales per octave.
  int numScales = 3;
  // Max ratio of Hessian eigenvalues.
  float edgeThresh = 10.0f;
  // Min contrast.
  float peakThresh = dPeakThreshold;

  int w=I.Width(), h=I.Height();
  //Convert to float
  Image<float> If( I.GetMat().cast<float>() );


  vl_constructor();

  VlSiftFilt *filt = vl_sift_new(w,h,numOctaves,numScales,firstOctave);
  if (edgeThresh >= 0)
    vl_sift_set_edge_thresh(filt, edgeThresh);
  if (peakThresh >= 0)
    vl_sift_set_peak_thresh(filt, 255*peakThresh/numScales);

  vl_sift_process_first_octave(filt, If.data());

  vl_sift_pix descr[128];
  Descriptor<type, 128> descriptor;

  while (true) {
    vl_sift_detect(filt);

    VlSiftKeypoint const *keys  = vl_sift_get_keypoints(filt);
    int nkeys = vl_sift_get_nkeypoints(filt);

    for (int i=0;i<nkeys;++i) {
      double angles [4];
      int	nangles=vl_sift_calc_keypoint_orientations(filt,angles,keys+i);

      for (int q=0 ; q < nangles ; ++q) {
        vl_sift_calc_keypoint_descriptor(filt,descr, keys+i, angles [q]);
        SIOPointFeature fp;
        fp.x() = keys[i].x;
        fp.y() = keys[i].y;
        fp.scale() = keys[i].sigma;
        fp.orientation() = static_cast<float>(angles[q]);

        siftDescToFloat(descr, descriptor, bRootSift);
        descs.push_back(descriptor);
        feats.push_back(fp);
      }
    }
    if (vl_sift_process_next_octave(filt))
      break; // Last octave
  }
  vl_sift_delete(filt);

  vl_destructor();

  return true;
}
Example #24
0
void Print_Polynomial_Extrapolation_Integral_Test() {
   double exact;
   double error;
   double h_next;
   double h_used;
   double x;
   double x_start;
   double x_stop;
   double y0 = a;
   double y1;
   int i;
   int err;
 
   fprintf(out,"\n\n\nGragg_Bulirsch_Stoer Method\n\n");
   fprintf(out,"Problem: Solve y' = xy,\n");
   fprintf(out,"Initial condition x = %4.1lf, y = %4.1lf\n",x0,y0);
   fprintf(out,"Number of steps %d and step size %4.2lf\n",number_of_steps,h);
   fprintf(out,"Polynomial Extrapolation\n\n");
   fprintf(out,"  n     x[n]           Estimate                 Exact");
   fprintf(out,"             Error\n");
   print_line += 10;

               /* Load initial conditions, (y0 is already set) */

   x_start = x0;
   x = x_start;

          /* Call Gragg_Bulirsh_Stoer method 'number_of_steps' times */
          /* with a step size of h. */

   for (i = 0; i < number_of_steps; i++) {

               /* Load initial conditions, (y0 is already set) */

      h_used = h;
      x_stop = x_start + h;

               /* Continue calling Gragg_Bulirsch_Stoer until */
            /* we have finished solving for x = xstart to x = stop */

      do {

         /* If the Gragg_Bulirsch_Stoer Method fails, divide the */
         /* step size used by 4 and try again.                   */

         /* NOTE.  In general you would want to put a counter    */
         /* here and terminate the routine if it fails too many  */
         /* times.                                               */
         
         while (Gragg_Bulirsch_Stoer( f, y0, &y1, x, h_used, &h_next, 1.0,
                                             tolerance, 0)) h_used /= 4.0;
         x += h_used;
         y0 = y1;
         if ( x + h_next > x_stop ) h_used = x + h_next - x_stop;
         else h_used = h_next;
      } while ( x < x_stop - 1.e-10 );
                  
      exact = If(x);
      error = exact - y1;
      fprintf(out,"%3d   %8.2le  %20.15le", i+1, x, y1);
      fprintf(out,"   %20.15le  %+9.4le\n", exact,error);
      print_line++;
      x_start = x;
   }
}
Example #25
0
bool syntaxparser::Statement(){
	bool bStatement = false;
	if (lexeme == "{"){
		bStatement = true;
		if(displayFlag){
			cout << "<Statement> ::= <Compound>" << endl;
			printproduction("<Statement> ::= <Compound>");
		}
		Compound();
	}
	else if (token == "identifier"){
		bStatement = true;
		if(displayFlag){
			cout << "<Statement> ::= <Assign>" << endl;
			printproduction("<Statement> ::= <Assign>");
		}
		Assign();
	}
	else if (lexeme == "if"){
		bStatement = true;
		if(displayFlag){
			cout << "<Statement> ::= <If>" << endl;
			printproduction("<Statement> ::= <If>");
		}
		If();
	}
	else if (lexeme == "return"){
		bStatement = true;

		if(displayFlag){
			cout << "<Statement> ::= <Return>" << endl;
			printproduction("<Statement> ::= <Return>");
		}
		Return();
	}
	else if (lexeme == "write"){
		bStatement = true;
		if(displayFlag){
			cout << "<Statement> ::= <Write>" << endl;
			printproduction("<Statement> ::= <Write>");
		}
		Write();
	}
	else if (lexeme == "read"){
		bStatement = true;

		if(displayFlag){
			cout << "<Statement> ::= <Read>" << endl;
			printproduction("<Statement> ::= <Read>");
		}
		Read();
	}
	else if (lexeme == "while"){
		bStatement = true;

		if(displayFlag){
			cout << "<Statement> ::= <While>" << endl;
			printproduction("<Statement> ::= <While>");
		}
		While();
	}
	return bStatement;
}
Example #26
0
//=========================================================
bool Parser::FreeStatement () {
    PrintRule rule("FreeStatement");
    return rule.Accept(If() || While() || For());
}
void f2_strassen_indexed_v2(uint32_t *p, ipmatrix_t dst, ipmatrix_t a, ipmatrix_t b, ipfree_region_t hFree)
{
    int log2n;
    ipmatrix_t tmp1, tmp2, tmp3, tmp4;
    ipmatrix_t M1, M2, M3, M4, M5, M6, M7;

    // VHLS-HACK : The number of steps made VHLS crash, so some
    // of the lambdas have been cost, at the expense of more memory
    // in use

    run_function_old<void>(
        Sequence(
            If([&](){ return ipmatrix_log2n(a)<=4; },
                [&](){ mul_ipmatrix(p, dst,a,b); },
                Return()
            ),
            [&](){
            log2n=ipmatrix_log2n(a)-1; // Size of ipmatrix_quads

            tmp1=alloc_ipmatrix(hFree, log2n);
            tmp2=alloc_ipmatrix(hFree, log2n);
            tmp3=alloc_ipmatrix(hFree, log2n);
            tmp4=alloc_ipmatrix(hFree, log2n);

            M1=alloc_ipmatrix(hFree, log2n);
            add_ipmatrix(p, tmp1,ipmatrix_quad(a,0,0),ipmatrix_quad(a,1,1));
            add_ipmatrix(p, tmp2,ipmatrix_quad(b,0,0),ipmatrix_quad(b,1,1));

            M2=alloc_ipmatrix(hFree, log2n);
            add_ipmatrix(p, tmp3,ipmatrix_quad(a,1,0),ipmatrix_quad(a,1,1));

            },
            Recurse([&](){ return make_hls_state_tuple( M1,tmp1,tmp2, hFree); }),
            Recurse([&](){ return make_hls_state_tuple( M2,tmp3,ipmatrix_quad(b,0,0), hFree); }),
            [&](){

            M3=alloc_ipmatrix(hFree, log2n);
            sub_ipmatrix(p, tmp1,ipmatrix_quad(b,0,1),ipmatrix_quad(b,1,1));

            M4=alloc_ipmatrix(hFree, log2n);
            sub_ipmatrix(p, tmp2,ipmatrix_quad(b,1,0),ipmatrix_quad(b,0,0));

            },
            Recurse([&](){ return make_hls_state_tuple( M3,ipmatrix_quad(a,0,0),tmp1, hFree); }),
            Recurse([&](){ return make_hls_state_tuple( M4,ipmatrix_quad(a,1,1),tmp2, hFree); }),
            [&](){

            M5=alloc_ipmatrix(hFree, log2n);
            add_ipmatrix(p, tmp1,ipmatrix_quad(a,0,0),ipmatrix_quad(a,0,1));

            },
            Recurse([&](){ return make_hls_state_tuple( M5,tmp1,ipmatrix_quad(b,1,1), hFree); }),
            [&](){

            M6=alloc_ipmatrix(hFree, log2n);
            sub_ipmatrix(p, tmp1,ipmatrix_quad(a,1,0),ipmatrix_quad(a,0,0));
            add_ipmatrix(p, tmp2,ipmatrix_quad(b,0,0),ipmatrix_quad(b,0,1));

            M7=alloc_ipmatrix(hFree, log2n);
            sub_ipmatrix(p, tmp3,ipmatrix_quad(a,0,1),ipmatrix_quad(a,1,1));
            add_ipmatrix(p, tmp4,ipmatrix_quad(b,1,0),ipmatrix_quad(b,1,1));

            },
            Recurse([&](){ return make_hls_state_tuple( M6,tmp1,tmp2, hFree); }),
            Recurse([&](){ return make_hls_state_tuple( M7,tmp3,tmp4, hFree); }),
            [&](){

            add_sub_add_ipmatrix(p, ipmatrix_quad(dst,0,0), M1, M4, M5, M7);
            add_ipmatrix(p, ipmatrix_quad(dst,0,1), M3, M5);
            add_ipmatrix(p, ipmatrix_quad(dst,1,0), M2, M4);
            add_sub_add_ipmatrix(p, ipmatrix_quad(dst,1,1), M1,M3,M2,M6);
            }
        ),
        dst, a, b, hFree,
        log2n, tmp1, tmp2, tmp3, tmp4,
        M1, M2, M3, M4, M5, M6, M7
    );
}
Example #28
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();
}