WOOO compiles all in one file! Dependencies resolved! Next up, C name mangeling for scoping
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import string:*;
|
||||
|
||||
__if_comp__ __C__ __simple_passthrough__ """
|
||||
#include <stdio.h>
|
||||
"""
|
||||
@@ -20,6 +22,14 @@ __if_comp__ __C__ __simple_passthrough__ """
|
||||
println();
|
||||
}
|
||||
|
||||
|void| print(|string| toPrint) {
|
||||
print(toPrint.toCharArray());
|
||||
}
|
||||
|
||||
|void| println(|string| toPrint) {
|
||||
println(toPrint.toCharArray());
|
||||
}
|
||||
|
||||
|void| print(|int| toPrint) {
|
||||
__if_comp__ __C__ {
|
||||
__simple_passthrough__ """
|
||||
|
||||
27
stdlib/string.krak
Normal file
27
stdlib/string.krak
Normal file
@@ -0,0 +1,27 @@
|
||||
import vector;
|
||||
import mem;
|
||||
|
||||
typedef string (Destructable) {
|
||||
|vector::vector<char>| data;
|
||||
|string*| construct() {
|
||||
data.construct();
|
||||
return this;
|
||||
}
|
||||
|string*| construct(|char*| str) {
|
||||
data.construct();
|
||||
while(*str) {
|
||||
data.addEnd(*str);
|
||||
str += 1;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|char*| toCharArray() {
|
||||
|char*| out = mem::new<char>(data.size);
|
||||
for (|int| i = 0; i < data.size; i++;)
|
||||
out[i] = data.get(i);
|
||||
return out;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import mem:*;
|
||||
import util:*;
|
||||
import io:*;
|
||||
//import io:*;
|
||||
|
||||
typedef template<T> vector (Destructable) {
|
||||
|T*| data;
|
||||
@@ -25,6 +25,8 @@ typedef template<T> vector (Destructable) {
|
||||
for (|int| i = 0; i < lesser<int>(size, newSize); i++;)
|
||||
newData[i] = data[i];
|
||||
delete<T>(data, 0);
|
||||
data = newData;
|
||||
available = newSize;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -34,21 +36,22 @@ typedef template<T> vector (Destructable) {
|
||||
|
||||
|T| get(|int| index) {
|
||||
if (index < 0 || index >= size) {
|
||||
println("Vector access out of bounds! Retuning 0th element as sanest option");
|
||||
// println("Vector access out of bounds! Retuning 0th element as sanest option");
|
||||
return data[0];
|
||||
}
|
||||
return data[index];
|
||||
}
|
||||
|
||||
|T*| getBackingMemory() { return data; }
|
||||
|
||||
|void| set(|int| index, |T| dataIn) {
|
||||
if (index < 0 || index >= size)
|
||||
return;
|
||||
data[index] = dataIn;
|
||||
}
|
||||
|void| addEnd(|T| dataIn) {
|
||||
if (size < available)
|
||||
size++;
|
||||
else
|
||||
size++;
|
||||
if (size >= available)
|
||||
resize(size*2);
|
||||
data[size-1] = dataIn;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user