simple() void {

a=1 //immutable variable
b``=2 //declare a mutable variable
b`=3 //Modify a mutable variable

//Some people rather use words so here are alternatives.
decl bb = 2
bb mut= 3

//however for a variable that is not a single word you may skip mut=
decl myarray = int[123]
myarray[0] mut = 1
myarray[5] = 3

//you may also declare like the below, which only exist within the if statement
if (constVar=5) > 0 { }
if (mutableVar decl=5) > 0 { mutableVar++ }
//These initalize to default value, which is 0 for ints and floats
c``=int
alternative``=$int //old style, will be removed if there's no problems with the new style

d``=u8[123] //128 unsigned byte array
e``=int //int is either 32 or 64bits. 32bit builds haven't been tested
f``=s64[10] //10 element array of 8bytes/64bits. 80byte in total
decl int g, h=5 //Both g and h are mutable.
$$int gg, hh=5 //same as above

//May or June release will have a better WriteLine
WriteLine("Simple")
WriteLine(itoa(h).UTF8) //Both of these functions are defined in internal.dio

//Enum and bitflags are defined a few lines down
assert(SimpleEnum.a == 0)
assert(SimpleEnum.b == 1)
assert(SimpleEnum.c == 2)

assert(BitFlags.a == 1)
assert(BitFlags.b == 2)
assert(BitFlags.c == 4)
_Assert(BitFlags.c == 4)
}

enum SimpleEnum { a, b, c}
bitnum BitFlags { a, b, c, d}
_Assert(BitFlags.d == 8)

class SimpleClass {
int? a, b //both are nullable
int c?, d //only c is nullable
f32 f //float
f64 g //double
h=25 //int literal, doesn't take up space in the class
i = "Also a literal"
u8[] varlength_array

test(=d) void { } //You don't have to do anything. d is automatically assigned
static StaticFunc() void {
WriteLine("StaticFunc")
}

//comma seperates variables of same type. Different types require semicolon or newline
test2(int j, k; f64 l) void { }

//Old constructor, likely will remove
//this() { WriteLine("SimpleClass Constructor")}
//this { WriteLine("SimpleClass Destructor")}
_Constructor { WriteLine("SimpleClass Constructor")}
_Constructor(int v) { WriteLine("SimpleClass other constructor")}
_Destructor { WriteLine("SimpleClass Destructor")}

take(SimpleClass own this) u8[] {
//This function destories SimpleClass so the destructor won't run
//Useful for converting one class to another, or pulling out an object to reuse from a class
return varlength_array
}
}

globalVar``=5 //mutable global var

TestFunc(int plainInt, nullableInt?, mutableInt mut, outVariable out; f64 f) f64
//old style of above is ... mutableInt`, outVariable``; f64 f) f64
{
//mutable params are passed by reference and may be modified. out params MUST be written
mutableInt`= nullableInt ?? plainInt //If the left side of ?? is null use the right side
outVariable`=5
return f*2.1
}

//Call the function by doing
//TestFunc(1, null, temp mut, outVar out, 1.2) you may also use out mut or decl/decl mut. We'll see which syntax is more popular
//TestFunc(1, null, temp`, outVar``, 1.2) original style

branch() void
{
//This prints "Hello Defer!" when it gets to the end of the function
defer {WriteLine("Defer!")}
defer {Write("Hello ")}
errdefer {WriteLine("This won't run since this function never returns an error")}
WriteLine("Branch")
//ALL for loops must have curly braces
for i to 3
{
WriteLine(itoa(i).UTF8)
}
WriteLine("")
for element in [4, 8, 5, 2]
{
WriteLine(itoa(element).UTF8)
}
WriteLine("")
z``=5
for z<8 //Acts like a while loop
{
WriteLine(itoa(z).UTF8)
z++
}
WriteLine("True") if z > 5 //single line if statement
if z<5 //If also must have curly brances unless in single line form above
{
WriteLine("Less than 5")
}
else {
WriteLine("z >= 5")
}

myCustom``=CustomEnumerator(9)
for val in myCustom
WriteLine(itoa(val).UTF8)
myCustom.Test(10)
for val in myCustom
WriteLine(itoa(val).UTF8)

cond = 1>0
trueVal = 25
falseVal = 36
result = if(cond, trueVal, falseVal) //Currently the false statement is converted to true statement type.
//If this is a problem you can workaround it by inverting the cond/true/false
WriteLine(itoa(result).UTF8)
}

class CustomEnumerator : Enumerable$int
{
int i
_Constructor(=i) {}
Next() int | std.End {
if ++i < 12
return i
else
return std.End
}
Test(=i) void {}
}

math() void {
WriteLine("math")
t = 1!=2 //true
f = 1==2 //false
if t
WriteLine("t is true")
if f! //not operator goes at the end
WriteLine("f is false")
a ``= 0~ //bitwise compliment is also after the value. a == -1
//common operators exist
a+=2 //is 1
WriteLine(itoa(a).UTF8)
WriteLine(itoa(--a).UTF8)
WriteLine(itoa(1<<2).UTF8)
}
array() void
{
WriteLine("array")
a=[3, 5, 7, 9, 4]
WriteLine("2:")
for i in a[2:] //7 9 4
{
WriteLine(itoa(i).UTF8)
}
WriteLine(":3")
for i in a[:3] //3, 5, 7
{
WriteLine(itoa(i).UTF8)
}
WriteLine("1:3")
for i in a[1:3] //5, 7
{
WriteLine(itoa(i).UTF8)
}
}

struct PlainOldData1 { int a, b, c }
struct PlainOldData2 { int d, e, f }
struct PlainOldDataInherit : PlainOldData1, PlainOldData2
{
int g
}
interface SimpleAddInterface
{
get(int v) int
}

//Classes MAY NOT inherit classes or structs, but they may implement interfaces
class SimpleAddClass : SimpleAddInterface
{
int value
this(int v) {value `= v}
get(int v) int { return v+value }
}
PrintSimpleAddInterface(SimpleAddInterface g) void {
WriteLine("PrintSimpleAddInterface")
WriteLine(itoa(g.get(4)).UTF8)
}

templatedAdd$T(T a, b) int { return a+b }
class Rect$T {
T left, top, right, bottom
Intersect(T x, y) bool
{
return (x>=left && x<=right) && (y>=top && x<=bottom)
}
}

errorExample(int a) int | error //For now only one type and error is allowed
{
errdefer {WriteLine("NOTICE: Returning an error!")}
return error if a > 10
return a * 2;
}

struct OpOverloadStruct
{
int a, b
_Operator + (int v) int { return a+v }
_Operator * (int v) int { return a*v }
_Operator[](int v) int {return v } //Read version
_Operator[](int k, v) int {return a*1000+b*100+k*10+v } //Write version
_Operator[](string k, v) int { Write(k); WriteLine(v); return a } //Write version
Head[](string k, v) int { Write(v); WriteLine(k); return b }
Head[](string k) int { return a*b }
_Operator += (int v) int { a+=v; return a }
}
_Operator - (OpOverloadStruct a; int v) int { return 68 }

OutideFunc(OpOverloadStruct d`; int v) void {
d.a `= v
}
OutideFunc(OpOverloadStruct d`; string v) void {
WriteLine(v)
}

_Extend { OutideFunc }

OperatorOverloadTest() int
{
v``=$OpOverloadStruct
v.a `= 3
v.b `= 7
assert(v[5] == 5)
assert(v+5 == 8)
assert(v*5 == 15)
assert((v[5]`=4) == 3754)
v["He"]`="llo"
v.Head["He"]`="llo"
assert(v.Head["He"] == 21)
v+=2
assert(v.a==5)

OutideFunc(v`, 35)
assert(v.a==35)
v.OutideFunc(41)
assert(v.a==41)
v.OutideFunc("OperatorOverloadTest Successful")
return 0
}

lambda_static(_StaticFunc(int a) int cb) int { return cb(25)*2 }
lambda_typical(_Func(int a) int cb) int { return cb(4) + 30 }

lambda_example() void
{
a``=100
assert(lambda_static(v => v+5)==60)
assert(lambda_typical(v => 6000+a+v)==6134)
}

//internal.dio and deflate.dio are good examples of how to use c code and create a wrapper
//A future release may include a tool to help write wrappers. Contact me if you'd like the current throwaway version

struct Data { int a,b,c,d }

main() int {
temp``=0
simple()
branch()
math()
array()
lambda_example()

{
WriteLine("Data assign example")
decl myData = Data
myData.{a=2, b=3, d=4} //assigns values
WriteLine(itoa(myData.a*myData.b+myData.d).UTF8) //10
myData2 decl = Data().{b=2, c=4}
myData2.{d=2,a=-5}
WriteLine(itoa(myData2.a-myData2.c).UTF8) //-9
}

PrintSimpleAddInterface($SimpleAddClass(20))
WriteLine(itoa(templatedAdd(250, 7)).UTF8)
WriteLine(itoa(templatedAdd$u8(250, 7)).UTF8)

OperatorOverloadTest()
TestFunc(1, null, temp mut, outVar out, 1.2) //decl mut plz

varThatIsntALiteral ``= 25
a ``=$u8[varThatIsntALiteral] //this uses malloc since size isn't known at compile time
//a[30]`=5 //Run time error here if we uncomment
a.Resize(50)
a[30]`=5 //ok

b = errorExample(6) ## {
WriteLine("Shouldn't get here")
return -1;
}
WriteLine(itoa(b).UTF8)
c = errorExample(16) ## {
WriteLine("Always gets here")
return 0;
}
WriteLine("Never gets here")
return -2
}