diff options
Diffstat (limited to 'tnslc/c_wrap.tnsl')
-rw-r--r-- | tnslc/c_wrap.tnsl | 62 |
1 files changed, 53 insertions, 9 deletions
diff --git a/tnslc/c_wrap.tnsl b/tnslc/c_wrap.tnsl index 93ea3e4..3d5fa02 100644 --- a/tnslc/c_wrap.tnsl +++ b/tnslc/c_wrap.tnsl @@ -51,26 +51,70 @@ asm "extern free" # there's no more to do 'cause free returns nothing ;/ -struct Array { - int el_size, - int num_el, +struct Vector { + uint + el_size, + num_el, + dat_size, ~void dat } -/; method Array +/; method Vector - /; resize (int num_el) - _realloc(self.dat, self.num_el * self.el_size) + /; resize (uint num_el) + self.dat_size = num_el + _realloc(self.dat, num_el * self.el_size) ;/ - /; get (int i) [~void] - /; if (i > self.num_el) + /; get (uint i) [~void] + /; if (i !< self.num_el) return self.dat ;/ return self.dat + (i * self.el_size) ;/ - /; set (int i, ~void data) + /; set (uint i, ~void data) + ~void index = get(i) + /; loop (i = 0; i < self.el_size) [index = index + 1; data = data + 1; i++] + index = data + ;/ + ;/ + + /; push (~void data) + self.num_el++ + self.set(self.num_el - 1, data) + /; if (self.num_el !< self.dat_size) + self.resize(2*self.dat_size) + ;/ + ;/ + + /; pop + self.num_el-- + /; if (self.num_el !== 0 && self.num_el < self.dat_size / 4) + self.resize(self.dat_size / 2) + ;/ + ;/ + + /; remove (int index) + index++ + /; loop (index < self.num_el) [index++] + self.set(index - 1, self.get(index)) + ;/ + self.pop() + ;/ + + /; start (int el_size) + self.num_el = 0 + self.el_size = el_size + self.dat_size = 1 + self.dat = _alloc(self.el_size) + ;/ + /; clean + self.num_el = 0 + self.el_size = 0 + self.dat_size = 0 + _delete(self.dat) + self.dat = 0 ;/ ;/ |