Esempio n. 1
0
ValuePtr
apply(EnvPtr env, ValuePtr procedure, ValuePtr args)
{
  if(procedure->type() == Value::NATIVE_PROCEDURE) {
    NativeProcedureValue* proc = static_cast<NativeProcedureValue*>(procedure.mValue);
    return (*proc->mProc)(env, args);
  }
  else if(procedure->type() == Value::PROCEDURE) {
    EnvPtr callEnvironment = new Environment;
    ProcedureValue* proc = static_cast<ProcedureValue*>(procedure.mValue);
    callEnvironment->parent = proc->environment;
    int iParam = 0;
    while(args->isNull() == false) {
      if(iParam == static_cast<int>(proc->paramList.size())) {
        CHECK_FAIL("Too many arguments to procedure");
      }
      callEnvironment->values[proc->paramList[iParam]] = args->car();
      iParam++;
      args = args->cdr();
    }
    if(iParam != static_cast<int>(proc->paramList.size())) {
      CHECK_FAIL("Too few arguments to procedure");
    }
    return evalSequence(callEnvironment, proc->body);
  }
  else {
    sWrite(env, new PairValue(procedure, new PairValue()));
    CHECK_FAIL("Wrong type of argument to apply: not procedure");
    return NULL;
  }  
  
}
Esempio n. 2
0
bool
sEqP(ValuePtr lhs, ValuePtr rhs)
{
  if(lhs->type() != rhs->type()) return false;
  if(lhs->isBool() && lhs->vBool() == rhs->vBool()) return true;
  else if(lhs->isNumber() && lhs->isExact() && rhs->isExact() && lhs->vInt() == rhs->vInt()) return true;
  else if(lhs->isNumber() && !lhs->isExact() && !rhs->isExact() && lhs->vFloat() == rhs->vFloat()) return true;
  else if(lhs->isString() && string(lhs->vString()) == string(rhs->vString())) return true;
  else if(lhs->isSymbol() && string(lhs->vString()) == string(rhs->vString())) return true;
  else if(lhs->isPair() && (lhs == rhs || (lhs->isNull() && rhs->isNull()))) return true;
  else if(lhs->isProcedure() && (lhs.mValue == rhs.mValue)) return true;
  else if(lhs->type() == Value::UNDEFINED) return false;
  return false;
}
Esempio n. 3
0
void fromValue(ValuePtr value,
	       int* type,
	       double* scalar,
	       ValueRangePtr** ranges,	
	       int* rangeLen,
	       StdStringPtr** strings,
	       int* stringsLen,
	       char** text,
	       int* textLen)
{
  Value_Type t = value->type();
  *type = (int) t;
  if (t == Value_Type_SCALAR)
    {
      *scalar = value->mutable_scalar()->value();
    }
  else if (t == Value_Type_RANGES)
    {
      *rangeLen = value->mutable_ranges()->range_size();
      *ranges = value->mutable_ranges()->mutable_range()->mutable_data();
    }
  else if (t == Value_Type_SET)
    {
      *stringsLen = value->set().item_size();
      *strings = value->mutable_set()->mutable_item()->mutable_data();
    }
  else if (t == Value_Type_TEXT)
    {
      std::string* txt = value->mutable_text()->mutable_value();
      *text = (char*) txt->data();
      *textLen = txt->size();
    }
}
Esempio n. 4
0
    void DisassemblerContext::setup_term(const ValuePtr<>& term) {
      if (!m_visited_terms.insert(term).second)
        return;

      setup_term_name(term);
      
      switch (term->term_type()) {
      case term_apply: {
        ValuePtr<ApplyType> apply = value_cast<ApplyType>(term);
        setup_term(apply->recursive());
        for (std::vector<ValuePtr<> >::const_iterator ii = apply->parameters().begin(), ie = apply->parameters().end(); ii != ie; ++ii)
          setup_term(*ii);
        break;
      }
      
      case term_exists: {
        ValuePtr<Exists> exists = value_cast<Exists>(term);
        setup_term(exists->result());
        break;
      }
        
      case term_parameter_placeholder:
      case term_recursive_parameter: {
        setup_term(term->type());
        break;
      }
        
      case term_functional: {
        class MyVisitor : public FunctionalValueVisitor {
          DisassemblerContext *m_self;
        public:
          MyVisitor(DisassemblerContext *self) : m_self(self) {}
          virtual void next(const ValuePtr<>& v) {if (v) m_self->setup_term(v);}
        };
        
        MyVisitor my_visitor(this);
        value_cast<FunctionalValue>(term)->functional_visit(my_visitor);
        break;
      }
        
      case term_function_type: {
        ValuePtr<FunctionType> cast_term = value_cast<FunctionType>(term);
        const std::vector<ParameterType>& parameter_types = cast_term->parameter_types();
        for (std::vector<ParameterType>::const_iterator ii = parameter_types.begin(), ie = parameter_types.end(); ii != ie; ++ii)
          setup_term(ii->value);
        setup_term(cast_term->result_type().value);
        break;
      }
      
      default:
        return; // Skip adding to definition list
      }
      
      if (TermDefinitionList *dl = term_definition_list(term))
        dl->push_back(term);
    }
Esempio n. 5
0
 void DisassemblerContext::print_phi_term(const ValuePtr<Phi>& term) {
   *m_output << "phi ";
   print_term(term->type(), true);
   *m_output << ": ";
   const std::vector<PhiEdge>& edges = term->edges();
   bool first = true;
   for (std::vector<PhiEdge>::const_iterator ii = edges.begin(), ie = edges.end(); ii != ie; ++ii) {
     if (first)
       first = false;
     else
       *m_output << ", ";
     *m_output << name(ii->block) << " > ";
     print_term(ii->value, true);
   }
   *m_output << ";\n";
 }
Esempio n. 6
0
AttributePtr toAttribute(char* name,
			 int nameLen,
			 ValuePtr value)
{
  AttributePtr attribute = new Attribute();
  attribute->set_name(name, nameLen);
  attribute->set_type(value->type());
  if (value->has_scalar())
    *attribute->mutable_scalar() = *value->mutable_scalar();
  if (value->has_ranges())
    *attribute->mutable_ranges() = *value->mutable_ranges();
  if (value->has_set())
    *attribute->mutable_set() = *value->mutable_set();
  if (value->has_text())
    *attribute->mutable_text() = *value->mutable_text();
  return attribute;
}
Esempio n. 7
0
void ParameterText::onChanged(QString)
{
	if (object->dvt == Value::STRING) {
		object->value = ValuePtr(lineEdit->text().toStdString());
	}
	else {
		ModuleContext ctx;
		shared_ptr<Expression> params = CommentParser::parser(lineEdit->text().toStdString().c_str());
		if (!params) return;
		ValuePtr newValue = params->evaluate(&ctx);
		if (object->dvt == newValue->type()) {
			object->value = newValue;
		}
	}
	object->focus = true;
	emit changed();
}
Item *ItemReaderASTVisitor::targetItemForBinding(const QStringList &bindingName,
                                                 const JSSourceValueConstPtr &value)
{
    Item *targetItem = m_item;
    const int c = bindingName.count() - 1;
    for (int i = 0; i < c; ++i) {
        ValuePtr v = targetItem->properties().value(bindingName.at(i));
        if (!v) {
            Item *newItem = Item::create(m_itemPool);
            v = ItemValue::create(newItem);
            targetItem->setProperty(bindingName.at(i), v);
        }
        if (Q_UNLIKELY(v->type() != Value::ItemValueType)) {
            QString msg = Tr::tr("Binding to non-item property.");
            throw ErrorInfo(msg, value->location());
        }
        targetItem = v.staticCast<ItemValue>()->item();
    }
    return targetItem;
}
Esempio n. 9
0
void ParameterExtractor::setParameters(const FileModule* module)
{
  if (!module) return;

  ModuleContext ctx;

  ParameterPos.clear();
  for (auto &assignment : module->scope.assignments) {
    const Annotation *param = assignment.annotation("Parameter");
    if (!param) continue;

    const ValuePtr defaultValue = assignment.expr->evaluate(&ctx);
    if (defaultValue->type() == Value::UNDEFINED) continue;

    ParameterObject *entryObject = new ParameterObject();
    entryObject->setAssignment(&ctx, &assignment, defaultValue);

    //check whether object exist or not previously
    if (entries.find(assignment.name) == entries.end() || resetPara) {

      //if object doen't exist
      //or we have reset Parameters then add new entry
      entries[assignment.name] = entryObject;
    } else {
      //if entry object is already exist we check if its modified
      //or not
      if (*entryObject == *entries[assignment.name]) {
        //if entry is not modified then we don't add new entry
        entryObject = entries[assignment.name];
      } else {
        //if entry is modified then we add new entry
        entries[assignment.name] = entryObject;
      }
    }
    entryObject->set = true;
    ParameterPos.push_back(assignment.name);
  }
  connectWidget();
  this->resetPara = false;
}
Esempio n. 10
0
Property::Property(const std::string& name, ValuePtr value)
	: m_name(name)
	, m_value(value)
	, m_type(value->type())
{
}
Esempio n. 11
0
void Property::setValue(ValuePtr value)
{
	m_value = value;
	if(value)
		m_type = value->type();
}
Esempio n. 12
0
    void DisassemblerContext::setup_term_definition(const ValuePtr<>& term) {
      if (!m_defined_terms.insert(term).second)
        return;
      
      setup_term_name(term);

      switch (term->term_type()) {
      case term_recursive: {
        ValuePtr<RecursiveType> recursive = value_cast<RecursiveType>(term);
        for (RecursiveType::ParameterList::const_iterator ii = recursive->parameters().begin(), ie = recursive->parameters().end(); ii != ie; ++ii) {
          setup_term_name(*ii);
          setup_term((*ii)->type());
        }
        if (recursive->result())
          setup_term(recursive->result());
        break;
      }
        
      case term_global_variable: {
        ValuePtr<GlobalVariable> gvar = value_cast<GlobalVariable>(term);
        setup_term(gvar->value_type());
        if (gvar->value())
          setup_term(gvar->value());
        break;
      }
      
      case term_function: {
        ValuePtr<Function> function = value_cast<Function>(term);
        setup_function(function);
        break;
      }
      
      case term_function_parameter: {
        ValuePtr<FunctionParameter> param = value_cast<FunctionParameter>(term);
        setup_term(param->type());
        break;
      }
      
      case term_instruction: {
        class MyVisitor : public InstructionVisitor {
          DisassemblerContext *m_self;
        public:
          MyVisitor(DisassemblerContext *self) : m_self(self) {}
          virtual void next(ValuePtr<>& v) {if (v) m_self->setup_term(v);}
        };
        
        MyVisitor my_visitor(this);
        ValuePtr<Instruction> insn = value_cast<Instruction>(term);
        insn->instruction_visit(my_visitor);
        m_local_definitions[insn->block()].push_back(insn);
        break;
      }
      
      case term_phi: {
        ValuePtr<Phi> phi = value_cast<Phi>(term);
        const std::vector<PhiEdge>& edges = phi->edges();
        for (std::vector<PhiEdge>::const_iterator ii = edges.begin(), ie = edges.end(); ii != ie; ++ii) {
          setup_term(ii->block);
          setup_term(ii->value);
        }
        break;
      }
      
      default:
        setup_term(term);
        break;
      }
    }