Giter Site home page Giter Site logo

objeck / objeck-lang Goto Github PK

View Code? Open in Web Editor NEW
148.0 4.0 11.0 2 GB

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.

Home Page: https://objeck.org

License: Other

Shell 0.12% C++ 56.72% C 38.99% HTML 0.14% Makefile 0.09% Perl 0.03% Batchfile 0.03% Terra 0.01% Brainfuck 0.01% Objective-C 0.05% CMake 0.75% PowerShell 0.01% M4 0.02% AMPL 0.01% CSS 0.02% JavaScript 0.06% Cuda 0.30% Fortran 2.61% XSLT 0.01% Python 0.03%
arm64 assembly-language cplusplus debuggers jit-compilation memory-management runtime-system documentation examples linux

objeck-lang's Introduction

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?

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();

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

objeck-lang's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

objeck-lang's Issues

Generic types and self instance

The following code generates a compiler error as the @self instance is unaware of generic type information.

method : public : Each(f : (K, V) ~ Nil) ~ Map<K, V> {
  Each(@root, f);
  return @self;
}

Encrypt->Base64 indexes out of bounds for some arguments

Using version 5.5.4 for windows x86, this test program

use Encryption;

class Base64Program {
	function : Main(args: String[]) ~ Nil {
		s1 := "string";
		s1->PrintLine();
		Encrypt->Base64(s1)->PrintLine();
		
		s2 := "hello";
		s2->PrintLine();
		Encrypt->Base64(s2)->PrintLine();
		
		s3 := "poop";
		s3->PrintLine();
		Encrypt->Base64(s3)->PrintLine();
	}
}

results in

string
c3RyaW5n
hello
aGVsbG8=
poop
>>> Index out of bounds in native JIT code! <<<
Unwinding local stack (00327D70):
  method: pos=2, name='Encryption.Encrypt->Base64(p0:System.String)'
  method: pos=1, name='Base64Program->Main(p0:System.String[])'
  ...

Side note: I like this project a lot. Feels sorta like a portable, mini java at like 1/8th the size.

JSON parser crashes with trailing whitespace.

The following JSON crashed the parser. The issue is due to trailing whitespace.

{
	"files": [
		"a.obs",
		"b.obs"
	],
	"libs": [
		"gen_collect.obl",
		"regex.obl",
		"net.obl",
		"misc.obl",
		"odbc.obl"
	],
	"flags": ""
}

Support for closures

Adding support for closures in the closure branch. Will release support for closures and lambda expression in 5.1.0.

string formatted output for arrays is incorrect

class Test {
  function : Main(args : String[]) ~ Nil {
  	a := [3,4,5];
  	a->ToString()->PrintLine();
  	b := a->ToString();

  	x := 101;
  	"{$x}: {$a}"->PrintLine();
  }
}

Output:
[3,4,5]
101: 1741121338720

if:
{$x}: {$b}"->PrintLine();

Output is correct. Bug is that output seems to printing the value of the array address.

String literal variable static check

The following code should generate an error since the value is an instance variable and functions are static.

class Test {
	@value : String;
	
	function : Main(args : String[]) ~ Nil {
#		@value += "z";
		"-- {$@value} --"->PrintLine();
	}
}

Support for lambda expression

Adding support for lambda expressions:

f := (a : Int) ~ Int => x + a * 13; # full syntax

ff := (a : Int) ~ Int; # user defined function type
f := ff => x + a * 13; # full syntax

Using enums for generic types

The following code should generate a compiler error. The incorrect code causes the memory manager to incorrectly treat a literal as an object.

use Collection.Generic;

class Foo {
	enum Value {
		BAR
	}
	
	function : Main(args : String[]) ~ Nil {
		hash := Hash->New()<String, Foo->Value>;
		hash->Insert("foo bar", Foo->Value->BAR);
	}
}```

Compiler not catching invalid generic type names

The following code should not compile.

class Test {
	foo : Collection.Generic.Vector<String>;

	New() {
		foo := Collection.Generic.Vector->New()<String>;
	}

	function : Main(args : String[]) ~ Nil {
	}
}

Default parameter assignment for objects

The code below would not compile. The context analysis was incorrectly flagging but only for default parameter assignment for objects to Nil.

function : Init(s : String := Nil) ~ Nil { ... }

Array address comparison

The following code produces a compiler error

class Foo {
	function : Main(args : String[]) ~ Nil {
		aa : Int[] := Int->New[3];
		bb : Int[] := Int->New[7];
		
		(aa = bb)->PrintLine();
	}
}

Unnecessary concreate arguments ignored by compiler

The following code should produce an error

class Program {
	function : Main(args: String[]) ~ Nil {
		f := Foo->New();
		f := f->Next()<String>;
	}
}

class Foo {
	New() {
	}

	method : public : Next() ~ Foo {
		return Nil;
	}
}

Incorrect memory metadata for class with library derived class hierarchy

The code below crashes because the compiler did not emit the memory metadata for the library class the parent class is derived from.

	@id : Int;
	
	New() {
		Parent(3.145);
	}

	function : Main(args : String[]) ~ Nil {
	}
}

class Foo from System.Concurrency.Thread {
	@value : Float;

	New(value : Float) {
		Parent();
		@value := value;
	}

	method : public : Run(arg : Base) ~ Nil {
	}
}```

JSON parser error

The following JSON is not parsed correctly

use Data.JSON;

class Brewery {
	function : Main(args : String[]) ~ Nil {
		JsonParser->New("[1,2,3]")->Parse()->PrintLine();
	}
}

Garage collection for multithreaded workloads

The following program causes crashes.

Issues:

  • code generation for classes derived from libraries classes
  • thread-safety of memory manager's young cache
use Collection.Generic;

class Foo {
	function : Main(args : String[]) ~ Nil {
		threads := Vector->New()<Service>;
		each(i : 64) {
			thread := Service->New(i);
			threads->AddBack(thread);
			thread->Execute(Nil);			
			"---"->PrintLine();
		};

		each(i :threads) {
			threads->Get(i)->Join();
		};

		"Done!"->PrintLine();
    }
}

class Service from System.Concurrency.Thread {
	@nodes : Map<String, IntHolder>;
	@max : Int;

	New(max : Int) {
		Parent();
		@nodes := Map->New()<String, IntHolder>;
		@max := max;
	}

	method : public : Run(param : Base) ~ Nil {
		each(i : @max) {
			Insert();
		};

		@nodes->Size()->PrintLine();
	}

	method : public : Insert() ~ Nil {
		value := "";
		length := Int->Random(5, 13);

		each(i : length) {
			value += Int->Random('a', 'z')->As(Char);
		};

		value->PrintLine();
		@nodes->Insert(value, length);
	}
}

Default parameter functions incorrectly generated

Code generate for the follow function is incorrect for it's alternate:
Original: function : Split(b : Float[,], offset : Int, count : Int, is_row : Bool := true) ~ Float[,]
Alternative: function : Split(b : Float[,], offset : Int, count : Int) ~ Float[,]

Generics?

I'm guessing that this was an explicit non-goal...

but this seems rather ugly:

result := reserved->Find(string)->As(String);

In my opinion, it'd be really easy to end up with a mismatched As somewhere.

I'm also kind of curious as to why StringMap's find needs explicit casts to String.

SSL server socket buffer read/write

The following code does not write out the buffer due to an unnecessary check of the SSL bio socket context.

image := FileReader->ReadBinaryFile("foo.jpg");
if(image <> Nil) {
	image_size := image->Size();
	out := "HTTP/1.1 200 OK\r\nContent-type: image/jpeg\r\nContent-Length: {$image_size}\r\naccpet-ranges: bytes\r\n\r\n";
	client->WriteString(out);
	client->WriteBuffer(0, image_size, image);
};
client->Close();```

Invalid leaving statement

The following causes a null pointer crash.

class The {
	function : Main(args : String[]) ~ Nil {
		if(args->Size() = 1) {
			leaving {
				
			};
                 };
        }
}

Respect CC

Right now, I can't try to build Objeck with Clang because the deploy script ignores any options passed to it. Could some of the lines be changed to something like this:

...
make clean; make -j3 "$@"

This would allow setting the CC variable.

LSP Find All References

The following code segments should be found bidirectionally.

headers := GetHeaders(client);
...
method : public : GetHeaders(client : TCPSecureSocket) ~ Map<String, String> { ... }

Documentation Misspelling

Under Vector

IsEmpty

Checks to see if the vector is empty

method : public : IsEmpty() ~ Bool
Return
Type Description
Bool ture if empty, false otherwise

Formatting of stack traces

Some stack traces show up as follows:

>>> Attempting to dereference a 'Nil' memory instance <<<
Unwinding local stack (0000015EA8C2DC80):
  method: pos=3, name='Evaluator->Evaluate(p0:Node)'
  method: pos=2, name='Evaluator:Evaluate:'
  method: pos=1, name='MiniLisp:Main:o.System.String*,'

Only the first list of the stack trace is pretty printed

Compilation failed with MSVC

Hi, I'm just trying to compile this on windows with MSVC 19.26 (MSVS 2019), but it failed with the following error message.

1>libz-static.lib(compress.obj) : MSIL .netmodule or module compiled with /GL found; restarting link with /LTCG; add /LTCG to the link command line to improve linker performance
1>LINK : warning LNK4075: ignoring '/INCREMENTAL' due to '/LTCG' specification
1>LINK : fatal error C1900: Il mismatch between 'P1' version '20210113' and 'P2' version '20190715'
1>LINK : fatal error LNK1257: code generation failed
1>Done building project "compiler.vcxproj" -- FAILED.

I tried to google it here and found out that it it tries to compile different projects with different compiler versions. I'm not sure how each project is configured or is this my fault, but all I've done was just running the object.sln in the core/release/ folder. Any pointers to help me resolve this problem would be helpful.

Issue with single default parameter

The following code did not compile.

class Test {
	function : Main(args : String[]) ~ Nil {
		Foo();
		Foo(false);
	}

	function : Foo(a : Bool := false) ~ Nil {		
		a->PrintLine();
	}
}

Unimplemented virtual methods were not being flagged

The following code should produce an error.

class Foo {
	function : Main(args : String[]) ~ Nil {
	}
}

class Fie from Fum {
	New() {
		Parent();
	}

	method : DoIt() ~ Nil {

	}
}

class Fum {
	New() {
	}

	method : virtual : DoIt() ~ Nil;
}```

AES 256 decrypt fails

The follwoing code is not working

key := "Forest Room 5"->ToByteArray();
 in := "I switched my motto / Instead of saying f*ck tomorrow, that buck that bought a bottle could've struck the lotto."->ToByteArray();
encrypted := Encryption.Encrypt->AES256(key, in);
if(encrypted <> Nil) {
	decprypted := Encryption.Decrypt->AES256(key, encrypted);
	if(decprypted <> Nil) { # FAILS
		String->New(decprypted)->PrintLine();
	};
};

Flagging invalid static method call

The following should generate an error

class Program {
	function : Main(args: String[]) ~ Nil {
	}

	method : Bar() ~ Nil {
		Foo->Next();
	}
}

class Foo {
	New() {
	}

	method : public : Next() ~ Foo {
		return Nil;
	}
}

Type inference for lambda expressions

For example:
map->Each(\^(k, v) => "{$k}: {$v}"->PrintLine());

Will be supported in next release 5.1.7 or 5.2.0. Initial implementation completed however more unit testing required.

Class enum type check

The following code was not caught by the compiler. The compiler was missing a class to enum check.

class Foo {
	function : Main(args : String[]) ~ Nil {
		if(String->New() = Foo->Bar) {
			"Okay"->PrintLine();
		};
	}

	enum Foo {
		Bar
	}
}```

Thread derived class Run method

The following program crashes because the thread's Run method is in a derived class.

class Foo {
	function : Main(args : String[]) ~ Nil {
		each(i : 5) {
			f := Fie->New();
			f->Execute(Nil);
		};

		System.IO.Console->ReadString();
	}
}

class Fie from Fum {
	New() {
		Parent();
	}

	method : SayIt() ~ Nil {
		"Hello World!"->PrintLine();
	}
}

class Fum from System.Concurrency.Thread {
	New() {
		Parent();
	}

	method : virtual : SayIt() ~ Nil;

	method : public : Run(param : Base) ~ Nil {
		SayIt();	
	}
}```

LSP Symbol support

The LSP bundle symbol was showing up as "Default" for files that did not have bundles defined. The "Default" bundle name should not be shown.

Invalid string formatting

The following code should not compile

class Test {
	function : Main(a : String[]) ~ Nil {
		b := 7; c := 13;
		"{$b, {$c}"->PrintLine();
	}
}

TCP write string

Socket WriteString is adding an extra '0' byte to the end of string

Generate app. exe for windows

Dear, the new language, does it generate .exe app for windows? Informs that using -tar exe can generate or get it wrong.?

obc -src Hello.obs -tar "exe"

Passing functions with generic types

The following code does not compile

use Collection.Generic;

class Program {
	function : Main(args: String[]) ~ Nil {
		m : Map<String, Vector<String>>;
		m->Each(Foo(String, Vector<String>) ~ Nil);
	}

	function : Foo(k : String, v : Vector<String>) ~ Nil {
	}
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.