Wooo! Fixed up remaining bugs in new syntax!

This commit is contained in:
Nathan Braswell
2015-05-09 06:24:56 -04:00
parent acf751c016
commit 87e1853713
47 changed files with 277 additions and 284 deletions

View File

@@ -26,7 +26,7 @@ WS = actual_white | WS comment WS | WS comment | ;
# cpp_comment lets us do stuff like ending a statement with a cpp comment - c comments already work as they don't eat the return
maybe_line_white = "( | )+" | ;
line_end = maybe_line_white ";" | maybe_line_white line_break | maybe_line_white cpp_comment ;
line_end = maybe_line_white ";" | maybe_line_white line_break | maybe_line_white cpp_comment | WS c_comment line_end ;
# line_end = "( | )+" ";" | "( | )+" line_break | "( | )+" cpp_comment | ";" | line_break | cpp_comment ;
# line_end = WS ";" | WS line_break | WS cpp_comment ;

View File

@@ -580,7 +580,12 @@ NodeTree<ASTData>* ASTTransformation::transform(NodeTree<Symbol>* from, NodeTree
// NodeTree<ASTData>* newIdentifier = transform(children[1], scope); //Transform the identifier
// newIdentifier->getDataRef()->valueType = Type(concatSymbolTree(children[0]));//set the type of the identifier
std::string newIdentifierStr = concatSymbolTree(children[0]);
Type* identifierType = typeFromTypeNode(children[2], scope, templateTypeReplacements);
Type* identifierType;
if (children.size() > 1 && concatSymbolTree(children[1]) == ".")
identifierType = typeFromTypeNode(children.back(), scope, templateTypeReplacements);
else
identifierType = typeFromTypeNode(children[2], scope, templateTypeReplacements);
std::cout << "Declaring an identifier " << newIdentifierStr << " to be of type " << identifierType->toString() << std::endl;
NodeTree<ASTData>* newIdentifier = new NodeTree<ASTData>("identifier", ASTData(identifier, Symbol(newIdentifierStr, true), identifierType));
addToScope(newIdentifierStr, newIdentifier, scope);
@@ -588,20 +593,20 @@ NodeTree<ASTData>* ASTTransformation::transform(NodeTree<Symbol>* from, NodeTree
addToScope("~enclosing_scope", newNode, newIdentifier);
newNode->addChild(newIdentifier);
if (children.size() > 2 && concatSymbolTree(children[2]) == ".") {
if (children.size() > 1 && concatSymbolTree(children[1]) == ".") {
//A bit of a special case for declarations - if there's anything after just the normal 1 node declaration, it's either
//an expression that is assigned to the declaration (int a = 4;) or a member call (Object a.constructAThing())
//This code is a simplified version of the code in function_call with respect to access_operation.
//Note that in this case, what is lhs there is our newIdentifier here (the declaration of the left side of the access operation)
auto sliced = slice(children, 4, -1);
auto sliced = slice(children, 3, -3);
std::vector<NodeTree<ASTData>*> initPositionFuncParams = transformChildren(sliced, std::set<int>(), scope, types, templateTypeReplacements);
NodeTree<ASTData>* rhs = transform(children[3], identifierType->typeDefinition, mapNodesToTypes(initPositionFuncParams), templateTypeReplacements); //If an access operation, then the right side will be in the lhs's type's scope
NodeTree<ASTData>* rhs = transform(children[2], identifierType->typeDefinition, mapNodesToTypes(initPositionFuncParams), templateTypeReplacements); //If an access operation, then the right side will be in the lhs's type's scope
std::vector<NodeTree<ASTData>*> transformedChildren; transformedChildren.push_back(newIdentifier); transformedChildren.push_back(rhs);
NodeTree<ASTData>* accessFuncCall = doFunction(scope, ".", transformedChildren, templateTypeReplacements);
accessFuncCall->getDataRef()->valueType = rhs->getDataRef()->valueType;
//Now we borrow a bit of code from function_call below to actually use our new accessFuncCall to setup a "initPosition" function call
//that will follow the identifier in this declaration node
std::string initPosFuncName = newIdentifierStr + "." + concatSymbolTree(children[3]);
std::string initPosFuncName = newIdentifierStr + "." + concatSymbolTree(children[2]);
NodeTree<ASTData>* initPositionFuncCall = new NodeTree<ASTData>(initPosFuncName, ASTData(function_call, Symbol(initPosFuncName, true)));
initPositionFuncCall->addChild(accessFuncCall);
initPositionFuncCall->getDataRef()->valueType = accessFuncCall->getDataRef()->valueType;
@@ -998,7 +1003,7 @@ NodeTree<ASTData>* ASTTransformation::templateFunctionLookup(NodeTree<ASTData>*
if (!traitsEqual)
continue;
std::vector<NodeTree<Symbol>*> functionParameters = slice(templateSyntaxTree->getChildren(), 2, -3, 2); //skip name, intervening commas, return type, and the code block
std::vector<NodeTree<Symbol>*> functionParameters = slice(templateSyntaxTree->getChildren(), 2, -4, 2); //skip name, intervening commas, return type, and the code block
std::cout << functionParameters.size() << " " << types.size() << std::endl;
if (functionParameters.size() != types.size())
continue;

View File

@@ -4,11 +4,11 @@ __if_comp__ __C__ simple_passthrough """
#include <stdio.h>
"""
|void| println() {
fun println() : void {
print("\n");
}
|void| print(|char*| toPrint) {
fun print(toPrint: char*) : void {
__if_comp__ __C__ {
simple_passthrough(toPrint = toPrint::) """
printf(toPrint);
@@ -17,20 +17,20 @@ __if_comp__ __C__ simple_passthrough """
return;
}
|void| println(|char*| toPrint) {
fun println(toPrint: char*) : void {
print(toPrint);
println();
}
|void| print(|string| toPrint) {
fun print(toPrint: string) : void {
print(toPrint.toCharArray());
}
|void| println(|string| toPrint) {
fun println(toPrint: string): void {
println(toPrint.toCharArray());
}
|void| print(|int| toPrint) {
fun print(toPrint: int): void {
__if_comp__ __C__ {
simple_passthrough(toPrint = toPrint::) """
printf("%d", toPrint);
@@ -39,12 +39,12 @@ __if_comp__ __C__ simple_passthrough """
return;
}
|void| println(|int| toPrint) {
fun println(toPrint: int): void {
print(toPrint);
println();
}
|void| print(|float| toPrint) {
fun print(toPrint: float): void {
__if_comp__ __C__ {
simple_passthrough(toPrint = toPrint::) """
printf("%f", toPrint);
@@ -53,7 +53,7 @@ __if_comp__ __C__ simple_passthrough """
return;
}
|void| print(|double| toPrint) {
fun print(toPrint: double) : void{
__if_comp__ __C__ {
simple_passthrough(toPrint = toPrint::) """
printf("%f", toPrint);
@@ -62,20 +62,15 @@ __if_comp__ __C__ simple_passthrough """
return;
}
|void| println(|float| toPrint) {
fun println(toPrint: float): void {
print(toPrint);
println();
}
|void| println(|double| toPrint){
fun println(toPrint: double): void {
print(toPrint);
println();
}

View File

@@ -2,7 +2,7 @@ __if_comp__ __C__ simple_passthrough(::"-lm") """
#include <math.h>
"""
|int| fibanacci(|int| num) {
fun fibanacci(num: int): int {
if (num < 2)
return 1;
return fibanacci(num-1) + fibanacci(num-2);
@@ -12,9 +12,9 @@ __if_comp__ __C__ simple_passthrough(::"-lm") """
* Trig Functions
********************/
|double| atan(|double| arg)
fun atan(arg: double): double
{
|double| ans = 0;
var ans: double = 0;
__if_comp__ __C__{
simple_passthrough(arg = arg, ans = ans : ans = ans :) """
ans = atan(arg);
@@ -24,9 +24,9 @@ __if_comp__ __C__ simple_passthrough(::"-lm") """
return ans;
}//end atan function
|double| atan2(|double| x, |double| y)
fun atan2(x: double, y: double): double
{
|double| ans = 0;
var ans: double = 0;
__if_comp__ __C__{
simple_passthrough(x = x, y = y, ans = ans : ans = ans :) """
ans = atan2(x,y);
@@ -36,9 +36,9 @@ __if_comp__ __C__ simple_passthrough(::"-lm") """
return ans;
}//end atan2 function
|double| acos(|double| arg)
fun acos(arg: double): double
{
|double| ans = 0;
var ans: double = 0;
__if_comp__ __C__{
simple_passthrough(arg = arg, ans = ans : ans = ans :) """
ans = acos(arg);
@@ -48,9 +48,9 @@ __if_comp__ __C__ simple_passthrough(::"-lm") """
return ans;
}//end acos function
|double| asin(|double| arg)
fun asin(arg: double): double
{
|double| ans = 0;
var ans: double = 0;
__if_comp__ __C__{
simple_passthrough(arg = arg, ans = ans : ans = ans :) """
ans = asin(arg);
@@ -60,9 +60,9 @@ __if_comp__ __C__ simple_passthrough(::"-lm") """
return ans;
}//end asin function
|double| tan(|double| arg)
fun tan(arg: double): double
{
|double| ans = 0;
var ans: double = 0;
__if_comp__ __C__{
simple_passthrough(arg = arg, ans = ans : ans = ans :) """
ans = tan(arg);
@@ -72,9 +72,9 @@ __if_comp__ __C__ simple_passthrough(::"-lm") """
return ans;
}//end tan function
|double| cos(|double| arg)
fun cos(arg: double): double
{
|double| ans = 0;
var ans: double = 0;
__if_comp__ __C__{
simple_passthrough(arg = arg, ans = ans : ans = ans :) """
ans = cos(arg);
@@ -84,9 +84,9 @@ __if_comp__ __C__ simple_passthrough(::"-lm") """
return ans;
}//end cos function
|double| sin(|double| arg)
fun sin(arg: double): double
{
|double| ans = 0;
var ans: double = 0;
__if_comp__ __C__{
simple_passthrough(arg = arg, ans = ans : ans = ans :) """
ans = sin(arg);
@@ -99,11 +99,3 @@ __if_comp__ __C__ simple_passthrough(::"-lm") """
//|int| NotPi = 3;
//|double| STD_PI = 4*atan(1);

View File

@@ -4,8 +4,8 @@ __if_comp__ __C__ simple_passthrough """
/* we have a template versions so we don't have to cast (because we don't have that yet) */
template <T> |T*| malloc(|int| size) {
|T*| memPtr;
fun malloc<T>(size: int): T* {
var memPtr: T*;
__if_comp__ __C__ {
simple_passthrough( size = size, memPtr = memPtr : memPtr = memPtr :) """
memPtr = malloc(size);
@@ -14,7 +14,7 @@ template <T> |T*| malloc(|int| size) {
return memPtr;
}
template <T> |void| free(|T*| memPtr) {
fun free<T>(memPtr: T*): void {
__if_comp__ __C__ {
simple_passthrough(memPtr = memPtr ::) """
free(memPtr);
@@ -22,9 +22,9 @@ template <T> |void| free(|T*| memPtr) {
}
}
template <T> |int| sizeof() {
|T| testObj;
|int| result;
fun sizeof<T>(): int {
var testObj: T;
var result: int;
__if_comp__ __C__ {
simple_passthrough(testObj = testObj : result = result:) """
int result = sizeof(testObj);
@@ -33,32 +33,32 @@ template <T> |int| sizeof() {
return result;
}
template <T> |T*| new(|int| count) {
fun new<T>(count: int): T* {
return malloc<T>( sizeof<T>() * count );
}
template <T> |T*| new() {
fun new<T>(): T* {
return new<T>(1);
}
/* We specilize on the trait Destructable to decide on whether or not the destructor should be called */
template <T> |void| delete(|T*| toDelete, |int| itemCount) {
fun delete<T>(toDelete: T*, itemCount: int): void {
delete<T>(toDelete);
}
/* Calling this with itemCount = 0 allows you to delete destructable objects without calling their destructors. */
template <T(Destructable)> |void| delete(|T*| toDelete, |int| itemCount) {
for (|int| i = 0; i < itemCount; i++;)
fun delete<T(Destructable)>(toDelete: T*, itemCount: int): void {
for (var i: int = 0; i < itemCount; i++;)
toDelete[i].destruct();
delete<T>(toDelete);
}
/* We specilize on the trait Destructable to decide on whether or not the destructor should be called */
template <T> |void| delete(|T*| toDelete) {
fun delete<T>(toDelete: T*): void {
free<T>(toDelete);
}
template <T(Destructable)> |void| delete(|T*| toDelete) {
fun delete<T(Destructable)>(toDelete: T*): void {
toDelete->destruct();
free<T>(toDelete);
}

View File

@@ -2,12 +2,12 @@ import vector;
import mem;
typedef string (Destructable) {
|vector::vector<char>| data;
|string*| construct() {
var data: vector::vector<char>;
fun construct(): string* {
data.construct();
return this;
}
|string*| construct(|char*| str) {
fun construct(str: char*): string* {
data.construct();
while(*str) {
data.addEnd(*str);
@@ -16,9 +16,9 @@ typedef string (Destructable) {
return this;
}
|char*| toCharArray() {
|char*| out = mem::new<char>(data.size);
for (|int| i = 0; i < data.size; i++;)
fun toCharArray(): char* {
var out: char* = mem::new<char>(data.size);
for (var i: int = 0; i < data.size; i++;)
out[i] = data.get(i);
return out;
}

View File

@@ -1,8 +1,8 @@
import io;
typedef template <T> trivialContainer {
|T| data;
|void| print() {
typedef trivialContainer<T> {
var data: T;
fun print(): void {
io::print(data);
}
};

View File

@@ -1,11 +1,11 @@
template<T> |T| greater(|T| a, |T| b) {
fun greater<T>(a: T, b: T): T {
if (a > b)
return a;
return b;
}
template<T> |T| lesser(|T| a, |T| b) {
fun lesser<T>(a: T, b: T): T {
if (a > b)
return b;
return a;

View File

@@ -2,27 +2,27 @@ import mem:*;
import util:*;
import io:*;
typedef template<T> vector (Destructable) {
|T*| data;
|int| size;
|int| available;
typedef vector<T> (Destructable) {
var data: T*;
var size: int;
var available: int;
|vector<T>*| construct() {
fun construct(): vector<T>* {
size = 0;
available = 8;
data = new<T>(8);
return this;
}
|void| destruct() {
fun destruct(): void {
delete<T>(data);
}
|bool| resize(|int| newSize) {
|T*| newData = new<T>(newSize);
fun resize(newSize: int): bool {
var newData: T* = new<T>(newSize);
if (!newData)
return false;
for (|int| i = 0; i < lesser<int>(size, newSize); i++;)
for (var i: int = 0; i < lesser<int>(size, newSize); i++;)
newData[i] = data[i];
delete<T>(data, 0);
data = newData;
@@ -30,11 +30,11 @@ typedef template<T> vector (Destructable) {
return true;
}
|T| at(|int| index) {
fun at(index: int): T {
return get(index);
}
|T| get(|int| index) {
fun get(index: int): T {
if (index < 0 || index >= size) {
println("Vector access out of bounds! Retuning 0th element as sanest option");
print("Vector tried to access element: ");
@@ -44,17 +44,18 @@ typedef template<T> vector (Destructable) {
return data[index];
}
|T*| getBackingMemory() { return data; }
fun getBackingMemory(): T* { return data; }
|void| set(|int| index, |T| dataIn) {
fun set(index: int, dataIn: T): void {
if (index < 0 || index >= size)
return;
data[index] = dataIn;
}
|void| addEnd(|T| dataIn) {
fun addEnd(dataIn: T): void {
size++;
if (size >= available)
resize(size*2);
data[size-1] = dataIn;
}
};

View File

@@ -4,13 +4,13 @@ __if_comp__ __C__ simple_passthrough """
int diff = 7;
"""
|void| print_it() {
fun print_it(): void {
__if_comp__ __C__ simple_passthrough """
printf("diff_file: %d\n", diff);
"""
}
|void| print_it(|int| i) {
fun print_it(i: int): void {
__if_comp__ __C__ simple_passthrough(i = i::) """
printf("diff_file: %d\n", i);
"""

View File

@@ -1,7 +1,7 @@
|int| sameVar;
|int| sameFun() { return 5; }
var sameVar: int;
fun sameFun(): int { return 5; }
typedef classTester {
|int| method() { return 8; }
fun method(): int { return 8; }
}

View File

@@ -1,6 +1,6 @@
|int| sameVar;
|int| sameFun() { return 6; }
var sameVar: int;
fun sameFun(): int { return 6; }
typedef classTester {
|int| method() { return 9; }
fun method(): int { return 9; }
}

View File

@@ -1,27 +1,27 @@
|int| qualified_variable = 7;
|int| qualified_func() { return 9; }
var qualified_variable: int = 7;
fun qualified_func(): int { return 9; }
typedef qualified_class {
|int| number;
|qualified_class*| construct(|int| num) {
var number: int;
fun construct(num: int): qualified_class* {
number = num;
return this;
}
|int| get() {
fun get(): int {
return number;
}
};
typedef template <T> qualified_container {
|T| data;
|qualified_container<T>*| construct(|T| dataIn) {
typedef qualified_container<T> {
var data: T;
fun construct(dataIn: T): qualified_container<T>* {
data = dataIn;
}
|T| get() {
fun get(): T {
return data;
}
};
template<T> |T| qualified_id(|T| it) {
fun qualified_id<T>(it: T): T {
return it;
}

View File

@@ -1,27 +1,27 @@
|int| unqualifed_variable = 8;
|int| unqualified_func() { return 10; }
var unqualifed_variable: int = 8;
fun unqualified_func(): int { return 10; }
typedef unqualified_class {
|int| number;
|unqualified_class*| construct(|int| num) {
var number: int;
fun construct(num: int): unqualified_class* {
number = num;
return this;
}
|int| get() {
fun get(): int {
return number;
}
};
typedef template <T> unqualified_container {
|T| data;
|unqualified_container<T>*| construct(|T| dataIn) {
typedef unqualified_container<T> {
var data: T;
fun construct(dataIn: T): unqualified_container<T>* {
data = dataIn;
}
|T| get() {
fun get(): T {
return data;
}
};
template<T> |T| unqualified_id(|T| it) {
fun unqualified_id<T>(it: T): T {
return it;
}

View File

@@ -1,44 +1,44 @@
import io:*;
typedef Vec2 {
|int| x;
|int| y;
var x: int;
var y: int;
|void| print() {
fun print(): void {
print(x);
print(" ");
print(y);
}
|Vec2| add(|Vec2| other) {
|Vec2| toReturn;
fun add(other: Vec2): Vec2 {
var toReturn: Vec2;
toReturn.x = x + other.x;
toReturn.y = y + other.y;
print();
return toReturn;
}
|Vec2| subtract(|Vec2| other) {
|Vec2| toReturn;
fun subtract(other: Vec2): Vec2 {
var toReturn: Vec2;
toReturn.x = x - other.x;
toReturn.y = y - other.y;
print();
return toReturn;
}
|Vec2| operator+(|Vec2| other) {
fun operator+(other: Vec2): Vec2 {
return add(other);
}
};
|Vec2| operator-(|Vec2| lhs, |Vec2| rhs) {
fun operator-(lhs: Vec2, rhs: Vec2): Vec2 {
return lhs.subtract(rhs);
}
|int| main() {
|Vec2| vector1;
|Vec2| vector2;
fun main(): int {
var vector1: Vec2;
var vector2: Vec2;
vector1.x = 3;
vector1.y = 9;
vector2 = vector1;
@@ -48,13 +48,13 @@ typedef Vec2 {
vector3.y = vector1.y + vector2.y;
vector2.print();
*/
|Vec2| addition = vector1 + vector2;
var addition: Vec2 = vector1 + vector2;
print("\n");
addition.print();
print("\nSubtraction\n");
vector2.x = 100;
vector2.y = 70;
|Vec2| subtraction = vector1 - vector2;
var subtraction: Vec2 = vector1 - vector2;
print("\n");
print(subtraction.x); print(" "); print(subtraction.y);

View File

@@ -1,12 +1,12 @@
import io:*;
|int| fibanacci(|int| num) {
fun fibanacci(num: int): int {
if (num < 2)
return 1;
return fibanacci(num-1) + fibanacci(num-2);
}
|int| main() {
fun main(): int {
print(fibanacci(4));
print("\n");
return 0;

View File

@@ -1,18 +1,18 @@
import io;
|int| main() {
fun main(): void {
io::println("Spam");
|int| x = 4;
var x: int = 4;
x += 3;
x++;
|int| y = 6;
|int| z = x + y;
|int| q = z+z;
|int| q2 = z*3;
|int| q3 = y + y;
var y :int = 6;
var z :int = x + y;
var q :int = z+z;
var q2:int = z*3;
var q3:int = y + y;
io::println(q3);
io::println(z);
io::println(q);
for (|int| i = 0; i < 20; i++;) z++;
for (var i:int = 0; i < 20; i++;) z++;
if (z > 20) io::println("We'll find out.");
io::println(z);
}

View File

@@ -6,15 +6,15 @@ __if_comp__ __C__ simple_passthrough """
int same = 5;
"""
|int| main() {
fun main(): int {
__if_comp__ __C__ simple_passthrough """
printf("same_file: %d\n", same);
"""
c_passthrough_diff::print_it();
|int| i = 7;
|int| j = 6;
var i: int = 7;
var j: int = 6;
__if_comp__ __C__ simple_passthrough(i = i, j = j : j = j:) """
j = i + j;
"""

View File

@@ -1,12 +1,12 @@
import vector:*;
import io:*;
template <T> |T| test(|vector<T>| a) {
fun test<T>(a: vector<T>): T {
return a.at(0);
}
|int| main() {
|vector<int>| a.construct();
fun main(): int {
var a.construct(): vector<int>;
a.addEnd(2);
println(test<int>(a));
return 0;

View File

@@ -1,7 +1,7 @@
/* Comment first! */
import io:*;
|int| main() {
fun main(): int {
println(1337) /*how bout now*/
println(42) //or now
return 0;

View File

@@ -2,24 +2,24 @@ import io:*;
import mem:*;
typedef ClassWithConstructor {
|int| data;
|ClassWithConstructor*| construct(|int| inData) {
var data: int;
fun construct(inData: int): ClassWithConstructor* {
data = inData;
return this;
}
|void| printData() {
fun printData(): void {
println(data);
}
};
|int| main() {
|ClassWithConstructor| object.construct(4);
fun main(): int {
var object.construct(4): ClassWithConstructor;
//ClassWithConstructor object;
//object.construct(4);
object.printData();
|int| a = 8;
var a: int = 8;
println(a);
|ClassWithConstructor*| objPtr = new<ClassWithConstructor>()->construct(11);
var objPtr: ClassWithConstructor* = new<ClassWithConstructor>()->construct(11);
objPtr->printData();
delete<ClassWithConstructor>(objPtr);
return 0;

View File

@@ -1,27 +1,27 @@
import io:*;
typedef DestructorPrint {
|char*| myStr;
|DestructorPrint*| construct(|char*| str) {
var myStr: char*;
fun construct(str: char*): DestructorPrint* {
myStr = str;
return this;
}
|void| destruct() {
fun destruct(): void {
println(myStr);
}
};
typedef NoDistruction {
|int| a;
|void| dummyFunc() {}
var a: int;
fun dummyFunc(): void {}
};
|void| indirPrint() {
|DestructorPrint| testObj.construct("Hello Destructors!");
|NoDistruction| dummy;
fun indirPrint(): void {
var testObj.construct("Hello Destructors!"): DestructorPrint;
var dummy: NoDistruction;
}
|int| main() {
fun main(): int {
indirPrint();
return 0;
}

View File

@@ -1,7 +1,7 @@
import io:*;
|int| main() {
fun main(): int {
if (1>2) {
println("Wrong");
} else {

View File

@@ -1,8 +1,8 @@
import io;
|void| nothing() {}
fun nothing(): void {}
|int| main() {
fun main(): int {
nothing();
io::println("It was nothing");
return 0;

View File

@@ -1,10 +1,10 @@
import io:*;
template <T,J> |void| addAndPrint(|T| a, |J| b) {
fun addAndPrint<T,J>(a: T, b: J): void {
print(a+b);
}
|int| main() {
fun main(): int {
addAndPrint<int,double>(10,12.14159);
print("\n");

View File

@@ -1,17 +1,17 @@
import io:*;
|int| ret1() {
fun ret1(): int {
return ret2() / 2;
}
|int| main() {
fun main(): int {
print(ret1());
print(ret2());
print("\n");
return 0;
}
|int| ret2() {
fun ret2(): int {
return 2;
}

View File

@@ -1,11 +1,11 @@
import io;
template <T> |T| addAndPrint(|T| a, |T| b) {
fun addAndPrint<T>(a: T, b: T): T {
io::print(a+b);
return a+b;
}
|int| main() {
fun main(): int {
addAndPrint<int>(10,12);
io::print("\n");

View File

@@ -2,11 +2,11 @@ import mem:*;
import io:*;
typedef AnObject {
|int| a;
|int| b;
|char*| c;
var a: int;
var b: int;
var c: char*;
|void| print() {
fun print(): void {
print(a+b);
print("\n");
print(c);
@@ -15,8 +15,8 @@ typedef AnObject {
};
|int| main() {
|AnObject*| ptr = new<AnObject>();
fun main(): int {
var ptr: AnObject* = new<AnObject>();
ptr->a = 4;
ptr->b = 7;
ptr->c = "Hello decent memory! Quite a nice feeling\n";

View File

@@ -1,25 +1,25 @@
import io:*;
typedef firstObject {
|int| objectNum;
|int| other;
|void| print() {
var objectNum: int;
var other: int;
fun print(): void {
print(other);
}
|void| printInd() {
fun printInd(): void {
print();
}
};
typedef Int int;
|Int| aliasNum;
var aliasNum: Int;
|int| main() {
|firstObject| wooObject;
fun main(): int {
var wooObject: firstObject;
wooObject.objectNum = 7;
print(wooObject.objectNum);
|firstObject*| objPtr = &wooObject;
var objPtr: firstObject* = &wooObject;
objPtr->objectNum = 42;
print(objPtr->objectNum);
print("\n");

View File

@@ -2,30 +2,30 @@ import io:*;
import trivial_container:*;
typedef RegularObject {
|int| num;
|trivialContainer<char*>| innerContainer;
|void| set(|char*| message, |int| number) {
var num: int;
var innerContainer: trivialContainer<char*>;
fun set(message: char*, number: int): void {
innerContainer.data = message;
num = number;
}
|char*| get() {
fun get(): char* {
return innerContainer.data;
}
|void| print() {
fun print(): void {
print(num);
innerContainer.print();
}
};
typedef MyIntContainer trivialContainer<int>;
|MyIntContainer| roundabout;
|RegularObject| outsideDec;
var roundabout: MyIntContainer;
var outsideDec: RegularObject;
|void| print(|trivialContainer<char*>| toPrint) {
fun print(toPrint: trivialContainer<char*>): void {
print(toPrint.data);
}
|int| main() {
fun main(): int {
roundabout.data = 4;
outsideDec.set("Hello!", 5);
roundabout.print();

View File

@@ -1,7 +1,7 @@
import io:*;
|int| main() {
fun main(): int {
if (1 != 2)
println("Correct");
}

View File

@@ -2,16 +2,16 @@ import io;
import scopeQualified;
import scopeUnqualified : * ;
|int| main() {
fun main(): int {
io::println("Qualified io!");
// Defined in scopeQualified
io::println(scopeQualified::qualified_variable);
io::println(scopeQualified::qualified_func());
|scopeQualified::qualified_class| qClass.construct(11);
var qClass.construct(11): scopeQualified::qualified_class;
io::println(qClass.get());
|scopeQualified::qualified_container<char*>| sayQualified.construct("Qualified Container!");
var sayQualified.construct("Qualified Container!"): scopeQualified::qualified_container<char*>;
io::println(sayQualified.get());
io::println(scopeQualified::qualified_id<char*>("Even template functions qualified!"));
@@ -21,10 +21,10 @@ import scopeUnqualified : * ;
// Defined in scopeUnqualified
io::println(unqualifed_variable);
io::println(unqualified_func());
|unqualified_class| uqClass.construct(12);
var uqClass.construct(12): unqualified_class;
io::println(uqClass.get());
|unqualified_container<char*>| sayUnqualified.construct("Unqualified Container!");
var sayUnqualified.construct("Unqualified Container!"): unqualified_container<char*>;
io::println(sayUnqualified.get());
io::println(unqualified_id<char*>("Even template functions unqualified!"));

View File

@@ -1,6 +1,6 @@
import io:*
|int| main() {
fun main(): int {
println("no semicolons!")
if (1 < 2) println("still no!")
println("and again")

View File

@@ -1,24 +1,24 @@
import io:*;
typedef objectA {
|int| a;
var a: int;
};
typedef BigObject {
|objectA| a;
|objectB| b;
|int| add() {
var a: objectA;
var b: objectB;
fun add(): int {
return a.a + b.b;
}
};
typedef objectB {
|int| b;
var b: int;
};
|int| main() {
|BigObject| c;
fun main(): int {
var c: BigObject;
c.a.a = 4;
c.b.b = 8;
print(c.add());

View File

@@ -2,23 +2,23 @@ import io:*
import sameNameOne
import sameNameTwo
|int| sameVar;
|int| sameFun() { return 4; }
var sameVar: int;
fun sameFun(): int { return 4; }
typedef classTester {
|int| method() {
fun method(): int {
return 7
}
}
|int| main() {
fun main(): int {
sameVar = 1
sameNameOne::sameVar = 2
sameNameTwo::sameVar = 3
|classTester| class1;
|sameNameOne::classTester| class2;
|sameNameTwo::classTester| class3;
var class1: classTester;
var class2: sameNameOne::classTester;
var class3: sameNameTwo::classTester;
println(sameVar)
println(sameNameOne::sameVar)

View File

@@ -1,11 +1,11 @@
import io:*;
|int| addAndPrintInt(|int| a, |int| b) {
fun addAndPrintInt(a: int, b: int): int {
print(a+b);
return a+b;
}
|int| main() {
fun main(): int {
print(addAndPrintInt(7,12));
print("\n");

View File

@@ -1,10 +1,10 @@
import io;
typedef template <T,J> TemplateTest {
|T| a;
|J| b;
|void| print() {
typedef TemplateTest<T,J> {
var a: T;
var b: J;
fun print(): void {
io::print("a: ");
io::print(a);
io::print("\n");
@@ -14,10 +14,10 @@ typedef template <T,J> TemplateTest {
}
};
|int| main() {
fun main(): int {
|TemplateTest<int, char*>| test;
|TemplateTest<char*, char*>| test2;
var test: TemplateTest<int, char*>;
var test2: TemplateTest<char*, char*>;
test.a = 24;
test.b = "Hello World";
test2.a = "Pi incoming";

View File

@@ -1,10 +1,10 @@
import io;
typedef template <T> TemplateTest {
|int| a;
|T| b;
|void| print() {
typedef TemplateTest<T> {
var a: int;
var b: T;
fun print(): void {
io::print("a: ");
io::print(a);
io::print("\n");
@@ -14,10 +14,10 @@ typedef template <T> TemplateTest {
}
};
|int| main() {
fun main(): int {
|TemplateTest<int>| test;
|TemplateTest<char*>| test2;
var test: TemplateTest<int>;
var test2: TemplateTest<char*>;
test.a = 5;
test.b = 7;
test2.a = 9;

View File

@@ -1,15 +1,15 @@
import io;
typedef FirstObject {
|int| objectNum;
|void| PrintSelf(|int| a) {
var objectNum: int;
fun PrintSelf(a: int): void {
io::print(objectNum);
io::print(a);
}
};
|int| main() {
|FirstObject| wooObject;
fun main(): int {
var wooObject: FirstObject;
wooObject.objectNum = 5;
wooObject.PrintSelf(7);
io::print("\n");

View File

@@ -2,8 +2,8 @@ import io;
import string;
|int| main() {
|string::string| str.construct("hello strings");
fun main(): int {
var str.construct("hello strings"): string::string;
io::println(str);
return 0;
}

View File

@@ -1,11 +1,11 @@
import io:*;
import trivial_container:*;
typedef template <T> TemplateTest {
|int| a;
|T| b;
|trivialContainer<T>| c;
|void| print() {
typedef TemplateTest<T> {
var a: int;
var b: T;
var c: trivialContainer<T>;
fun print(): void {
print("a: ");
print(a);
print("\n");
@@ -19,17 +19,17 @@ typedef template <T> TemplateTest {
typedef MyInt int;
|MyInt| c;
var c: MyInt;
template <T> |T| addAndPrint(|T| a, |T| b) {
fun addAndPrint<T>(a: T, b: T): T {
print(a+b);
return a+b;
}
|int| main() {
|TemplateTest<int>| test;
|TemplateTest<char*>| test2;
fun main(): int {
var test: TemplateTest<int>;
var test2: TemplateTest<char*>;
test.a = 5;
test.b = 7;
test.c.data = 1337;
@@ -40,7 +40,7 @@ template <T> |T| addAndPrint(|T| a, |T| b) {
test.print();
test2.print();
|trivialContainer<char*>| testImport;
var testImport: trivialContainer<char*>;
testImport.data = "From another file! Whoh!";
testImport.print();
print("\n");

View File

@@ -1,9 +1,9 @@
import io:*;
import mem:*;
|int| main() {
|int| b;
|int*| a = &b;
fun main(): int {
var b: int;
var a: int* = &b;
a [ 0 ] = 7;
print(a [ 0 ] );
print(*a);

View File

@@ -1,8 +1,8 @@
import io;
|int| a = 42;
var a: int = 42;
|int| main() {
fun main(): int {
io::println(a);
return 0;
}

View File

@@ -7,19 +7,19 @@ typedef Trait2 (SecondTrait) {};
typedef TwoTrait (FirstTrait, SecondTrait) {};
typedef AlreadySpecilized (FirstTrait, SecondTrait) {};
template <T> |void| OneTwoFunc(|T| obj) {
fun OneTwoFunc<T>(obj: T): void {
println("No Traits");
}
template <T(FirstTrait)> |void| OneTwoFunc(|T| obj) {
fun OneTwoFunc<T(FirstTrait)>(obj: T): void {
println("First Trait");
}
template <T(SecondTrait)> |void| OneTwoFunc(|T| obj) {
fun OneTwoFunc<T(SecondTrait)>(obj: T): void {
println("Second Trait");
}
template <T(FirstTrait, SecondTrait)> |void| OneTwoFunc(|T| obj) {
fun OneTwoFunc<T(FirstTrait, SecondTrait)>(obj: T): void {
println("Both Traits");
}
/*
@@ -30,10 +30,10 @@ template <AlreadySpecilized> |void| OneTwoFunc(|AlreadySpecilized| obj) {
//This should work for objects too!
//To test, we cycle the mapping of traits
typedef template<T> OneTwoObj (FirstTrait) {};
typedef template<T(FirstTrait)> OneTwoObj (SecondTrait) {};
typedef template<T(SecondTrait)> OneTwoObj (FirstTrait, SecondTrait) {};
typedef template<T(FirstTrait, SecondTrait)> OneTwoObj {};
typedef OneTwoObj<T> (FirstTrait) {};
typedef OneTwoObj<T(FirstTrait)> (SecondTrait) {};
typedef OneTwoObj<T(SecondTrait)> (FirstTrait, SecondTrait) {};
typedef OneTwoObj<T(FirstTrait, SecondTrait)> {};
/*
*typedef template<AlreadySpecilized> OneTwoObj {
* void proveSpecilized() {
@@ -42,12 +42,12 @@ typedef template<T(FirstTrait, SecondTrait)> OneTwoObj {};
*};
*/
|int| main() {
|NoTraits| a;
|Trait1| b;
|Trait2| c;
|TwoTrait| d;
|AlreadySpecilized| e;
fun main(): int {
var a: NoTraits;
var b: Trait1;
var c: Trait2;
var d: TwoTrait;
var e: AlreadySpecilized;
OneTwoFunc<NoTraits>(a);
OneTwoFunc<Trait1>(b);
@@ -57,10 +57,10 @@ typedef template<T(FirstTrait, SecondTrait)> OneTwoObj {};
println();
|OneTwoObj<NoTraits>| alpha;
|OneTwoObj<Trait1>| beta;
|OneTwoObj<Trait2>| gamma;
|OneTwoObj<TwoTrait>| delta;
var alpha: OneTwoObj<NoTraits>;
var beta: OneTwoObj<Trait1>;
var gamma: OneTwoObj<Trait2>;
var delta: OneTwoObj<TwoTrait>;
// |OneTwoObj<AlreadySpecilized>| epsilon;
OneTwoFunc<OneTwoObj<NoTraits>>(alpha);

View File

@@ -1,10 +1,10 @@
import io:*;
import math:*;
|int| main()
fun main(): int
{
|double| ans;
|double| STD_PI = 4.0*atan(1.0);
var ans: double;
var STD_PI: double = 4.0*atan(1.0);
println(STD_PI);
/*

View File

@@ -1,20 +1,20 @@
import io;
typedef ClassWithConstructor {
|int| data;
|ClassWithConstructor*| construct(|int| inData) {
var data: int;
fun construct(inData: int): ClassWithConstructor* {
data = inData;
return this;
}
|void| printData() {
fun printData(): void {
io::println(data);
}
};
|int| main() {
|ClassWithConstructor| object.construct(4);
fun main(): int {
var object.construct(4): ClassWithConstructor;
object.printData();
|int| a = 8;
var a :int = 8;
io::println(a);
return 0;
}

View File

@@ -3,25 +3,25 @@ import mem:*;
import vector:*;
typedef AbleToBeDestroyed (Destructable) {
|void| destruct() {
fun destruct(): void {
println("Destroyed!");
}
};
|int| main() {
|vector<int>| intVec.construct();
fun main(): int {
var intVec.construct(): vector<int>;
intVec.addEnd(1);
intVec.addEnd(3);
intVec.addEnd(3);
intVec.addEnd(7);
println(intVec.size);
for (|int| i = 0; i < intVec.size; i++;)
for (var i: int = 0; i < intVec.size; i++;)
print(intVec.at(i));
println();
|vector<AbleToBeDestroyed>*| desVec = new<vector<AbleToBeDestroyed>>()->construct();
|AbleToBeDestroyed| testDestruct;
var desVec: vector<AbleToBeDestroyed>* = new<vector<AbleToBeDestroyed>>()->construct();
var testDestruct: AbleToBeDestroyed;
desVec->addEnd(testDestruct);
delete<vector<AbleToBeDestroyed>>(desVec);