This commit is contained in:
Nathan Braswell
2014-08-19 01:24:28 -04:00
parent 5b57770774
commit 5974deece2
11 changed files with 153 additions and 81 deletions

View File

@@ -2,6 +2,10 @@ __if_comp__ __C__ __simple_passthrough__ """
#include <stdio.h>
"""
/*
*import string;
*/
|void| println() {
print("\n");
}
@@ -20,6 +24,17 @@ __if_comp__ __C__ __simple_passthrough__ """
println();
}
/*
*|void| print(|String| toPrint) {
* print(toPrint.c_str());
*}
*
*|void| println(|String| toPrint) {
* print(toPrint);
* println();
*}
*/
|void| print(|int| toPrint) {
__if_comp__ __C__ {
__simple_passthrough__ """

49
stdlib/string.krak Normal file
View File

@@ -0,0 +1,49 @@
import vector;
import mem;
typedef String (Destructable) {
|vector<char>| charVec;
|String*| construct() {
charVec.construct();
return this;
}
|void| destruct() {
charVec.destruct();
}
|String*| construct(|char*| stringInput) {
charVec.construct();
append(stringInput);
return this;
}
|char| operator[](|int| index) {
return charVec[index];
}
|void| append(|String| toAppend) {
for (|int| i = 0; i < toAppend.size(); i++;)
charVec.addEnd(toAppend[i]);
}
|void| append(|char*| toAppend) {
while(toAppend)
charVec.addEnd(toAppend++);
}
|String| operator+(|String| other) {
|String| self = clone();
self.append(other);
return self;
}
|char*| c_str() {
|char*| toReturn = new<char>(charVec.size()+1);
for (|int| i = 0; i < charVec.size(); i++;)
toReturn[i] = charVec[i];
toReturn[charVec.size()] = 0;
return toReturn;
}
};

View File

@@ -27,12 +27,12 @@ typedef template<T> vector (Destructable) {
delete<T>(data, 0);
return true;
}
|T| at(|int| index) {
return get(index);
|T| operator[](|int| index) {
return at(index);
}
|T| get(|int| index) {
|T| at(|int| index) {
if (index < 0 || index >= size) {
println("Vector access out of bounds! Retuning 0th element as sanest option");
return data[0];