Change over everything to sizeof intrinsic
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
kraken="kraken"
|
kraken="kraken"
|
||||||
bootstrap_commits=(cf46fb13afe66ba475db9725e9269c9c1cd3bbc3 2cd43e5a217318c70097334b3598d2924f64b362)
|
bootstrap_commits=(cf46fb13afe66ba475db9725e9269c9c1cd3bbc3 2cd43e5a217318c70097334b3598d2924f64b362 2051f54b559ac5edf67277d4f1134aca2cb9215d)
|
||||||
|
|
||||||
# Echo version string to a file included by kraken.krak
|
# Echo version string to a file included by kraken.krak
|
||||||
# There is a default version string in the file in case kraken is not built with captain
|
# There is a default version string in the file in case kraken is not built with captain
|
||||||
|
|||||||
@@ -30,19 +30,8 @@ fun free<T>(memPtr: *T): void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun sizeof<T>(): int {
|
|
||||||
var testObj: *T;
|
|
||||||
var result: int;
|
|
||||||
__if_comp__ __C__ {
|
|
||||||
simple_passthrough(testObj = testObj : result = result:) """
|
|
||||||
int result = sizeof(*testObj);
|
|
||||||
"""
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
fun new<T>(count: int): *T {
|
fun new<T>(count: int): *T {
|
||||||
return malloc<T>( sizeof<T>() * count );
|
return malloc<T>( #sizeof<T> * count );
|
||||||
}
|
}
|
||||||
|
|
||||||
fun new<T>(): *T {
|
fun new<T>(): *T {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ fun serialize<T(Serializable)>(it: T): vector::vector<char> {
|
|||||||
fun serialize<T>(it: T): vector::vector<char> {
|
fun serialize<T>(it: T): vector::vector<char> {
|
||||||
var char_data = (&it) cast *char
|
var char_data = (&it) cast *char
|
||||||
var toRet = vector::vector<char>()
|
var toRet = vector::vector<char>()
|
||||||
for (var i = 0; i < mem::sizeof<T>(); i++;)
|
for (var i = 0; i < #sizeof<T>; i++;)
|
||||||
toRet.add(char_data[i])
|
toRet.add(char_data[i])
|
||||||
return toRet
|
return toRet
|
||||||
}
|
}
|
||||||
@@ -19,7 +19,7 @@ fun unserialize<T>(it: ref vector::vector<char>): T {
|
|||||||
return unserialize<T>(it, 0).first
|
return unserialize<T>(it, 0).first
|
||||||
}
|
}
|
||||||
fun unserialize<T>(it: ref vector::vector<char>, pos: int): util::pair<T,int> {
|
fun unserialize<T>(it: ref vector::vector<char>, pos: int): util::pair<T,int> {
|
||||||
return util::make_pair(*(it.getBackingMemory()+pos) cast *T, pos + mem::sizeof<T>())
|
return util::make_pair(*(it.getBackingMemory()+pos) cast *T, pos + #sizeof<T>)
|
||||||
}
|
}
|
||||||
fun unserialize<T(Serializable)>(it: ref vector::vector<char>, pos: int): util::pair<T,int> {
|
fun unserialize<T(Serializable)>(it: ref vector::vector<char>, pos: int): util::pair<T,int> {
|
||||||
var toRet: T
|
var toRet: T
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import mem
|
|||||||
import serialize
|
import serialize
|
||||||
|
|
||||||
fun to_string(in: int): string {
|
fun to_string(in: int): string {
|
||||||
var dest = mem::new<char>(mem::sizeof<int>() * 8)
|
var dest = mem::new<char>(#sizeof<int> * 8)
|
||||||
defer mem::delete(dest)
|
defer mem::delete(dest)
|
||||||
__if_comp__ __C__ {
|
__if_comp__ __C__ {
|
||||||
simple_passthrough(dest = dest, in = in::) """
|
simple_passthrough(dest = dest, in = in::) """
|
||||||
|
|||||||
Reference in New Issue
Block a user