Wooo! Fixed up remaining bugs in new syntax!
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user