当前位置: 首页>>代码示例>>C++>>正文


C++ SExpr类代码示例

本文整理汇总了C++中SExpr的典型用法代码示例。如果您正苦于以下问题:C++ SExpr类的具体用法?C++ SExpr怎么用?C++ SExpr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了SExpr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: compile_error

// Parsing nth argument (output = -1)
pair<string,ProtoType*> ProtoInterpreter::parse_argument(SE_List_iter* i, int n,
                                                         Signature* sig, bool anonymous_ok) {
  SExpr *a = i->get_next("argument");
  SExpr *b = (i->on_token("|")) ? i->get_next("argument") : NULL;
  string name=""; ProtoType* type=NULL;
  if(b) { // specified as name|type
    if(sexp_is_type(a))
      compile_error(a,"Parameter name cannot be a type");
    if(a->isSymbol()) name = dynamic_cast<SE_Symbol &>(*a).name;
    else compile_error(a,"Parameter name not a symbol: "+ce2s(a));
    type = sexp_to_type(b);
  } else { // determine name or type by parsing
    if(sexp_is_type(a)) {
      if(anonymous_ok) type = sexp_to_type(a);
      else compile_error(a,"Function parameters must be named: "+ce2s(a));
    }
    else if(a->isSymbol()) name = dynamic_cast<SE_Symbol &>(*a).name;
    else compile_error(a,"Parameter name not a symbol: "+ce2s(a));
  }
  // fall back to defaults where needed
  if(name=="") name = (n>=0) ? ("arg"+i2s(n)) : "value";
  if(type==NULL) type = new ProtoType();
  // record name in signature and return
  if(sig->names.count(name))
    compile_error(a,"Cannot bind '"+name+"': already bound");
  sig->names[name] = n;
  return make_pair(name,type);
}
开发者ID:chazmatazz,项目名称:proto-mirror,代码行数:29,代码来源:interpreter.cpp

示例2: throw

void SExpr::toStream(std::ostream& out, const SExpr& sexpr, OutputLanguage language, int indent) throw() {
  if( sexpr.isKeyword() && languageQuotesKeywords(language) ){
    out << quoteSymbol(sexpr.getValue());
  } else {
    toStreamRec(out, sexpr, language, indent);
  }
}
开发者ID:g2graman,项目名称:CVC4,代码行数:7,代码来源:sexpr.cpp

示例3: m_env

SExpr* ProtoInterpreter::expand_macro(MacroOperator* m, SE_List* call) {
  Env m_env(this);
  // bind variables to SExprs
  if(!m->signature->legal_length(call->len()-1))
    return sexp_err(call,"Wrong number of arguments for macro "+m->name);
  int i=1; // start after macro name
  for(int j=0;j<m->signature->required_inputs.size();j++) {
    ProtoSymbol* var
      = &dynamic_cast<ProtoSymbol &>(*m->signature->required_inputs[j]);
    m_env.bind(var->value,(*call)[i++]);
  }
  for(int j=0;j<m->signature->optional_inputs.size() && i<call->len();j++) {
    ProtoSymbol* var
      = &dynamic_cast<ProtoSymbol &>(*m->signature->optional_inputs[j]);
    m_env.bind(var->value,(*call)[i++]);
  }
  if(m->signature->rest_input) { // sweep all else into rest argument
    ProtoSymbol* var
      = &dynamic_cast<ProtoSymbol &>(*m->signature->rest_input);
    SE_List *rest = new SE_List(); rest->inherit_attributes(m);
    for(; i<call->len(); ) { rest->add((*call)[i++]); }
    m_env.bind(var->value,rest);
  }
  // then substitute the pattern
  V3 << "Expand macro call:\n"; V3 << call->to_str() << endl;
  SExpr* expanded = macro_substitute(m->pattern,&m_env);
  V3 << "Macro expanded into:\n"; V3 << expanded->to_str() << endl;
  return expanded;
}
开发者ID:chazmatazz,项目名称:proto-mirror,代码行数:29,代码来源:interpreter.cpp

示例4: throw

CVC4::SExpr SmtEngine::getOption(const std::string& key) const
  throw(OptionException) {

  NodeManagerScope nms(d_nodeManager);

  Trace("smt") << "SMT getOption(" << key << ")" << endl;

  if(key.length() >= 18 &&
     key.compare(0, 18, "command-verbosity:") == 0) {
    map<string, Integer>::const_iterator i = d_commandVerbosity.find(key.c_str() + 18);
    if(i != d_commandVerbosity.end()) {
      return (*i).second;
    }
    i = d_commandVerbosity.find("*");
    if(i != d_commandVerbosity.end()) {
      return (*i).second;
    }
    return Integer(2);
  }

  if(Dump.isOn("benchmark")) {
    Dump("benchmark") << GetOptionCommand(key);
  }

  if(key == "command-verbosity") {
    vector<SExpr> result;
    SExpr defaultVerbosity;
    for(map<string, Integer>::const_iterator i = d_commandVerbosity.begin();
        i != d_commandVerbosity.end();
        ++i) {
      vector<SExpr> v;
      v.push_back((*i).first);
      v.push_back((*i).second);
      if((*i).first == "*") {
        // put the default at the end of the SExpr
        defaultVerbosity = v;
      } else {
        result.push_back(v);
      }
    }
    // put the default at the end of the SExpr
    if(!defaultVerbosity.isAtom()) {
      result.push_back(defaultVerbosity);
    } else {
      // ensure the default is always listed
      vector<SExpr> v;
      v.push_back("*");
      v.push_back(Integer(2));
      result.push_back(v);
    }
    return result;
  }

  ${smt_getoption_handlers}

#line 134 "${template}"

  throw UnrecognizedOptionException(key);
}
开发者ID:jgorzny,项目名称:CVC4,代码行数:59,代码来源:smt_options_template.cpp

示例5: pushState

bool Game::pollSource()
{
	if(m_sexprSource == 0)
	{
		return false;
	}

	if(m_sexprSource->sexprReady())
	{
		SExpr sexpr = m_sexprSource->getSExpr();
		
		if(sexpr.type() == NodeType::Unknown)
		{
			return false;
		}
		
		if(sexpr[0] == "status")
		{
			GameState* state = new GameState;
			state->fromSExpr(sexpr);

			pushState(state);
			return true;
		}

        //Ident message
        //("ident" (("0" "MuesAI" "Stephen Mues" "human") ("1" "MuesAI" "Stephen Mues" "zombie")) "0")
		if(sexpr[0] == "ident")
		{
			SExpr ident = sexpr.next().list();
            if(ident.list()[3] == "zombie")
            {
			    m_zombieName = ident.list()[2];
			    m_humanName = ident.next().list()[2];
            }
            else
            {
			    m_humanName = ident.list()[2];
			    m_zombieName = ident.next().list()[2];
            }
		}

		if(sexpr[0] == "notification")
		{
            if(sexpr[1] == Config::instance()->get("user") || atoi(Config::instance()->get("arenaMode").c_str()) > 0)
			{
				cout << "A game was joined by the same player that this visualizer is logged in as" << endl;
                if( atoi(Config::instance()->get("autoJoin").c_str()) > 0 || atoi(Config::instance()->get("arenaMode").c_str()) > 0)
				{
                    cout << "Stopping reader thread" << endl;
					m_nextGame = sexpr[2];
                    Engine::instance()->stopPolling();
					//throw "die";
				}
			}
		}
	}

	return false;
}
开发者ID:,项目名称:,代码行数:60,代码来源:

示例6: throw

void Printer::toStream(std::ostream& out, const SExpr& sexpr) const throw() {
  if(sexpr.isInteger()) {
    out << sexpr.getIntegerValue();
  } else if(sexpr.isRational()) {
    out << fixed << sexpr.getRationalValue().getDouble();
  } else if(sexpr.isKeyword()) {
    out << sexpr.getValue();
  } else if(sexpr.isString()) {
    string s = sexpr.getValue();
    // escape backslash and quote
    for(size_t i = 0; i < s.length(); ++i) {
      if(s[i] == '"') {
        s.replace(i, 1, "\\\"");
        ++i;
      } else if(s[i] == '\\') {
        s.replace(i, 1, "\\\\");
        ++i;
      }
    }
    out << "\"" << s << "\"";
  } else {
    out << '(';
    const vector<SExpr>& kids = sexpr.getChildren();
    bool first = true;
    for(vector<SExpr>::const_iterator i = kids.begin(); i != kids.end(); ++i) {
      if(first) {
        first = false;
      } else {
        out << ' ';
      }
      out << *i;
    }
    out << ')';
  }
}/* Printer::toStream(SExpr) */
开发者ID:xcodevn,项目名称:CVC4,代码行数:35,代码来源:printer.cpp

示例7: if

ProtoType* ProtoInterpreter::sexp_to_type(SExpr* s) {
  if(s->isSymbol()) {
    const string &name = dynamic_cast<SE_Symbol &>(*s).name;
    if(name=="any") { return new ProtoType();
    } else if(name=="local") { return new ProtoLocal();
    } else if(name=="tuple") { return new ProtoTuple();
    } else if(name=="symbol") { return new ProtoSymbol();
    } else if(name=="number") { return new ProtoNumber();
    } else if(name=="scalar") { return new ProtoScalar();
    } else if(name=="boolean") { return new ProtoBoolean();
    } else if(name=="vector") { return new ProtoVector();
    } else if(name=="lambda" || name=="fun") { return new ProtoLambda();
    } else if(name=="field") { return new ProtoField();
    } else { return type_err(s,"Unknown type "+s->to_str());
    }
  } else if(s->isList()) {
    SE_List* sl = &dynamic_cast<SE_List &>(*s);
    if(!sl->op()->isSymbol()) 
      return type_err(s,"Compound type must start with symbol: "+ce2s(s));
    const string &name = dynamic_cast<SE_Symbol &>(*sl->op()).name;
    if(name=="tuple" || name=="vector") {
      ProtoTuple* t;
      if(name=="tuple") t=new ProtoTuple(true); else t=new ProtoVector(true);
      for(int i=1;i<sl->len();i++) {
        SExpr* subex = (*sl)[i];
        if(subex->isSymbol()
           && dynamic_cast<SE_Symbol &>(*subex).name=="&rest") {
          t->bounded=false; continue;
        }
        ProtoType* sub = sexp_to_type(subex);
        if(name=="vector" && !sub->isA("ProtoScalar"))
          return type_err(sl,"Vectors must contain only scalars");
        t->types.push_back(sub);
      }
      return t;
    } else if(name=="lambda" || name=="fun") {
      if(sl->len()!=3) return type_err(s,"Bad lambda type: "+s->to_str());
      Signature* sig = sexp_to_sig((*sl)[1]);
      sig->output = sexp_to_type((*sl)[2]);
      return new ProtoLambda(new Operator(s,sig));
    } else if(name=="field") {
      if(sl->len()!=2) return type_err(s,"Bad field type: "+s->to_str());
      ProtoType* sub = sexp_to_type((*sl)[1]);
      if(sub->isA("ProtoField")) 
        return type_err(s,"Field type must have a local subtype");
      return new ProtoField(sub);
    } else {
      return type_err(s,"Unknown type "+s->to_str());
    }
  } else { // scalars specify ProtoScalar literals
    return new ProtoScalar(dynamic_cast<SE_Scalar &>(*s).value);
  }
}
开发者ID:chazmatazz,项目名称:proto-mirror,代码行数:53,代码来源:interpreter.cpp

示例8: parse_primitive_attributes

// Parse the extra arguments of a primitive into attributes
void parse_primitive_attributes(SE_List_iter* li,Primitive* p) {
  while(li->has_next()) {
    SExpr* v = li->get_next();
    if(!v->isKeyword()) {compile_error(v,v->to_str()+" not a keyword"); return;}
    const string &name = dynamic_cast<SE_Symbol &>(*v).name;
    if(p->attributes.count(name))
      compile_warn("Primitive "+p->name+" overriding duplicate '"
                   +name+"' attribute");
    if(li->has_next() && !li->peek_next()->isKeyword()) {
      p->attributes[name]=new SExprAttribute(li->get_next());
    } else {
      p->attributes[name]=new MarkerAttribute(true);
    }
  }
}
开发者ID:chazmatazz,项目名称:proto-mirror,代码行数:16,代码来源:interpreter.cpp

示例9: make_gensym

// walks through, copying (and inheriting attributes)
SExpr* ProtoInterpreter::macro_substitute(SExpr* src, Env* e, SE_List* wrapper) {
  if(is_gensym(src)) { // substitute with a gensym for this instance
    SE_Symbol *groot = &dynamic_cast<SE_Symbol &>(*src);
    SExpr *gensym;
    CompilationElement *element = e->lookup(groot->name);
    if (element == 0) {
      gensym = make_gensym(groot->name);
      gensym->inherit_attributes(src);
      e->bind(groot->name, gensym);
    } else {
      gensym = &dynamic_cast<SExpr &>(*element);
    }
    return gensym;
  } else if(src->isList()) { // SE_List
    SE_List *srcl = &dynamic_cast<SE_List &>(*src);
    string opname
      = ((*srcl)[0]->isSymbol() ? dynamic_cast<SE_Symbol &>(*(*srcl)[0]).name
         : "");
    if(opname=="comma") {
      if(srcl->len()!=2 || !(*srcl)[1]->isSymbol())
        return sexp_err(src,"Bad comma form: "+src->to_str());
      SE_Symbol* sn = &dynamic_cast<SE_Symbol &>(*(*srcl)[1]);
      // insert source text
      return dynamic_cast<SExpr &>(*e->lookup(sn,"SExpr")).copy();
    } else if(opname=="comma-splice") {
      if(wrapper==NULL)
        return sexp_err(src,"Comma-splice "+(*srcl)[0]->to_str()+" w/o list");
      if(srcl->len()!=2 || !(*srcl)[1]->isSymbol())
        return sexp_err(src,"Bad comma form: "+src->to_str());
      SE_Symbol* sn = &dynamic_cast<SE_Symbol &>(*(*srcl)[1]);
      SE_List* value = &dynamic_cast<SE_List &>(*e->lookup(sn,"SE_List"));
      for(int i=0;i<value->len();i++) 
        wrapper->add((*value)[i]->copy());
      return NULL; // comma-splices return null
    } else { // otherwise, just substitute each child
      SE_List *l = new SE_List();
      SE_List *srcl = &dynamic_cast<SE_List &>(*src);
      for(int i=0;i<srcl->len();i++) {
        SExpr* sub = macro_substitute((*srcl)[i],e,l);
        if(sub!=NULL) l->add(sub); // comma-splices add selves and return null
      }
      return l;
    }
  } else { // symbol or scalar
    return src->copy();
  }
}
开发者ID:chazmatazz,项目名称:proto-mirror,代码行数:48,代码来源:interpreter.cpp

示例10: scope

void SExpr::toStreamRec(std::ostream& out, const SExpr& sexpr,
                        OutputLanguage language, int indent) {
  StreamFormatScope scope(out);

  if (sexpr.isInteger()) {
    out << sexpr.getIntegerValue();
  } else if (sexpr.isRational()) {
    const double approximation = sexpr.getRationalValue().getDouble();
    out << std::fixed << approximation;
  } else if (sexpr.isKeyword()) {
    out << sexpr.getValue();
  } else if (sexpr.isString()) {
    std::string s = sexpr.getValue();
    // escape backslash and quote
    for (size_t i = 0; i < s.length(); ++i) {
      if (s[i] == '"') {
        s.replace(i, 1, "\\\"");
        ++i;
      } else if (s[i] == '\\') {
        s.replace(i, 1, "\\\\");
        ++i;
      }
    }
    out << "\"" << s << "\"";
  } else {
    const std::vector<SExpr>& kids = sexpr.getChildren();
    out << (indent > 0 && kids.size() > 1 ? "( " : "(");
    bool first = true;
    for (std::vector<SExpr>::const_iterator i = kids.begin(); i != kids.end();
         ++i) {
      if (first) {
        first = false;
      } else {
        if (indent > 0) {
          out << "\n" << std::string(indent, ' ');
        } else {
          out << ' ';
        }
      }
      toStreamRec(out, *i, language,
                  indent <= 0 || indent > 2 ? 0 : indent + 2);
    }
    if (indent > 0 && kids.size() > 1) {
      out << '\n';
      if (indent > 2) {
        out << std::string(indent - 2, ' ');
      }
    }
    out << ')';
  }
} /* toStreamRec() */
开发者ID:CVC4,项目名称:CVC4,代码行数:51,代码来源:sexpr.cpp

示例11: convertInvoke

 SExpr convertInvoke(const SExpr& invoke) {
     std::string resultString = "call " + currentModule_->exportedFunction(invoke[1].value())->name() + " ";
     for (std::size_t i = 2; i < invoke.children().size(); i++) {
         resultString += invoke[i].toString();
         resultString += " ";
     }
     SExpr result = SExprParser::parseString(resultString);
     return result;
 }
开发者ID:WebAssembly,项目名称:wasmint,代码行数:9,代码来源:main.cpp

示例12: ArithRRNode

 SExpr* SPrimScope::inlineEQ() {
   if (PrintInlining) lprintf("%*s*inlining _Eq\n", (void*)(depth-1), ""); 
   NodeGen* ng = theNodeGen;
   if (SICDebug) ng->comment("inlined _Eq");
   SExpr* arg = args->top();
   PReg* r  = receiver->preg();
   PReg* ar = arg->preg();
   ng->append(new ArithRRNode(SubCCArithOp, r, ar, ng->noPR));
   Node* test = ng->append(new BranchNode(EQBranchOp));
   Node* falseNode;
   test->append(falseNode = new AssignNode(falsePR(), resultPR));
   SExpr* e1 = new ConstantSExpr(Memory->falseObj, resultPR, falseNode);
   MergeNode* merge = new MergeNode("inlineEQ merge");
   falseNode->append(merge);
   Node* trueNode = new AssignNode(truePR(), resultPR);
   ng->current = test->append1(trueNode);
   SExpr* e2 = new ConstantSExpr(Memory->trueObj, resultPR, trueNode);
   ng->branch(merge);
   SExpr* res = e1->copyMergeWith(e2, resultPR, ng->current);
   return res;
 }
开发者ID:AaronNGray,项目名称:self,代码行数:21,代码来源:sicPrimline.cpp

示例13: getChildren

bool SExpr::operator==(const SExpr& s) const {
  if (d_sexprType == s.d_sexprType && d_integerValue == s.d_integerValue &&
      d_rationalValue == s.d_rationalValue &&
      d_stringValue == s.d_stringValue) {
    if (d_children == NULL && s.d_children == NULL) {
      return true;
    } else if (d_children != NULL && s.d_children != NULL) {
      return getChildren() == s.getChildren();
    }
  }
  return false;
}
开发者ID:CVC4,项目名称:CVC4,代码行数:12,代码来源:sexpr.cpp

示例14: Unused

 lookupTarget* sicScopeLookupTarget::get_target_for_slot(slotDesc* s,
                                                         simpleLookup* L) {
   Unused(L);
   if (s->name == VMString[LEXICAL_PARENT]) {
     return new sicScopeLookupTarget(scope->parent());
   } else if (s->name == VMString[SELF]) {
     SExpr* t = scope->receiverExpr();
     if (t->isConstantSExpr()) {
       return (new objectLookupTarget(t->constant())) -> be_receiver();
     } else if (t->hasMap()) {
       return ( new mapLookupTarget(t->map())) -> be_receiver();
     } else {
       // don't know the receiver type
       return NULL;
     }
   } else if (! s->is_map_slot()) {
     return NULL;
   } else {
     return new objectLookupTarget(s->data);
   }
 }
开发者ID:ardeujho,项目名称:self,代码行数:21,代码来源:target.cpp

示例15: opcode_for_selector

  SExpr* SPrimScope::inlineIntArithmetic() {
    ArithOpCode op = opcode_for_selector(_selector);
      
    bool intRcvr =
      receiver->hasMap() && receiver->map() == Memory->smi_map;
    SExpr* arg = args->nth(0);
    bool intArg = arg->hasMap() && arg->map() == Memory->smi_map;
    if ( intArg
    &&   arg->isConstantSExpr()
    &&   intRcvr
    &&   arg->constant() == as_smiOop(0)
    &&   can_fold_rcvr_op_zero_to_zero(op)) {
      if (PrintInlining)
        lprintf("%*s*constant-folding %s: 0\n", (void*)(depth-1), "", ArithOpName[op]);
      return receiver;
    }
    if (PrintInlining) lprintf("%*s*inlining %s:\n", (void*)(depth-1),
                               "", ArithOpName[op]);

    if (!TArithRRNode::isOpInlinable(op))
      return NULL;
      
    NodeGen* n = theNodeGen;
    Node* arith = n->append(new TArithRRNode(op, receiver->preg(), arg->preg(),
                                             resultPR, intRcvr, intArg));

    // success case - no overflow, int tags
    MergeNode* ok = (MergeNode*)n->append(new MergeNode("inlineIntArithmetic ok"));
    SExpr* succExpr = new MapSExpr(Memory->smi_map->enclosing_mapOop(), resultPR, ok);
    // merge of success & failure branches
    MergeNode* done = (MergeNode*)ok->append(new MergeNode("inlineIntArithmetic done"));

    // failure case
    n->current = arith->append1(new NopNode);
    if (theSIC->useUncommonTraps &&
        sender()->rscope->isUncommonAt(sender()->bci(), true)) {
      n->uncommonBranch(currentExprStack(0), true);
      n->current = done;
      if (PrintInlining) {
        lprintf("%*s*making arithmetic failure uncommon\n", (void*)(depth-1),
                "");
      }
      return succExpr;
    } else {
      fint b = bci();
      PReg* error = new SAPReg(_sender, b, b);
      if (intRcvr && intArg) {
        // must be overflow
        n->loadOop(VMString[OVERFLOWERROR], error);
      } else {
        arith->hasSideEffects_now = true;    // may fail, so can't eliminate
        if (intRcvr || TARGET_ARCH == I386_ARCH) {
          // arg & TagMask already done by TArithRRNode
          // I386 does 'em all
        } else {
          PReg* t = new TempPReg(this, Temp1, false, true);
          n->append(new ArithRCNode(AndCCArithOp, t, Tag_Mask, t));
          n->current->hasSideEffects_now = true;
        }
        // Note: this code assumes that condcode EQ means overflow
        Node* branch = n->append(new BranchNode(EQBranchOp));
        // no overflow, must be type error
        n->loadOop(VMString[BADTYPEERROR], error);
        MergeNode* cont = (MergeNode*)n->append(
          new MergeNode("inlineIntArithmetic cont"));
        // overflow error
        PReg* err = new_ConstPReg(_sender, VMString[OVERFLOWERROR]);
        n->current = branch->append1(new AssignNode(err, error));
        n->branch(cont);
      }
      Node* dummy;
      SExpr* failExpr = genPrimFailure(NULL, error, dummy, done, resultPR);
      assert(done, "merge should always exist");
      return succExpr->mergeWith(failExpr, done);
    }
  }
开发者ID:AaronNGray,项目名称:self,代码行数:76,代码来源:sicPrimline.cpp


注:本文中的SExpr类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。