Ejemplo n.º 1
0
	Ref<Object> Frame::benchmark(Frame * frame)
	{		
		Integer * times;
		Object * callback, * result;
		
		frame->extract()(times, "times")(callback, "callback");
		
		Math::IntermediateT count = times->value().to_intermediate();
		
		Time start;
		
		while (count > 0) {
			result = callback->evaluate(frame);
			
			count--;			
		}
		
		Time end;
		
		Time duration = (end - start);
		
		std::cerr << "Total time for " << times->value() << " runs = " << duration << std::endl;
		std::cerr << "Average time taken = " << (duration / times->value().to_intermediate()) << std::endl;
		
		return result;
	}
Ejemplo n.º 2
0
	Value * CompiledType::intType (Frame * frame) {
		Integer * bitSize;
		
		frame->extract()(bitSize);
		
		unsigned nbits = bitSize->value();
		
		if (nbits >= llvm::IntegerType::MIN_INT_BITS && nbits <= llvm::IntegerType::MAX_INT_BITS) {
			switch (bitSize->value()) {
				case 1:
					return new CompiledType(llvm::Type::getInt1Ty(llvm::getGlobalContext()));
				case 8:
					return new CompiledType(llvm::Type::getInt8Ty(llvm::getGlobalContext()));
				case 16:
					return new CompiledType(llvm::Type::getInt16Ty(llvm::getGlobalContext()));
				case 32:
					return new CompiledType(llvm::Type::getInt32Ty(llvm::getGlobalContext()));
				case 64:
					return new CompiledType(llvm::Type::getInt64Ty(llvm::getGlobalContext()));
				default:
					return new CompiledType(llvm::IntegerType::get(llvm::getGlobalContext(), bitSize->value()));
			}
		}
		
		throw Exception("Invalid primative integer width!", bitSize, frame);
	}
Ejemplo n.º 3
0
	Ref<Object> String::at (Frame * frame) {
		String * self;
		Integer * offset;
		frame->extract()(self, "self")(offset, "offset");
		
		// Bounds checking
		if (offset->value() < 0 || offset->value() > self->value().size()) {
			throw Exception("Invalid Offset!", offset, frame);
		}
		
		StringT character(1, self->value()[offset->value().to_intermediate()]);
		
		return new(frame) String(character);
	}
Ejemplo n.º 4
0
int getFibonacci2()
{
	unsigned int n;
	try
	{
		cin >> n;
	}catch(exception e){cout << "Invalid number" << endl;return -3;}
	if(n<=0)
	{
		cout << "Integer too small" << endl;
		return 3;
	}
	if(getCount("Files/Fibonacci2/")<n)
	{
		cout << "Integer too big" << endl;
		return 1;
	}
    string s = getLine("Files/Fibonacci2/",n-1);
	if(s=="")
	{
		cout << "Error occured. Could not retrieve number." << endl;
		return -1;
	}
	cout << "The " << n << "th fibonacci number is: " << endl << s << endl;
	Integer fib = ConvertBase(createFromText(s,2305843009213693952),10);
	cout << "Its decimal value is: " << endl << fib.value() << endl; 
	return 0;
}
Ejemplo n.º 5
0
	Value * CompiledType::vectorType (Frame * frame) {
		CompiledType * elementType;
		Integer * numberOfElements;
		
		frame->extract()(elementType)(numberOfElements);
		
		return new CompiledType(llvm::VectorType::get(elementType->value(), numberOfElements->value()));
	}
Ejemplo n.º 6
0
 L Diff::fixedBoundGet(APInt c) {
   Integer cv = constantValue();
   if (!cv.hasValue()) return L_NULL;
   LBound *bound = LBound::fixed(cv.value());
   L l = bound->get(c);
   delete bound;
   return l;
 }
Ejemplo n.º 7
0
int main()
{
  Integer i = new Integer(), j = new Integer(3);
  Integer k = j;
  if(i.value() != 0 || j.value() != 3 || k.value() != 3)
  {
    cout << "Test 1 failed- basics" << endl;
    return 1;
  }
  i = 5;
  if(i.value() != 5)
  {
    cout << "Test 2 failed- assignment" << endl;
    return 1;
  }
  int a = i;
  if(a != 5)
  {
    cout << "Test 3 failed- integer assignment" << endl;
    return 1;
  }
}
Ejemplo n.º 8
0
int calcFibonacci()
{
	//load
	cout << "Getting data..." << endl;
	deque<string> data;
    unsigned long long x = getCount("Files/Fibonacci/");
	string s = getLine("Files/Fibonacci/",x-2);
	if(s=="")
	{
		cout << "Error! Calculation was not executed." << endl;
		return -2;
	}
	data.push_back(s);
	s = getLine("Files/Fibonacci/",x-1);
	if(s=="")
	{
		cout << "Error! Calculation was not executed." << endl;
		return -2;
	}
	data.push_back(s);
	//calculate
	unsigned long siz = 2;
	cout << "Calculating..." << endl;
    while(stop.test_and_set(memory_order_acquire))
    {
		Integer a(data.at(siz-2));
		Integer b(data.at(siz-1));
        Integer z = a+b;
		string z2 = z.value();
        data.push_back(z2);
		siz++;
    }
    
	//save
	cout << "Saving data..." << endl;
	int o = printLines("Files/Fibonacci/",data,2,data.size()-2);
	if(o==-3)
	{
		cout << "Big error!! You should reset all files to initial setup before continuing." << endl;
		return -5;
	}
	else if(o!=0)
	{
		cout << "Error! Calculated data might not have been saved." << endl;
		return -3;
	}
	cout << "Fibonacci process was successful. I found " << (data.size()-2) << " fibonacci numbers("
		<< (x+1) << "-" << (x+data.size()-2) << ")." << endl;
	stop.clear();
	return 0;
}
Ejemplo n.º 9
0
	Value * CompiledType::floatType (Frame * frame) {
		Integer * bitSize;
		
		frame->extract()(bitSize);
		
		switch (bitSize->value()) {
			case 32:
				return new CompiledType(llvm::Type::getFloatTy(llvm::getGlobalContext()));
			case 64:
				return new CompiledType(llvm::Type::getDoubleTy(llvm::getGlobalContext()));
			case 128:
				return new CompiledType(llvm::Type::getFP128Ty(llvm::getGlobalContext()));
		}

		throw Exception("Invalid primative float width!", bitSize, frame);
	}
Ejemplo n.º 10
0
int calcFactorial()
{
	//load
	cout << "Getting data..." << endl;
	deque<string> data;
    unsigned long long x = getCount("Files/Factorial/");
	string s = getLine("Files/Factorial/",x-1);
	if(s=="")
	{
		cout << "Error! Calculation was not executed." << endl;
		return -2;
	}
	data.push_back(s);

	//calculate
	Integer k(Int2Str(x));
	Integer one("1");
	cout << "Calculating..." << endl;
    while(stop.test_and_set(memory_order_acquire))
    {
		Integer a(data.at(data.size()-1));
        Integer z = a*k;
		string z2 = z.value();
        data.push_back(z2);
		k = k + one;
    }
    
	//save
	cout << "Saving data..." << endl;
	int o = printLines("Files/Factorial/",data,1,data.size()-1);
	if(o==-3)
	{
		cout << "Big error!! You should reset all files to initial setup before continuing." << endl;
		return -5;
	}
	else if(o!=0)
	{
		cout << "Error! Calculated data might not have been saved." << endl;
		return -3;
	}

	cout << "Factorial process was productive. I found the factorials of " << (data.size()-1) << " numbers("
		<< (x+1) << "-" << (x+data.size()-1) << ")." << endl;
	stop.clear();
	return 0;
}
Ejemplo n.º 11
0
void Integer::set( const Integer& i ){
    *(int*)data_ = i.value();
}
Ejemplo n.º 12
0
int Integer::compare( const Integer& i ) const{
    return ( *(int*)data_ > i.value() )? 1 : ( *(int*)data_ < i.value() )? -1 : 0;
}
Ejemplo n.º 13
0
Integer::Integer( const Integer& i ){
    data_ = (void*)new int( i.value() );
}
Ejemplo n.º 14
0
string to_s(const Integer& v) {
    return "<Integer: " + std::to_string(v.value()) + ">";
}
Ejemplo n.º 15
0
 friend bool operator== (int lhs, Integer rhs) {
     return lhs == rhs.value();
 }
Ejemplo n.º 16
0
Decimal Type::createDecimal( const Integer& value )
{
    assert( value.trivial() );
    Decimal tmp( value.value(), value.sign() );
    return tmp;
}
 inline ReturnType operator()( Integer const & arg ) const
 {
     return ReturnType(arg.value());
 }