Objeck Lang Save

Objeck is a modern object-oriented programming language with functional features. It emphasizes, expression, simplicity, portability, and scalability. The programming environment consists of a compiler, virtual machine, REPL shell, and command line debugger with IDE plugins.

Project README

Intuitive, Fast & Efficient

An Objeck


GitHub CI Coverity SCA GitHub CodeQL Discord

Objeck is a fast, intuitive, and lightweight programming language that supports both object-oriented and functional programming paradigms, and is designed to be compatible with multiple platforms, including Windows, Linux, and macOS.

use API.Google.Gemini, System.IO.Filesystem;

class IdentifyImage {
  function : Main(args : String[]) ~ Nil {
    content := Content->New("user")->AddPart(TextPart->New("What number is this image showing?"))
      ->AddPart(BinaryPart->New(FileReader->ReadBinaryFile("thirdteen.png"), "image/png"))
      ->AddPart(TextPart->New("Format output as JSON"));

    candidates := Model->GenerateContent("models/gemini-pro-vision", content, EndPoint->GetApiKey());
    if(candidates->Size() > 0) {
      candidates->First()->GetAllText()->Trim()->PrintLine();
    };
  }
}
VS Code Debugger Dungeon Crawler Platformer Windows Utility
alt text alt text alt text alt text alt text

Want to get started? Take a look at the language guide and code examples. If you want to contribute, start with the system architecture.

What is it?

  • Modern object-oriented and functional
  • Cross-platform: Linux (x64 and ARM64), macOS (ARM64), Windows (x64)
  • Optimized and JIT-compiled runtimes
  • API support for
    • Secure web servers and clients
    • Encryption
    • JSON, CSV, and XML parsing libraries
    • Regular expressions
    • 2D gaming
    • Linear matrix mathematics
    • Collections
    • Files, directories, sockets, STDIO, logging, serialization, and pipes
  • REPL and IDE LSP support (for VSCode, Sublime, Kate, etc.)
  • Online guides and API documentation.

What's New?

  • v2024.5.0

    • Extended LSP functionality
    • DeepMind (Gemini) support for functions
  • v2024.4.0 [current release]

    • Added support for Google DeepMind (Gemini) APIs
      • Model
      • Corpus (v1beta)
      • Chat
    • Open AI support for external function calls
    • OAuth2 support (session and file based support)
    • Refactored KMeans ML implementation to support arrays
    • Improved support for Date <=> String operations
    • Improved Base64 encoding and decoding
    • Added support for private functions
    • Tuples classes moved to Collection.Tuple
    • Added 'First' and 'Last' methods to Vector classes
    • Fixed ARM64 JIT compiler 'eor' instruction issue impacting macOS and ARM64
  • v2024.3.0

    • Added support for OpenAI APIs
    • Fixed GC bug #462 and #482
  • v2024.2.1

  • v2024.2.0

    • New incremental JSON parser
      • Improved parsing performance for large JSON documents
    • Immutable Tuple types
      • Pair<A,B>
      • Triplet<A,B,C>
      • Quartet<A,B,C,D>
    • Range support
      • Added CharRange, IntRange and, FloatRange classes

How to Use It?

Object-oriented

Inheritance

class Triangle from Shape {
  New() {
    Parent();
  }
}

Interfaces

class Triangle from Shape implements Color {
  New() {
    Parent();
  }

  method : public : GetRgb() ~ Int {
    return 0xadd8e6;
  }
}

interface Color {
  method : virtual : public : GetRgb() ~ Int;
}

Type Inference

value := "Hello World!";
value->Size()->PrintLine();

Anonymous Classes

interface Greetings {
  method : virtual : public : SayHi() ~ Nil;
}

class Hello {
  function : Main(args : String[]) ~ Nil {
    hey := Base->New() implements Greetings {
      New() {}

      method : public : SayHi() ~ Nil {
        "Hey..."->PrintLine();
      }
    };
}

Reflection

klass := "Hello World!"->GetClass();
klass->GetName()->PrintLine();
klass->GetMethodNumber()->PrintLine();

Dependency Injection

value := Class->Instance("System.String")->As(String);
value += "510";
value->PrintLine();

Generics

map := Collection.Map->New()<IntRef, String>;
map->Insert(415, "San Francisco");
map->Insert(510, "Oakland");
map->Insert(408, "Sunnyvale");
map->ToString()->PrintLine();

Type Boxing

list := Collection.List->New()<IntRef>;
list->AddBack(17);
list->AddFront(4);
(list->Back() + list->Front())->PrintLine();

Static import

use function Int;

class Test {
  function : Main(args : String[]) ~ Nil {
    Abs(-256)->Sqrt()->PrintLine();
  }
}

Serialization

serializer := System.IO.Serializer->New();
serializer->Write(map);
serializer->Write("Fin.");
bytes := serializer->Serialize();
bytes->Size()->PrintLine();

Functional

Closures and Lambda Expressions

funcs := Vector->New()<FuncRef<IntRef>>;
each(i : 10) {
  funcs->AddBack(FuncRef->New(\() ~ IntRef : () 
    => System.Math.Routine->Factorial(i) * funcs->Size())<IntRef>);
};

each(i : funcs) {
  value := funcs->Get(i)<FuncRef>;
  func := value->Get();
  func()->Get()->PrintLine();
};

First-Class Functions

@f : static : (Int) ~ Int;
@g : static : (Int) ~ Int;

function : Main(args : String[]) ~ Nil {
  compose := Composer(F(Int) ~ Int, G(Int) ~ Int);
  compose(13)->PrintLine();
}

function : F(a : Int) ~ Int {
  return a + 14;
}

function : G(a : Int) ~ Int {
  return a + 15;
}

function : native : Compose(x : Int) ~ Int {
  return @f(@g(x));
}

function : Composer(f : (Int) ~ Int, g : (Int) ~ Int) ~ (Int) ~ Int {
  @f := f;
  @g := g;
  return Compose(Int) ~ Int;
}

Host Support

Unicode

"Καλημέρα κόσμε"->PrintLine();

File System

content := Sytem.IO.Filesystem.FileReader->ReadFile(filename);
content->Size()->PrintLine();
Sytem.IO.Filesystem.File->Size(filename)->PrintLine();

Sockets

socket->WriteString("GET / HTTP/1.1\nHost:google.com\nUser Agent: Mozilla/5.0 (compatible)\nConnection: Close\n\n");
line := socket->ReadString();
while(line <> Nil & line->Size() > 0) {
  line->PrintLine();  
  line := socket->ReadString();
};
socket->Close();

Named Pipes

pipe := System.IO.Pipe->New("foobar", Pipe->Mode->CREATE);
if(pipe->Connect()) {
  pipe->ReadLine()->PrintLine();
  pipe->WriteString("Hi Ya!");
  pipe->Close();
};

Threads

class CaculateThread from Thread {
  ...
  @inc_mutex : static : ThreadMutex;

  New() {
    @inc_mutex := ThreadMutex->New("inc_mutex");
  }
  
  method : public : Run(param : System.Base) ~ Nil {
    Compute();
  }

  method : native : Compute() ~ Nil {
    y : Int;

    while(true) {
      critical(@inc_mutex) {
        y := @current_line;
        @current_line+=1;
      };
      ...
    };
  }
}

Date/Times

yesterday := System.Time.Date->New();
yesterday->AddDays(-1);
yesterday->ToString()->PrintLine();

Notable Libraries

Open Source Agenda is not affiliated with "Objeck Lang" Project. README Source: objeck/objeck-lang