Declarations are now written |type| identifier;, generally. Functions are similar |void| func() {}, etc. Special declarations still work, etc
This commit is contained in:
@@ -1,64 +1,64 @@
|
||||
import io;
|
||||
|
||||
typedef Vec2 {
|
||||
int x;
|
||||
int y;
|
||||
|int| x;
|
||||
|int| y;
|
||||
|
||||
void print() {
|
||||
|void| print() {
|
||||
print(x);
|
||||
print(" ");
|
||||
print(y);
|
||||
}
|
||||
|
||||
Vec2 add(Vec2 other) {
|
||||
Vec2 toReturn;
|
||||
|Vec2| add(|Vec2| other) {
|
||||
|Vec2| toReturn;
|
||||
toReturn.x = x + other.x;
|
||||
toReturn.y = y + other.y;
|
||||
print();
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
Vec2 subtract(Vec2 other) {
|
||||
Vec2 toReturn;
|
||||
|Vec2| subtract(|Vec2| other) {
|
||||
|Vec2| toReturn;
|
||||
toReturn.x = x - other.x;
|
||||
toReturn.y = y - other.y;
|
||||
print();
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
Vec2 operator+(Vec2 other) {
|
||||
|Vec2| operator+(|Vec2| other) {
|
||||
return add(other);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Vec2 operator-(Vec2 lhs, Vec2 rhs) {
|
||||
|Vec2| operator-(|Vec2| lhs, |Vec2| rhs) {
|
||||
return lhs.subtract(rhs);
|
||||
}
|
||||
|
||||
int main() {
|
||||
Vec2 vector1;
|
||||
Vec2 vector2;
|
||||
|int| main() {
|
||||
|Vec2| vector1;
|
||||
|Vec2| vector2;
|
||||
vector1.x = 3;
|
||||
vector1.y = 9;
|
||||
vector2 = vector1;
|
||||
/* NOTE COMMENT
|
||||
Vec2 vector3;
|
||||
|Vec2| vector3;
|
||||
vector3.x = vector1.x + vector2.x;
|
||||
vector3.y = vector1.y + vector2.y;
|
||||
vector2.print();
|
||||
*/
|
||||
Vec2 addition = vector1 + vector2;
|
||||
|Vec2| addition = vector1 + vector2;
|
||||
print("\n");
|
||||
addition.print();
|
||||
print("\nSubtraction\n");
|
||||
vector2.x = 100;
|
||||
vector2.y = 70;
|
||||
Vec2 subtraction = vector1 - vector2;
|
||||
|Vec2| subtraction = vector1 - vector2;
|
||||
print("\n");
|
||||
print(subtraction.x); print(" "); print(subtraction.y);
|
||||
|
||||
print("\n");
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import io;
|
||||
|
||||
int fibanacci(int num) {
|
||||
|int| fibanacci(|int| num) {
|
||||
if (num < 2)
|
||||
return 1;
|
||||
return fibanacci(num-1) + fibanacci(num-2);
|
||||
}
|
||||
|
||||
int main() {
|
||||
|int| main() {
|
||||
print(fibanacci(4));
|
||||
print("\n");
|
||||
return 0;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* Comment first! */
|
||||
import io;
|
||||
|
||||
int main() {
|
||||
|int| main() {
|
||||
println(1337);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2,24 +2,24 @@ import io;
|
||||
import mem;
|
||||
|
||||
typedef ClassWithConstructor {
|
||||
int data;
|
||||
ClassWithConstructor* construct(int inData) {
|
||||
|int| data;
|
||||
|ClassWithConstructor*| construct(|int| inData) {
|
||||
data = inData;
|
||||
return this;
|
||||
}
|
||||
void printData() {
|
||||
|void| printData() {
|
||||
println(data);
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
ClassWithConstructor object.construct(4);
|
||||
|int| main() {
|
||||
|ClassWithConstructor| object.construct(4);
|
||||
//ClassWithConstructor object;
|
||||
//object.construct(4);
|
||||
object.printData();
|
||||
int a = 8;
|
||||
|int| a = 8;
|
||||
println(a);
|
||||
ClassWithConstructor* objPtr = new<ClassWithConstructor>()->construct(11);
|
||||
|ClassWithConstructor*| objPtr = new<ClassWithConstructor>()->construct(11);
|
||||
objPtr->printData();
|
||||
delete<ClassWithConstructor>(objPtr);
|
||||
return 0;
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
import io;
|
||||
|
||||
typedef DestructorPrint {
|
||||
char* myStr;
|
||||
DestructorPrint* construct(char* str) {
|
||||
|char*| myStr;
|
||||
|DestructorPrint*| construct(|char*| str) {
|
||||
myStr = str;
|
||||
return this;
|
||||
}
|
||||
void destruct() {
|
||||
|void| destruct() {
|
||||
println(myStr);
|
||||
}
|
||||
};
|
||||
|
||||
typedef NoDistruction {
|
||||
int a;
|
||||
void dummyFunc() {}
|
||||
|int| a;
|
||||
|void| dummyFunc() {}
|
||||
};
|
||||
|
||||
void indirPrint() {
|
||||
DestructorPrint testObj.construct("Hello Destructors!");
|
||||
NoDistruction dummy;
|
||||
|void| indirPrint() {
|
||||
|DestructorPrint| testObj.construct("Hello Destructors!");
|
||||
|NoDistruction| dummy;
|
||||
}
|
||||
|
||||
int main() {
|
||||
|int| main() {
|
||||
indirPrint();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import io;
|
||||
|
||||
void nothing() {}
|
||||
|void| nothing() {}
|
||||
|
||||
int main() {
|
||||
|int| main() {
|
||||
nothing();
|
||||
println("It was nothing");
|
||||
return 0;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import io;
|
||||
|
||||
template <T,J> void addAndPrint(T a, J b) {
|
||||
template <T,J> |void| addAndPrint(|T| a, |J| b) {
|
||||
print(a+b);
|
||||
}
|
||||
|
||||
int main() {
|
||||
|int| main() {
|
||||
|
||||
addAndPrint<int,double>(10,12.14159);
|
||||
print("\n");
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import io;
|
||||
|
||||
int ret1() {
|
||||
|int| ret1() {
|
||||
return ret2() / 2;
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
|int| main() {
|
||||
print(ret1());
|
||||
print(ret2());
|
||||
print("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ret2() {
|
||||
|int| ret2() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import io;
|
||||
|
||||
template <T>T addAndPrint(T a, T b) {
|
||||
template <T> |T| addAndPrint(|T| a, |T| b) {
|
||||
print(a+b);
|
||||
return a+b;
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
|int| main() {
|
||||
addAndPrint<int>(10,12);
|
||||
print("\n");
|
||||
|
||||
|
||||
@@ -2,11 +2,11 @@ import mem;
|
||||
import io;
|
||||
|
||||
typedef AnObject {
|
||||
int a;
|
||||
int b;
|
||||
char* c;
|
||||
|int| a;
|
||||
|int| b;
|
||||
|char*| c;
|
||||
|
||||
void print() {
|
||||
|void| print() {
|
||||
print(a+b);
|
||||
print("\n");
|
||||
print(c);
|
||||
@@ -15,8 +15,8 @@ typedef AnObject {
|
||||
};
|
||||
|
||||
|
||||
int main() {
|
||||
AnObject* ptr = new<AnObject>();
|
||||
|int| main() {
|
||||
|AnObject*| ptr = new<AnObject>();
|
||||
ptr->a = 4;
|
||||
ptr->b = 7;
|
||||
ptr->c = "Hello decent memory! Quite a nice feeling\n";
|
||||
@@ -24,4 +24,4 @@ int main() {
|
||||
delete<AnObject>(ptr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
import io;
|
||||
|
||||
typedef firstObject {
|
||||
int objectNum;
|
||||
int other;
|
||||
void print() {
|
||||
|int| objectNum;
|
||||
|int| other;
|
||||
|void| print() {
|
||||
print(other);
|
||||
}
|
||||
void printInd() {
|
||||
|void| printInd() {
|
||||
print();
|
||||
}
|
||||
};
|
||||
|
||||
typedef Int int;
|
||||
|
||||
Int aliasNum;
|
||||
|Int| aliasNum;
|
||||
|
||||
int main() {
|
||||
firstObject wooObject;
|
||||
|int| main() {
|
||||
|firstObject| wooObject;
|
||||
wooObject.objectNum = 7;
|
||||
print(wooObject.objectNum);
|
||||
firstObject* objPtr = &wooObject;
|
||||
|firstObject*| objPtr = &wooObject;
|
||||
objPtr->objectNum = 42;
|
||||
print(objPtr->objectNum);
|
||||
print("\n");
|
||||
|
||||
@@ -2,30 +2,30 @@ import io;
|
||||
import trivial_container;
|
||||
|
||||
typedef RegularObject {
|
||||
int num;
|
||||
trivialContainer<char*> innerContainer;
|
||||
void set(char* message, int number) {
|
||||
|int| num;
|
||||
|trivialContainer<char*>| innerContainer;
|
||||
|void| set(|char*| message, |int| number) {
|
||||
innerContainer.data = message;
|
||||
num = number;
|
||||
}
|
||||
char* get() {
|
||||
|char*| get() {
|
||||
return innerContainer.data;
|
||||
}
|
||||
void print() {
|
||||
|void| print() {
|
||||
print(num);
|
||||
innerContainer.print();
|
||||
}
|
||||
};
|
||||
|
||||
typedef MyIntContainer trivialContainer<int>;
|
||||
MyIntContainer roundabout;
|
||||
RegularObject outsideDec;
|
||||
|MyIntContainer| roundabout;
|
||||
|RegularObject| outsideDec;
|
||||
|
||||
void print(trivialContainer<char*> toPrint) {
|
||||
|void| print(|trivialContainer<char*>| toPrint) {
|
||||
print(toPrint.data);
|
||||
}
|
||||
|
||||
int main() {
|
||||
|int| main() {
|
||||
roundabout.data = 4;
|
||||
outsideDec.set("Hello!", 5);
|
||||
roundabout.print();
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
import io;
|
||||
|
||||
typedef objectA {
|
||||
int a;
|
||||
|int| a;
|
||||
};
|
||||
|
||||
typedef BigObject {
|
||||
objectA a;
|
||||
objectB b;
|
||||
int add() {
|
||||
|objectA| a;
|
||||
|objectB| b;
|
||||
|int| add() {
|
||||
return a.a + b.b;
|
||||
}
|
||||
};
|
||||
|
||||
typedef objectB {
|
||||
int b;
|
||||
|int| b;
|
||||
};
|
||||
|
||||
|
||||
int main() {
|
||||
BigObject c;
|
||||
|int| main() {
|
||||
|BigObject| c;
|
||||
c.a.a = 4;
|
||||
c.b.b = 8;
|
||||
print(c.add());
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import io;
|
||||
|
||||
int addAndPrintInt(int a, int b) {
|
||||
|int| addAndPrintInt(|int| a, |int| b) {
|
||||
print(a+b);
|
||||
return a+b;
|
||||
}
|
||||
|
||||
int main() {
|
||||
|int| main() {
|
||||
|
||||
print(addAndPrintInt(7,12));
|
||||
print("\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@ import io;
|
||||
|
||||
|
||||
typedef template <T,J> TemplateTest {
|
||||
T a;
|
||||
J b;
|
||||
void print() {
|
||||
|T| a;
|
||||
|J| b;
|
||||
|void| print() {
|
||||
print("a: ");
|
||||
print(a);
|
||||
print("\n");
|
||||
@@ -14,10 +14,10 @@ typedef template <T,J> TemplateTest {
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
|int| main() {
|
||||
|
||||
TemplateTest<int, char*> test;
|
||||
TemplateTest<char*, char*> test2;
|
||||
|TemplateTest<int, char*>| test;
|
||||
|TemplateTest<char*, char*>| test2;
|
||||
test.a = 24;
|
||||
test.b = "Hello World";
|
||||
test2.a = "Pi incoming";
|
||||
|
||||
@@ -2,9 +2,9 @@ import io;
|
||||
|
||||
|
||||
typedef template <T> TemplateTest {
|
||||
int a;
|
||||
T b;
|
||||
void print() {
|
||||
|int| a;
|
||||
|T| b;
|
||||
|void| print() {
|
||||
print("a: ");
|
||||
print(a);
|
||||
print("\n");
|
||||
@@ -14,10 +14,10 @@ typedef template <T> TemplateTest {
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
|int| main() {
|
||||
|
||||
TemplateTest<int> test;
|
||||
TemplateTest<char*> test2;
|
||||
|TemplateTest<int>| test;
|
||||
|TemplateTest<char*>| test2;
|
||||
test.a = 5;
|
||||
test.b = 7;
|
||||
test2.a = 9;
|
||||
|
||||
@@ -2,15 +2,15 @@
|
||||
import io;
|
||||
|
||||
typedef FirstObject {
|
||||
int objectNum;
|
||||
void PrintSelf(int a) {
|
||||
|int| objectNum;
|
||||
|void| PrintSelf(|int| a) {
|
||||
print(objectNum);
|
||||
print(a);
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
FirstObject wooObject;
|
||||
|int| main() {
|
||||
|FirstObject| wooObject;
|
||||
wooObject.objectNum = 5;
|
||||
wooObject.PrintSelf(7);
|
||||
print("\n");
|
||||
|
||||
@@ -2,10 +2,10 @@ import io;
|
||||
import trivial_container;
|
||||
|
||||
typedef template <T> TemplateTest {
|
||||
int a;
|
||||
T b;
|
||||
trivialContainer<T> c;
|
||||
void print() {
|
||||
|int| a;
|
||||
|T| b;
|
||||
|trivialContainer<T>| c;
|
||||
|void| print() {
|
||||
print("a: ");
|
||||
print(a);
|
||||
print("\n");
|
||||
@@ -19,17 +19,17 @@ typedef template <T> TemplateTest {
|
||||
|
||||
typedef MyInt int;
|
||||
|
||||
MyInt c;
|
||||
|MyInt| c;
|
||||
|
||||
|
||||
template <T> T addAndPrint(T a, T b) {
|
||||
template <T> |T| addAndPrint(|T| a, |T| b) {
|
||||
print(a+b);
|
||||
return a+b;
|
||||
}
|
||||
|
||||
int main() {
|
||||
TemplateTest<int> test;
|
||||
TemplateTest<char*> test2;
|
||||
|int| main() {
|
||||
|TemplateTest<int>| test;
|
||||
|TemplateTest<char*>| test2;
|
||||
test.a = 5;
|
||||
test.b = 7;
|
||||
test.c.data = 1337;
|
||||
@@ -40,7 +40,7 @@ int main() {
|
||||
test.print();
|
||||
test2.print();
|
||||
|
||||
trivialContainer<char*> testImport;
|
||||
|trivialContainer<char*>| testImport;
|
||||
testImport.data = "From another file! Whoh!";
|
||||
testImport.print();
|
||||
print("\n");
|
||||
@@ -49,4 +49,4 @@ int main() {
|
||||
print("\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import io;
|
||||
import mem;
|
||||
|
||||
int main() {
|
||||
int b;
|
||||
int* a = &b;
|
||||
|int| main() {
|
||||
|int| b;
|
||||
|int*| a = &b;
|
||||
a [ 0 ] = 7;
|
||||
print(a [ 0 ] );
|
||||
print(*a);
|
||||
|
||||
@@ -7,23 +7,23 @@ typedef Trait2 (SecondTrait) {};
|
||||
typedef TwoTrait (FirstTrait, SecondTrait) {};
|
||||
typedef AlreadySpecilized (FirstTrait, SecondTrait) {};
|
||||
|
||||
template <T> void OneTwoFunc(T obj) {
|
||||
template <T> |void| OneTwoFunc(|T| obj) {
|
||||
println("No Traits");
|
||||
}
|
||||
|
||||
template <T(FirstTrait)> void OneTwoFunc(T obj) {
|
||||
template <T(FirstTrait)> |void| OneTwoFunc(|T| obj) {
|
||||
println("First Trait");
|
||||
}
|
||||
|
||||
template <T(SecondTrait)> void OneTwoFunc(T obj) {
|
||||
template <T(SecondTrait)> |void| OneTwoFunc(|T| obj) {
|
||||
println("Second Trait");
|
||||
}
|
||||
|
||||
template <T(FirstTrait, SecondTrait)> void OneTwoFunc(T obj) {
|
||||
template <T(FirstTrait, SecondTrait)> |void| OneTwoFunc(|T| obj) {
|
||||
println("Both Traits");
|
||||
}
|
||||
/*
|
||||
template <AlreadySpecilized> void OneTwoFunc(AlreadySpecilized obj) {
|
||||
template <AlreadySpecilized> |void| OneTwoFunc(|AlreadySpecilized| obj) {
|
||||
println("Already Specilized");
|
||||
}
|
||||
*/
|
||||
@@ -42,12 +42,12 @@ typedef template<T(FirstTrait, SecondTrait)> OneTwoObj {};
|
||||
*};
|
||||
*/
|
||||
|
||||
int main() {
|
||||
NoTraits a;
|
||||
Trait1 b;
|
||||
Trait2 c;
|
||||
TwoTrait d;
|
||||
AlreadySpecilized e;
|
||||
|int| main() {
|
||||
|NoTraits| a;
|
||||
|Trait1| b;
|
||||
|Trait2| c;
|
||||
|TwoTrait| d;
|
||||
|AlreadySpecilized| e;
|
||||
|
||||
OneTwoFunc<NoTraits>(a);
|
||||
OneTwoFunc<Trait1>(b);
|
||||
@@ -57,11 +57,11 @@ int main() {
|
||||
|
||||
println();
|
||||
|
||||
OneTwoObj<NoTraits> alpha;
|
||||
OneTwoObj<Trait1> beta;
|
||||
OneTwoObj<Trait2> gamma;
|
||||
OneTwoObj<TwoTrait> delta;
|
||||
// OneTwoObj<AlreadySpecilized> epsilon;
|
||||
|OneTwoObj<NoTraits>| alpha;
|
||||
|OneTwoObj<Trait1>| beta;
|
||||
|OneTwoObj<Trait2>| gamma;
|
||||
|OneTwoObj<TwoTrait>| delta;
|
||||
// |OneTwoObj<AlreadySpecilized>| epsilon;
|
||||
|
||||
OneTwoFunc<OneTwoObj<NoTraits>>(alpha);
|
||||
OneTwoFunc<OneTwoObj<Trait1>>(beta);
|
||||
|
||||
2
tests/typeExpr.expected_results
Normal file
2
tests/typeExpr.expected_results
Normal file
@@ -0,0 +1,2 @@
|
||||
4
|
||||
8
|
||||
20
tests/typeExpr.krak
Normal file
20
tests/typeExpr.krak
Normal file
@@ -0,0 +1,20 @@
|
||||
import io;
|
||||
|
||||
typedef ClassWithConstructor {
|
||||
|int| data;
|
||||
|ClassWithConstructor*| construct(|int| inData) {
|
||||
data = inData;
|
||||
return this;
|
||||
}
|
||||
|void| printData() {
|
||||
println(data);
|
||||
}
|
||||
};
|
||||
|
||||
|int| main() {
|
||||
|ClassWithConstructor| object.construct(4);
|
||||
object.printData();
|
||||
|int| a = 8;
|
||||
println(a);
|
||||
return 0;
|
||||
}
|
||||
@@ -3,24 +3,24 @@ import mem;
|
||||
import vector;
|
||||
|
||||
typedef AbleToBeDestroyed (Destructable) {
|
||||
void destruct() {
|
||||
|void| destruct() {
|
||||
println("Destroyed!");
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
vector<int> intVec.construct();
|
||||
|int| main() {
|
||||
|vector<int>| intVec.construct();
|
||||
intVec.addEnd(1);
|
||||
intVec.addEnd(3);
|
||||
intVec.addEnd(3);
|
||||
intVec.addEnd(7);
|
||||
for (int i = 0; i < intVec.size; i++;)
|
||||
for (|int| i = 0; i < intVec.size; i++;)
|
||||
print(intVec.at(i));
|
||||
|
||||
println();
|
||||
|
||||
vector<AbleToBeDestroyed>* desVec = new<vector<AbleToBeDestroyed>>()->construct();
|
||||
AbleToBeDestroyed testDestruct;
|
||||
|vector<AbleToBeDestroyed>*| desVec = new<vector<AbleToBeDestroyed>>()->construct();
|
||||
|AbleToBeDestroyed| testDestruct;
|
||||
desVec->addEnd(testDestruct);
|
||||
delete<vector<AbleToBeDestroyed>>(desVec);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user