Objeck

Implementation of programming language Objeck

The only implementation of the language, written by its author. Includes a compiler which translates programs to bytecode, virtual machine with garbage collector and just-in-time compilation and a command-line debugger.

Features

  • Native platform support for Windows, Linux and Mac OS X
  • Support for object-oriented programming (virtual classes, interfaces, enums, functions and methods) and functional programming (high-order functions)
  • Runtime introspection and object serialization
  • Support for polymorphic methods and functions
  • Class library support (math, files, sockets, xml, http, collections and etc.)
  • Automatic memory management (mark and sweep garbage collection)
  • Native runtime JIT support for IA-32 and AMD64 architectures
  • Compiler optimizations (short-circuit evaluation, method inlining, constant folding, strength reduction, instruction simplification)

Examples:

Hello, World!:

Example for versions Objeck 2.0.3
bundle Default {
	class Hello {
		function : Main(args : String[]) ~ Nil {
			"Hello, World!"->PrintLine();
		}
	}
}

Factorial:

Example for versions Objeck 2.0.3

This example uses built-in Factorial() function.

bundle Default {
 class Factorial {
 function : Main(args : String[]) ~ Nil {
 for (i := 0; i <= 16; i += 1;) {
 i->Print();
 "! = "->Print();
 i->Factorial()->PrintLine();
 };
 }
 }
}

Fibonacci numbers:

Example for versions Objeck 2.0.3

This example uses recursive definition of Fibonacci numbers.

bundle Default {
 class Fib {
 function : Fibonacci (n: Int) ~ Int {
 if (n<=2) {
 return 1;
 };
 return Fibonacci(n-1) + Fibonacci(n-2);
 }
 function : Main(args : String[]) ~ Nil {
 for (i := 0; i <= 16; i += 1;) {
 Fibonacci(i)->Print();
 ", "->Print();
 };
 "..."->PrintLine();
 }
 }
}

Quadratic equation:

Example for versions Objeck 2.0.3
use IO;
bundle Default {
 class Quadratic {
 function : Main(args : String[]) ~ Nil {
 A := Console->ReadString()->ToInt();
 if (A=0) {
 "Not a quadratic equation."->PrintLine();
 return;
 };
 B := Console->ReadString()->ToInt();
 C := Console->ReadString()->ToInt();
 D := 1.0*(B*B-4*A*C);
 if (D=0) {
 "x = "->Print();
 (0-B/2.0/A)->PrintLine();
 };
 if (D>0) {
 "x1 = "->Print();
 ((0-B+(D->SquareRoot()))/2.0/A)->PrintLine();
 "x2 = "->Print();
 ((0-B-(D->SquareRoot()))/2.0/A)->PrintLine();
 };
 if (D<0) {
 out := "x1 = (";
 out->Append(0-B/2.0/A);
 out->Append(",");
 out->Append(((D->Abs())->SquareRoot())/2/A);
 out->Append(")");
 out->PrintLine();
 out := "x2 = (";
 out->Append(0-B/2.0/A);
 out->Append(",");
 out->Append(0-((D->Abs())->SquareRoot())/2/A);
 out->Append(")");
 out->PrintLine();
 };
 }
 }
}

AltStyle によって変換されたページ (->オリジナル) /