Example #1
0
int VRPyBase::pySize(PyObject* v) {
    if (VRPyVec2f::check(v)) return 2;
    if (VRPyVec3f::check(v)) return 3;
    if (isList(v)) return PyList_Size(v);
    if (isTuple(v)) return PyTuple_Size(v);
    return 0;
}
Example #2
0
Tuple&
Value::toTuple()
{
    if (not isTuple()) {
        throw utils::CastError(_("Value is not a tuple"));
    }
    return static_cast<Tuple&>(*this);
}
Example #3
0
File: eqml.cpp Project: krant/eqml
	eqmlTerm(const char * buf, int index = 0) : _buf(buf), _index(index)
	{
		if (index == 0)
			ei_decode_version(_buf, &_index, NULL);

		ei_get_type(_buf, &_index, &_type, &_size);
		
		if (isTuple())
			ei_decode_tuple_header(_buf, &_index, &_arity);
	}
Example #4
0
vector<ofxPythonObject> ofxPythonObject::asVector() const
{
	std::vector<ofxPythonObject> v;
	if(isList())
	{
		int len = PyList_Size(get()->obj);
		for (int i = 0; i<len; ++i)
		{
			v.push_back(make_object_borrowed(PyList_GetItem(get()->obj,i)));
		}
	}
	else if(isTuple())
	{
		int len = PyTuple_Size(get()->obj);
		for (int i = 0; i<len; ++i)
		{
			v.push_back(make_object_borrowed(PyTuple_GetItem(get()->obj,i)));
		}
	}
	return v;
}
Example #5
0
/**
Parse a host/magic constant reference
*/
Tuple parseHostRef(Input* input)
{
    // Parse the identifier name
    auto ident = parseIdentStr(input);
    auto name = (std::string)ident;

    try
    {
        auto hostVal = getHostDef(name);

        if (hostVal.isTuple())
            return (Tuple)hostVal;

        return Tuple{
            Tuple("value"),
            hostVal 
        };
    }
    catch (...)
    {
        throw ParseError(input, "unresolved host definition \"" + name + "\"");
    }
}
Example #6
0
File: type.cpp Project: jinala/CVC4
TupleType::TupleType(const Type& t) throw(IllegalArgumentException)
    : Type(t) {
  PrettyCheckArgument(isNull() || isTuple(), this);
}
Example #7
0
const pytuple* pybase::asTuple() const {
	assert(isTuple());
	return (reinterpret_cast<const pytuple*>(this));
}
Example #8
0
PyObject* VRPyBase::getItem(PyObject* v, int i) {
    if (i < 0 || i >= pySize(v)) return 0;
    if (isList(v)) return PyList_GetItem(v,i);
    if (isTuple(v)) return PyTuple_GetItem(v,i);
    return 0;
}
Example #9
0
vector<PyObject*> VRPyBase::pyListToVector(PyObject *v) {
    vector<PyObject*> res;
    if(isList(v))  for (int i=0; i<pySize(v); i++) res.push_back(PyList_GetItem(v, i));
    if(isTuple(v)) for (int i=0; i<pySize(v); i++) res.push_back(PyTuple_GetItem(v, i));
    return res;
}
Example #10
0
LLFunction* DtoInlineIRFunction(FuncDeclaration* fdecl)
{
    const char* mangled_name = mangleExact(fdecl);
    TemplateInstance* tinst = fdecl->parent->isTemplateInstance();
    assert(tinst);

    Objects& objs = tinst->tdtypes;
    assert(objs.dim == 3);

    Expression* a0 = isExpression(objs[0]);
    assert(a0);
    StringExp* strexp = a0->toStringExp();
    assert(strexp);
    assert(strexp->sz == 1);
    std::string code(static_cast<char*>(strexp->string), strexp->len);

    Type* ret = isType(objs[1]);
    assert(ret);

    Tuple* a2 = isTuple(objs[2]);
    assert(a2);
    Objects& arg_types = a2->objects;

    std::string str;
    llvm::raw_string_ostream stream(str);
    stream << "define " << *DtoType(ret) << " @" << mangled_name << "(";

    for(size_t i = 0; ;)
    {
        Type* ty = isType(arg_types[i]);
        //assert(ty);
        if(!ty)
        {
            error(tinst->loc,
                "All parameters of a template defined with pragma llvm_inline_ir, except for the first one, should be types");
            fatal();
        }
        stream << *DtoType(ty);

        i++;
        if(i >= arg_types.dim)
            break;

        stream << ", ";
    }

    if(ret->ty == Tvoid)
        code.append("\nret void");

    stream << ")\n{\n" << code <<  "\n}";

    llvm::SMDiagnostic err;

#if LDC_LLVM_VER >= 306
    std::unique_ptr<llvm::Module> m = llvm::parseAssemblyString(
        stream.str().c_str(), err, gIR->context());
#elif LDC_LLVM_VER >= 303
    llvm::Module* m = llvm::ParseAssemblyString(
        stream.str().c_str(), NULL, err, gIR->context());
#else
    llvm::ParseAssemblyString(
        stream.str().c_str(), gIR->module, err, gIR->context());
#endif

    std::string errstr = err.getMessage();
    if(errstr != "")
        error(tinst->loc,
            "can't parse inline LLVM IR:\n%s\n%s\n%s\nThe input string was: \n%s",
#if LDC_LLVM_VER >= 303
            err.getLineContents().str().c_str(),
#else
            err.getLineContents().c_str(),
#endif
            (std::string(err.getColumnNo(), ' ') + '^').c_str(),
            errstr.c_str(), stream.str().c_str());

#if LDC_LLVM_VER >= 306
    llvm::Linker(gIR->module).linkInModule(m.get());
#else
#if LDC_LLVM_VER >= 303
    std::string errstr2 = "";
#if LDC_LLVM_VER >= 306
    llvm::Linker(gIR->module).linkInModule(m.get(), &errstr2);
#else
    llvm::Linker(gIR->module).linkInModule(m, &errstr2);
#endif
    if(errstr2 != "")
        error(tinst->loc,
            "Error when linking in llvm inline ir: %s", errstr2.c_str());
#endif
#endif

    LLFunction* fun = gIR->module->getFunction(mangled_name);
    fun->setLinkage(llvm::GlobalValue::LinkOnceODRLinkage);
    fun->addFnAttr(LDC_ATTRIBUTE(AlwaysInline));
    return fun;
}