blob: b6af0fee934b16baf0d2a5a20cc100b6c5c54aa6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
#include "std/base.toc", base;
// @TODO: check for failed calloc
calloc ::= #foreign("calloc", base.libc) fn(#C size_t, #C size_t) #C &"void";
free ::= #foreign("free", base.libc) fn(#C &"void");
new ::= fn(t :: Type) &t {
return calloc(1, (sizeof t) as #C size_t);
}
news ::= fn(t :: Type, n : int) []t {
s: []t;
s.data = calloc(n as #C size_t, (sizeof t) as #C size_t);
s.len = n;
return s;
}
del ::= fn(t::=, x: &t) {
free(x);
}
dels ::= fn(t::=, x: []t) {
free(x.data);
}
// @OPTIM @OPTIM @OPTIM
mem_copy ::= fn(out: &void, in: &void, n : int) {
out_u8 : &u8 = out;
in_u8 : &u8 = in;
for i := 0..n-1 {
*out_u8 = *in_u8;
out_u8 += 1;
in_u8 += 1;
}
}
|