예제 #1
0
파일: interp.c 프로젝트: daizhihui/tinyBase
/*
 * mk_conditions: converts a list of conditions into an array of conditions
 *
 * Returns:
 *    the lengh of the list on success ( >= 0 )
 *    error code otherwise
 */
static int mk_conditions(NODE *list, int max, Condition conditions[])
{
   int i;
   NODE *current;

   /* for each element of the list... */
   for(i = 0; list != NULL; ++i, list = list -> u.LIST.next){
      /* If the list is too long then error */
      if(i == max)
         return E_TOOMANY;

      current = list -> u.LIST.curr;
      conditions[i].lhsAttr.relName = 
         current->u.CONDITION.lhsRelattr->u.RELATTR.relname;
      conditions[i].lhsAttr.attrName = 
         current->u.CONDITION.lhsRelattr->u.RELATTR.attrname;
      conditions[i].op = current->u.CONDITION.op;
      if (current->u.CONDITION.rhsRelattr) {
         conditions[i].bRhsIsAttr = TRUE;
         conditions[i].rhsAttr.relName = 
            current->u.CONDITION.rhsRelattr->u.RELATTR.relname;
         conditions[i].rhsAttr.attrName = 
            current->u.CONDITION.rhsRelattr->u.RELATTR.attrname;
      }
      else {
         conditions[i].bRhsIsAttr = FALSE;
         mk_value(current->u.CONDITION.rhsValue, conditions[i].rhsValue);
      }
   }

   return i;
}
예제 #2
0
expr copy(expr const & a) {
    switch (a.kind()) {
    case expr_kind::Var:      return mk_var(var_idx(a));
    case expr_kind::Constant: return mk_constant(const_name(a));
    case expr_kind::Type:     return mk_type(ty_level(a));
    case expr_kind::Value:    return mk_value(static_cast<expr_value*>(a.raw())->m_val);
    case expr_kind::App:      return mk_app(num_args(a), begin_args(a));
    case expr_kind::Eq:       return mk_eq(eq_lhs(a), eq_rhs(a));
    case expr_kind::Lambda:   return mk_lambda(abst_name(a), abst_domain(a), abst_body(a));
    case expr_kind::Pi:       return mk_pi(abst_name(a), abst_domain(a), abst_body(a));
    case expr_kind::Let:      return mk_let(let_name(a), let_type(a), let_value(a), let_body(a));
    case expr_kind::MetaVar:  return mk_metavar(metavar_idx(a), metavar_ctx(a));
    }
    lean_unreachable();
}
예제 #3
0
파일: interp.c 프로젝트: daizhihui/tinyBase
/*
 * mk_values: converts a list of values into an array of values
 *
 * Returns:
 *    the lengh of the list on success ( >= 0 )
 *    error code otherwise
 */
static int mk_values(NODE *list, int max, Value values[])
{
   int i;

   /* for each element of the list... */
   for(i = 0; list != NULL; ++i, list = list -> u.LIST.next){
      /* If the list is too long then error */
      if(i == max)
         return E_TOOMANY;

      mk_value(list->u.LIST.curr, values[i]);
   }

   return i;
}
예제 #4
0
파일: interp.c 프로젝트: daizhihui/tinyBase
/*
 * interp: interprets parse trees
 *
 */
RC interp(NODE *n)
{
   RC errval = 0;         /* returned error value      */

   /* if input not coming from a terminal, then echo the query */
   if(!isatty(0))
      echo_query(n);

   switch(n -> kind){

      case N_CREATETABLE:            /* for CreateTable() */
         {
            int nattrs;
            AttrInfo attrInfos[MAXATTRS];

            /* Make sure relation name isn't too long */
            if(strlen(n -> u.CREATETABLE.relname) > MAXNAME){
               print_error((char*)"create", E_TOOLONG);
               break;
            }

            /* Make a list of AttrInfos suitable for sending to Create */
            nattrs = mk_attr_infos(n -> u.CREATETABLE.attrlist, MAXATTRS, 
                  attrInfos);
            if(nattrs < 0){
               print_error((char*)"create", nattrs);
               break;
            }

            /* Make the call to create */
            errval = pSmm->CreateTable(n->u.CREATETABLE.relname, nattrs, 
                  attrInfos);
            break;
         }   

      case N_CREATEINDEX:            /* for CreateIndex() */

         errval = pSmm->CreateIndex(n->u.CREATEINDEX.relname,
               n->u.CREATEINDEX.attrname);
         break;

      case N_DROPINDEX:            /* for DropIndex() */

         errval = pSmm->DropIndex(n->u.DROPINDEX.relname,
               n->u.DROPINDEX.attrname);
         break;

      case N_DROPTABLE:            /* for DropTable() */

         errval = pSmm->DropTable(n->u.DROPTABLE.relname);
         break;

      case N_LOAD:            /* for Load() */

         errval = pSmm->Load(n->u.LOAD.relname,
               n->u.LOAD.filename);
         break;

      case N_SET:                    /* for Set() */

         errval = pSmm->Set(n->u.SET.paramName,
               n->u.SET.string);
         break;

      case N_HELP:            /* for Help() */

         if (n->u.HELP.relname)
            errval = pSmm->Help(n->u.HELP.relname);
         else
            errval = pSmm->Help();
         break;

      case N_PRINT:            /* for Print() */

         errval = pSmm->Print(n->u.PRINT.relname);
         break;

      case N_QUERY:            /* for Query() */
         {
            int       nSelAttrs = 0;
            RelAttr  relAttrs[MAXATTRS];
            int       nRelations = 0;
            char      *relations[MAXATTRS];
            int       nConditions = 0;
            Condition conditions[MAXATTRS];

            /* Make a list of RelAttrs suitable for sending to Query */
            nSelAttrs = mk_rel_attrs(n->u.QUERY.relattrlist, MAXATTRS,
                  relAttrs);
            if(nSelAttrs < 0){
               print_error((char*)"select", nSelAttrs);
               break;
            }

            /* Make a list of relation names suitable for sending to Query */
            nRelations = mk_relations(n->u.QUERY.rellist, MAXATTRS, relations);
            if(nRelations < 0){
               print_error((char*)"select", nRelations);
               break;
            }

            /* Make a list of Conditions suitable for sending to Query */
            nConditions = mk_conditions(n->u.QUERY.conditionlist, MAXATTRS,
                  conditions);
            if(nConditions < 0){
               print_error((char*)"select", nConditions);
               break;
            }

            /* Make the call to Select */
            errval = pQlm->Select(nSelAttrs, relAttrs,
                  nRelations, relations,
                  nConditions, conditions);
            break;
         }   

      case N_INSERT:            /* for Insert() */
         {
            int nValues = 0;
            Value values[MAXATTRS];

            /* Make a list of Values suitable for sending to Insert */
            nValues = mk_values(n->u.INSERT.valuelist, MAXATTRS, values);
            if(nValues < 0){
               print_error((char*)"insert", nValues);
               break;
            }

            /* Make the call to insert */
            errval = pQlm->Insert(n->u.INSERT.relname,
                  nValues, values);
            break;
         }   

      case N_DELETE:            /* for Delete() */
         {
            int nConditions = 0;
            Condition conditions[MAXATTRS];

            /* Make a list of Conditions suitable for sending to delete */
            nConditions = mk_conditions(n->u.DELETE.conditionlist, MAXATTRS,
                  conditions);
            if(nConditions < 0){
               print_error((char*)"delete", nConditions);
               break;
            }

            /* Make the call to delete */
            errval = pQlm->Delete(n->u.DELETE.relname,
                  nConditions, conditions);
            break;
         }   

      case N_UPDATE:            /* for Update() */
         {
            RelAttr relAttr;

            // The RHS can be either a value or an attribute
            Value rhsValue;
            RelAttr rhsRelAttr;
            int bIsValue;

            int nConditions = 0;
            Condition conditions[MAXATTRS];

            /* Make a RelAttr suitable for sending to Update */
            mk_rel_attr(n->u.UPDATE.relattr, relAttr);

            struct node *rhs = n->u.UPDATE.relorvalue;
            if (rhs->u.RELATTR_OR_VALUE.relattr) {
               mk_rel_attr(rhs->u.RELATTR_OR_VALUE.relattr, rhsRelAttr);
               bIsValue = 0;
            } else {
               /* Make a value suitable for sending to update */
               mk_value(rhs->u.RELATTR_OR_VALUE.value, rhsValue);
               bIsValue = 1;
            }

            /* Make a list of Conditions suitable for sending to Update */
            nConditions = mk_conditions(n->u.UPDATE.conditionlist, MAXATTRS,
                  conditions);
            if(nConditions < 0){
               print_error((char*)"update", nConditions);
               break;
            }

            /* Make the call to update */
            errval = pQlm->Update(n->u.UPDATE.relname, relAttr, bIsValue, 
                  rhsRelAttr, rhsValue, nConditions, conditions);
            break;
         }   

      default:   // should never get here
         break;
   }

   return (errval);
}
예제 #5
0
app * float_util::mk_nzero(unsigned ebits, unsigned sbits) {
    scoped_mpf v(fm());
    fm().mk_nzero(ebits, sbits, v);
    return mk_value(v);
}
예제 #6
0
app * float_util::mk_plus_inf(unsigned ebits, unsigned sbits) {
    scoped_mpf v(fm());
    fm().mk_pinf(ebits, sbits, v);
    return mk_value(v);
}
예제 #7
0
app * fpa_util::mk_ninf(unsigned ebits, unsigned sbits) {
    scoped_mpf v(fm());
    fm().mk_ninf(ebits, sbits, v);
    return mk_value(v);
}