static JudgmentOnValueTree* treeFromList(boost::python::object inList)
		{
		//generic iterator...
		boost::python::object it = inList.attr("__iter__")();

		ImmutableTreeVector<pair<JudgmentOnValueTuple, uword_t> > jovts;

		try {
			while(1)
				{
				boost::python::object val = it.attr("next")();

				boost::python::extract<JudgmentOnValueTuple> e(val);

				if (!e.check())
					throw std::logic_error(
						"List arguments to JudgmentOnValueTree::__init__ must be JOVTs"
						);

				jovts = jovts + make_pair(e(), jovts.size());
				}
			}
		catch(...)
			{
			PyErr_Clear();
			}

		return new JudgmentOnValueTree(
			createJOVTreeRule(
				jovts,
				EqualFrequency()
				)
			);
		}
		static ImmutableTreeVector<T> slice(ImmutableTreeVector<T>& in, boost::python::slice s)
			{
			int32_t start = boost::python::extract<int32_t>(s.start());
			if (start < 0)
				start = in.size() - start;

			int32_t stop = boost::python::extract<int32_t>(s.stop());
			if (stop < 0)
				stop = in.size() - stop;

			return in.slice(start, stop);
			}
Example #3
0
NativeType nativeTypeForCppmlTuple()
	{
	//get a list of types and offsets into the tuple
	ImmutableTreeVector<pair<NativeType, uword_t> > offsets = 
		NativeTypeForCppmlTupleImpl<T, typename T::metadata>::get();

	NativeType resultType = NativeType::Composite();

	//build up the tuple type one field at a time
	for (long k = 0; k < offsets.size();k++)
		{
		if (offsets[k].second == resultType.packedSize())
			resultType = resultType + offsets[k].first;
			else
		if (offsets[k].second < resultType.packedSize())
			{
			//the sizes should have been linearly increasing
			lassert_dump(false, "inconsistent typing found: " + prettyPrintString(offsets));
			}
		else
			{
			//add enough padding to compensate for the extra bytes that C++ places in between
			//members to get alignment
			resultType = resultType + 
				NativeType::Composite(
					NativeType::Array(
						NativeType::Integer(8,false),
						offsets[k].second - resultType.packedSize()
						)
					);

			resultType = resultType + offsets[k].first;
			}
		}

	lassert(resultType.packedSize() <= sizeof(T));

	if (resultType.packedSize() < sizeof(T))
		resultType = resultType + 
			NativeType::Composite(
				NativeType::Array(
					NativeType::Integer(8,false),
					sizeof(T) - resultType.packedSize()
					)
				);

	return resultType;
	}
		static typename ImmutableTreeWrapperRetType<T>::res_type getVal(ImmutableTreeVector<T>& self, int32_t ix)
			{
			if (ix >= 0 && ix < self.size())
				return self[ix];

			throw IndexError();
			}
Example #5
0
		static boost::python::object	toPython(const ImmutableTreeVector<T>& inT)
			{
			boost::python::list o = boost::python::list();

			for (int32_t k = 0; k < inT.size();k++)
				o.append(Converter<T>::toPython(inT[k]));

			return o;
			}
NativeExpression callLibraryFunctionContainingCPPTypes(
			NativeLibraryFunctionTarget target,
			NativeType resultType,
			bool resultTypeIsPOD,
			ImmutableTreeVector<NativeExpression> inArguments,
			ImmutableTreeVector<bool> inArgumentTypesArePOD
			)
	{
	if (!resultTypeIsPOD && resultType.isNothing())
		resultTypeIsPOD = true;
	//make sure all of our arguments have types
	for (long k = 0; k < inArguments.size();k++)
		if (!inArguments[k].type())
			{
			NativeExpression e;
			for (long j = 0; j <= k; j++)
				e = e >> inArguments[j];

			return e;
			}
		static uint32_t size(ImmutableTreeVector<T>& in)
			{
			return in.size();
			}