Declarations are now written |type| identifier;, generally. Functions are similar |void| func() {}, etc. Special declarations still work, etc

This commit is contained in:
Nathan Braswell
2014-08-01 00:45:48 -07:00
parent 4cf8dbbd5b
commit 5b57770774
31 changed files with 199 additions and 175 deletions

View File

@@ -2,11 +2,11 @@ __if_comp__ __C__ __simple_passthrough__ """
#include <stdio.h>
"""
void println() {
|void| println() {
print("\n");
}
void print(char* toPrint) {
|void| print(|char*| toPrint) {
__if_comp__ __C__ {
__simple_passthrough__ """
printf(toPrint);
@@ -15,12 +15,12 @@ void print(char* toPrint) {
return;
}
void println(char* toPrint) {
|void| println(|char*| toPrint) {
print(toPrint);
println();
}
void print(int toPrint) {
|void| print(|int| toPrint) {
__if_comp__ __C__ {
__simple_passthrough__ """
printf("%d", toPrint);
@@ -29,12 +29,12 @@ void print(int toPrint) {
return;
}
void println(int toPrint) {
|void| println(|int| toPrint) {
print(toPrint);
println();
}
void print(float toPrint) {
|void| print(|float| toPrint) {
__if_comp__ __C__ {
__simple_passthrough__ """
printf("%f", toPrint);
@@ -43,7 +43,7 @@ void print(float toPrint) {
return;
}
void print(double toPrint) {
|void| print(|double| toPrint) {
__if_comp__ __C__ {
__simple_passthrough__ """
printf("%f", toPrint);
@@ -52,7 +52,7 @@ void print(double toPrint) {
return;
}
void println(float toPrint) {
|void| println(|float| toPrint) {
print(toPrint);
println();
}

View File

@@ -1,9 +1,9 @@
int NotPi = 3;
float Pi = 3.141592654;
|int| NotPi = 3;
|float| Pi = 3.141592654;
int fibanacci(int num) {
|int| fibanacci(|int| num) {
if (num < 2)
return 1;
return fibanacci(num-1) + fibanacci(num-2);
}
}

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 = 0;
template <T> |T*| malloc(|int| size) {
|T*| memPtr = 0;
__if_comp__ __C__ {
__simple_passthrough__ """
memPtr = malloc(size);
@@ -14,7 +14,7 @@ template <T> T* malloc(int size) {
return memPtr;
}
template <T> void free(T* memPtr) {
template <T> |void| free(|T*| memPtr) {
__if_comp__ __C__ {
__simple_passthrough__ """
free(memPtr);
@@ -22,9 +22,9 @@ template <T> void free(T* memPtr) {
}
}
template <T> int sizeof() {
int result = 0;
T testObj;
template <T> |int| sizeof() {
|int| result = 0;
|T| testObj;
__if_comp__ __C__ {
__simple_passthrough__ """
result = sizeof(testObj);
@@ -33,32 +33,32 @@ template <T> int sizeof() {
return result;
}
template <T> T* new(int count) {
template <T> |T*| new(|int| count) {
return malloc<T>( sizeof<T>() * count );
}
template <T> T* new() {
template <T> |T*| new() {
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) {
template <T> |void| delete(|T*| toDelete, |int| itemCount) {
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++;)
template <T(Destructable)> |void| delete(|T*| toDelete, |int| itemCount) {
for (|int| i = 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) {
template <T> |void| delete(|T*| toDelete) {
free(toDelete);
}
template <T(Destructable)> void delete(T* toDelete) {
template <T(Destructable)> |void| delete(|T*| toDelete) {
toDelete->destruct();
free(toDelete);
}

View File

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

View File

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

View File

@@ -3,36 +3,36 @@ import util;
import io;
typedef template<T> vector (Destructable) {
T *data;
int size;
int available;
|T*| data;
|int| size;
|int| available;
vector<T>* construct() {
|vector<T>*| construct() {
size = 0;
available = 8;
data = new<T>(8);
return this;
}
void destruct() {
|void| destruct() {
delete<T>(data);
}
bool resize(int newSize) {
T* newData = new<T>(newSize);
|bool| resize(|int| newSize) {
|T*| newData = new<T>(newSize);
if (!newData)
return false;
for (int i = 0; i < lesser<int>(size, newSize); i++;)
for (|int| i = 0; i < lesser<int>(size, newSize); i++;)
newData[i] = data[i];
delete<T>(data, 0);
return true;
}
T at(int index) {
|T| at(|int| index) {
return get(index);
}
T get(int index) {
|T| get(|int| index) {
if (index < 0 || index >= size) {
println("Vector access out of bounds! Retuning 0th element as sanest option");
return data[0];
@@ -40,12 +40,12 @@ typedef template<T> vector (Destructable) {
return data[index];
}
void set(int index, T dataIn) {
|void| set(|int| index, |T| dataIn) {
if (index < 0 || index >= size)
return;
data[index] = dataIn;
}
void addEnd(T dataIn) {
|void| addEnd(|T| dataIn) {
if (size < available)
size++;
else