Skip to content

Instantly share code, notes, and snippets.

@zezba9000
Last active May 23, 2016 07:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zezba9000/2bbdff8a573d6c3b871fbe48c8b15ece to your computer and use it in GitHub Desktop.
Save zezba9000/2bbdff8a573d6c3b871fbe48c8b15ece to your computer and use it in GitHub Desktop.
`INFO =======================================================`
`File Ext = '.rl'`
`NOTE: This lang compiles out to other lang targets such as C, Nim, C#, Java, javaScript, etc`
`The lang utalizes the native GC in each target. If a GC doesn't exist a simple one capabled of running on Arduino to PC will be implemented`
`This lang is strong typed, supports runtime type info and objects/classes are linked via namespace over file location (like C#)`
`There are two primary goals with this lang
#1 portability (Arduino'ish devices with 1kb or less of ram to PCs with GBs of ram) [Almost any CPU should work out of the box with code gen targets]
#2 performance (targets like Nim [deterministic GC] and C will get you this)`
`Some type notes...
int = CPU PTR size for integer
You can also define types like int8, int16, in32, etc
num = CPU PTR size for floating point
You can also define types like num32, num64, etc
text = two byte unicode string just like C#
char = two byte unicode char just like C#`
`INFO =======================================================`
namespace Testing.MyNamespace;
use System.IO;
`TODO: alias MyObj = SomeNamespace.BaseClass;`
`All comments have a start and end char`
`
Comments can be multi-line
Like this!
`
trait MyTrait
{
`Anything in here gets directly injected into any object, class or struct types that derive from it`
}
interface MyInterface
{
`Would work just like C# interfaces and support virtual methods only`
}
`Objects support virtual methods and are alocated on the heap (GC collected and hold a referenct to there vTable)`
object MyObject public single : SomeNamespace.BaseObj, MyInterface, MyTrait
{
`NOTE: All types default to public/readonly(external) read/write(internal) [This gets the best performance on all lang targets]`
`Setting a var to 'public' would make it public/read/write`
`Setting a var to 'private' is the same as C# or Java`
`Setting a var to 'internal' is the same as C#`
`Text can be single or multi-line and spaces/tabs start reletive to texts definitions offset`
def myText : text = "Hello World!";
def myText2 : text =
"Hello
World!";
def myChar : char = 'c';
`All 'def' types MUST set there value (same as const in C#)`
def value public : int = -1;
def value2 public : int = {1};
def value3, value4, value5 private : num = {2.0, 3.0f, #FFFFFFFF};
`All 'var' types CANT set a value (this must be done in a constructor)`
var yahoo public : int;
var yahooTest : int;
var yahoo2, yahoo3 public : int;
cons (x, y, z : int)
{
this.x = x;
this.y = y;
this.z = z;
`constructor methods can invoke their base method kinda like Java (as its more powerful then C++/C# approch)`
base.cons(x, y, z);
}
cons (x : num)
{
}
cons (x : num, y, z : int)
{
}
`Return type goes at the end`
`single is the same as 'static' in C# or 'final' in Java`
func simpleMethod() single : int
{
return 0;
}
@[MyAttribute("SomeValue")]
func foo(i : int) : tuple[value : int, value2 : num]
{
var myTemplate = MyTemplate~[int];
`Test setting vars in different ways`
var i2 = i;
var i2 = (i);
var i2 = (i + 1);
var i2 : int = 1;
`Test setting var sets in different ways`
var i2 = {i};
var i4, i5 = {i, i2};
`Test setting var to method return`
var i = foo2();
var i : int = foo2();
var myTuple = foo3();
i = myTuple.value;
`text types`
var myText : text = "Hello";
def myText2 = "Hello";
var myText3 =
"Hi
By";
i2 = i;
var x = Foo(0, 1);
for (var i = 0; i != 1; ++i)
{
i = 128;
}
foreach (var i in list)
{
i = 128;
}
loop (var i in 0..10)
{
i = 128;
}
while (false)
{
i = 128;
continue;
break;
}
dowhile (false)
{
i = 128;
}
if (false)
{
i = 128;
}
elif (true)
{
i = 128;
}
else
{
i = 128;
}
block
{
i = 128;
}
`Use syntax of native lang to target low level features (such as pointers in C, Nim or C# etc)`
native
{
&i += 1;
}
return tuple(0, 1);
}
}
`Classes dont support virtual methods and are alocated on the heap (GC collected)`
class MyClass
{
func foo()
{
var t : tuple[result : Exception, hit : RayHit];
try (t = rayHit())`Anything that returns a Exception type must be wrapped in a try`
{
if (t.result.succeeded)
{
t.hit.pos = 0;
}
}
var t2 = rayHit();
}
}
`Structs dont support virtual methods and are alocated on the stack (no GC collection needed)`
struct MyStruct
{
var x, y, z : num;
operator[+](MyStruct value, MyStruct value2)
{
value.x += value.x;
value.y += value.x;
value.z += value.x;
return value;
}
}
`More though needs to go into templates but here is a general idea`
class MyTemplate~[T]
{
var value : T;
func foo(i : T)
{
when (typeof(i) == typeof(T))
{
value = i;
}
elwhen (typeof(i) == typeof(MyStruct))
{
`do stuff...`
}
else
{
`do stuff...`
}
}
func foo~[T2](i : T2) : T
{
return value + i;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment