Serilization and caching the table works!

This commit is contained in:
Nathan Braswell
2015-08-26 03:45:34 -04:00
parent b67d5e85fe
commit d72cbdcedb
16 changed files with 276 additions and 25 deletions

View File

@@ -1,6 +1,7 @@
import vector
import util
import mem
import serialize
fun to_string(in: int): string {
var dest = mem::new<char>(mem::sizeof<int>() * 8)
@@ -23,8 +24,11 @@ fun string(in:char):string {
out += in
return out
}
fun string():string {
return string("")
}
obj string (Object) {
obj string (Object, Serializable) {
var data: vector::vector<char>;
fun construct(): *string {
data.construct();
@@ -69,6 +73,15 @@ obj string (Object) {
data.destruct()
}
fun serialize(): vector::vector<char> {
return serialize::serialize(data)
}
fun unserialize(it: ref vector::vector<char>, pos: int): int {
construct()
util::unpack(data, pos) = serialize::unserialize<vector::vector<char>>(it, pos)
return pos
}
fun operator[](index: int): ref char { return data[index]; }
fun slice(first: int, second: int): string {
var new.construct(data.slice(first,second)): string