项目作者: objeck

项目描述 :
Modern object-oriented and functional programming language
高级语言: C
项目地址: git://github.com/objeck/objeck-lang.git
创建时间: 2014-06-08T03:25:12Z
项目社区:https://github.com/objeck/objeck-lang

开源协议:Other

下载


Object-Oriented, Functional & AI-Enabled


An Objeck



GitHub CodeQL
GitHub CI
Coverity SCA

Releases

  • v2025.4.x

    • Support for the Open AI’s Realtime API
    • Hexagon NPU support for Llama and Mistra
  • v2025.3.0

    • Updated VS Code LSP support for macOS and Linux ✍🏽
    • Collection bug fixes 🫙
    • LSP bug fixes ⌨️
    • More aggressive method inlining 🏎️
  • v2025.2.2

    • Improved named pipe support 🔌
    • Updates to the LSP client/server ⌨️
    • Fixed Windows installer issues with missing DLLs 🏗️
    • Error handling bug fixes
  • v2025.2.1

    • Improved support for JSON stream parsing ⭐
    • Faster ‘String’ compare 🚄

Examples

  1. # hello world
  2. class Hello {
  3. function : Main(args : String[]) ~ Nil {
  4. "Hello World" PrintLine();
  5. "Καλημέρα κόσμε" PrintLine();
  6. "こんにちは 世界" PrintLine();
  7. }
  8. }
  1. # openai and perplexity inference
  2. use API.OpenAI, API.OpenAI.Chat, Collection;
  3. class OpenAICompletion {
  4. @is_pplx : static : Bool;
  5. function : Main(args : String[]) ~ Nil {
  6. if(args->Size() <> 1) {
  7. ">>> Error: Token file required <<"->ErrorLine();
  8. Runtime->Exit(1);
  9. };
  10. token := GetApiKey(args[0]);
  11. if(token = Nil) {
  12. ">>> Unable to use API key <<"->PrintLine();
  13. Runtime->Exit(1);
  14. };
  15. model : String;
  16. if(@is_pplx) {
  17. Completion->SetBaseUrl("https://api.perplexity.ai");
  18. model := "llama-3-sonar-small-32k-online";
  19. }
  20. else {
  21. model := "gpt-4o";
  22. };
  23. message := Pair->New("user", "What is the longest road in Denver?")<String, String>;
  24. completion := Completion->Complete(model, message, token);
  25. if(completion <> Nil) {
  26. choice := completion->GetFirstChoice();
  27. if(choice = Nil) {
  28. ">>> Error: Unable to complete query <<"->ErrorLine();
  29. Runtime->Exit(1);
  30. };
  31. message := choice->GetMessage()<String, String>;
  32. if(message = Nil) {
  33. ">>> Error: Unable to read response <<"->ErrorLine();
  34. Runtime->Exit(1);
  35. };
  36. message->GetSecond()->PrintLine();
  37. };
  38. }
  39. function : GetApiKey(filename : String) ~ String {
  40. token := System.IO.Filesystem.FileReader->ReadFile(filename);
  41. if(token <> Nil) {
  42. token := token->Trim();
  43. if(<>token->StartsWith("sk-") & <>token->StartsWith("pplx-")) {
  44. ">>> Unable to read token from file: '{$filename}' <<"->PrintLine();
  45. Runtime->Exit(1);
  46. };
  47. if(token->StartsWith("pplx-")) {
  48. @is_pplx := true;
  49. };
  50. return token;
  51. };
  52. return Nil;
  53. }
  54. }
  1. # image identification
  2. use API.Google.Gemini, System.IO.Filesystem;
  3. class IdentifyImage {
  4. function : Main(args : String[]) ~ Nil {
  5. content := Content->New("user")->AddPart(TextPart->New("What number is this image showing?"))
  6. ->AddPart(BinaryPart->New(FileReader->ReadBinaryFile("thirteen.png"), "image/png"))
  7. ->AddPart(TextPart->New("Format output as JSON"));
  8. candidates := Model->GenerateContent("models/gemini-pro-vision", content, EndPoint->GetApiKey());
  9. if(candidates->Size() > 0) {
  10. candidates->First()->GetAllText()->Trim()->PrintLine();
  11. };
  12. }
  13. }
  1. # text to speech
  2. use Web.HTTP, Collection, Data.JSON, API.OpenAI.Audio;
  3. class Embaddings {
  4. function : Main(args : String[]) ~ Nil {
  5. if(args->Size() = 1) {
  6. message := args[1];
  7. response := API.OpenAI.Audio.Speech->Speak("tts-1", message, "fable", "mp3", token)<String, ByteArrayRef>;
  8. if(response->GetFirst()->Has("audio")) {
  9. System.IO.Filesystem.FileWriter->WriteFile("speech.mp3", response->GetSecond()->Get());
  10. };
  11. }
  12. }
  13. }

Design [1]

  • Object-oriented and functional
  • Cross-platform support for Linux, macOS, and Windows (including Docker and RPI 3/4/5)
  • JIT-compiled runtimes (ARM64 and AMD64)
  • REPL shell
  • LSP plugins for VSCode, Sublime, Kate, and more
  • API documentation

Libraries [2]

Features

Object-oriented

Inheritance

  1. class Triangle from Shape {
  2. New() {
  3. Parent();
  4. }
  5. }

Interfaces

  1. class Triangle from Shape implements Color {
  2. New() {
  3. Parent();
  4. }
  5. method : public : GetRgb() ~ Int {
  6. return 0xadd8e6;
  7. }
  8. }
  9. interface Color {
  10. method : virtual : public : GetRgb() ~ Int;
  11. }

Type Inference

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

Anonymous Classes

  1. interface Greetings {
  2. method : virtual : public : SayHi() ~ Nil;
  3. }
  4. class Hello {
  5. function : Main(args : String[]) ~ Nil {
  6. hey := Base->New() implements Greetings {
  7. New() {}
  8. method : public : SayHi() ~ Nil {
  9. "Hey..."->PrintLine();
  10. }
  11. };
  12. }

Reflection

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

Dependency Injection

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

Generics

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

Type Boxing

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

Static import

  1. use function Int;
  2. class Test {
  3. function : Main(args : String[]) ~ Nil {
  4. Abs(-256)->Sqrt()->PrintLine();
  5. }
  6. }

Serialization

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

Functional

Closures and Lambda Expressions

  1. funcs := Vector->New()<FuncRef<IntRef>>;
  2. each(i : 10) {
  3. funcs->AddBack(FuncRef->New(\() ~ IntRef : ()
  4. => i->Factorial() * funcs->Size())<IntRef>);
  5. };
  6. each(i : funcs) {
  7. value := funcs->Get(i)<FuncRef>;
  8. func := value->Get();
  9. func()->Get()->PrintLine();
  10. };

First-Class Functions

  1. @f : static : (Int) ~ Int;
  2. @g : static : (Int) ~ Int;
  3. function : Main(args : String[]) ~ Nil {
  4. compose := Composer(F(Int) ~ Int, G(Int) ~ Int);
  5. compose(13)->PrintLine();
  6. }
  7. function : F(a : Int) ~ Int {
  8. return a + 14;
  9. }
  10. function : G(a : Int) ~ Int {
  11. return a + 15;
  12. }
  13. function : native : Compose(x : Int) ~ Int {
  14. return @f(@g(x));
  15. }
  16. function : Composer(f : (Int) ~ Int, g : (Int) ~ Int) ~ (Int) ~ Int {
  17. @f := f;
  18. @g := g;
  19. return Compose(Int) ~ Int;
  20. }

Host Support

Unicode

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

File System

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

Sockets

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

Named Pipes

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

Threads

  1. class CaculateThread from Thread {
  2. ...
  3. @inc_mutex : static : ThreadMutex;
  4. New() {
  5. @inc_mutex := ThreadMutex->New("inc_mutex");
  6. }
  7. method : public : Run(param : System.Base) ~ Nil {
  8. Compute();
  9. }
  10. method : native : Compute() ~ Nil {
  11. y : Int;
  12. while(true) {
  13. critical(@inc_mutex) {
  14. y := @current_line;
  15. @current_line+=1;
  16. };
  17. ...
  18. };
  19. }
  20. }

Date/Times

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

Screenshots

VS Code Debugger Dungeon Crawler Platformer Windows Utility

alt text | alt text | alt text | alt text | alt text |