language

some fools attempt at an interpreted language
Log | Files | Refs | README

fibb.ti (984B)


      1 class Adder:
      2 {
      3 	int operandA = 0;
      4 
      5 	int operandB = 0;
      6 
      7 	func doOperation -> int:
      8 	{
      9 		return operandA + operandB;
     10 	}
     11 }
     12 
     13 class Counter:
     14 {
     15 	var add_machine = new Adder();
     16 
     17 	add_machine.operandA = 0;
     18 
     19 	add_machine.operandB = 1;
     20 
     21 	func count -> int:
     22 	{
     23 		add_machine.operandA = add_machine.doOperation();
     24 		return add_machine.operandA;
     25 	}
     26 
     27 	func reset -> int:
     28 	{
     29 		int old_value = add_machine.operandA;
     30 		add_machine.operandA = 0;
     31 
     32 		return old_value;
     33 	}
     34 }
     35 
     36 class ObjectFibb(Counter acc):
     37 {
     38 	var add_machine = new Adder();
     39 
     40 	add_machine.operandA  = 0;
     41 	add_machine.operandB = 1;
     42 
     43 	func next -> void:
     44 	{
     45 		add_machine.operandB = add_machine.doOperation();
     46 		add_machine.operandA = add_machine.doOperation();
     47 	}
     48 
     49 	func run (int count) -> int:
     50 	{
     51 		while acc.count() < count:
     52 		{
     53 			next();
     54 		}
     55 
     56 		return add_machine.operandA;
     57 	}
     58 }
     59 
     60 class FullFibb:
     61 {
     62 	var the_counter = new Counter();
     63 	var fibb = new ObjectFibb(the_counter);
     64 
     65 	func do (int count) -> int:
     66 	{
     67 		return fibb.run(count);
     68 	}
     69 }
     70