aboutsummaryrefslogtreecommitdiff
path: root/v_windows/v/vlib/builtin/linux_bare/old/array_bare.v
diff options
context:
space:
mode:
authorIndrajith K L2022-12-03 17:00:20 +0530
committerIndrajith K L2022-12-03 17:00:20 +0530
commitf5c4671bfbad96bf346bd7e9a21fc4317b4959df (patch)
tree2764fc62da58f2ba8da7ed341643fc359873142f /v_windows/v/vlib/builtin/linux_bare/old/array_bare.v
downloadcli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.tar.gz
cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.tar.bz2
cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.zip
Adds most of the toolsHEADmaster
Diffstat (limited to 'v_windows/v/vlib/builtin/linux_bare/old/array_bare.v')
-rw-r--r--v_windows/v/vlib/builtin/linux_bare/old/array_bare.v53
1 files changed, 53 insertions, 0 deletions
diff --git a/v_windows/v/vlib/builtin/linux_bare/old/array_bare.v b/v_windows/v/vlib/builtin/linux_bare/old/array_bare.v
new file mode 100644
index 0000000..b92214f
--- /dev/null
+++ b/v_windows/v/vlib/builtin/linux_bare/old/array_bare.v
@@ -0,0 +1,53 @@
+module builtin
+
+pub struct array {
+pub:
+ data voidptr
+ len int
+ cap int
+ element_size int
+}
+
+// for now off the stack
+fn new_array_from_c_array(len int, cap int, elm_size int, c_array voidptr) array {
+ arr := array{
+ len: len
+ cap: cap
+ element_size: elm_size
+ data: c_array
+ }
+ return arr
+}
+
+// Private function. Used to implement array[] operator
+fn (a array) get(i int) voidptr {
+ if i < 0 || i >= a.len {
+ panic('array.get: index out of range') // FIXME: (i == $i, a.len == $a.len)')
+ }
+ return a.data + i * a.element_size
+}
+
+// Private function. Used to implement assigment to the array element.
+fn (mut a array) set(i int, val voidptr) {
+ if i < 0 || i >= a.len {
+ panic('array.set: index out of range') // FIXME: (i == $i, a.len == $a.len)')
+ }
+ mem_copy(a.data + a.element_size * i, val, a.element_size)
+}
+
+// array.repeat returns new array with the given array elements
+// repeated `nr_repeat` times
+pub fn (a array) repeat(nr_repeats int) array {
+ assert nr_repeats >= 0
+
+ arr := array{
+ len: nr_repeats * a.len
+ cap: nr_repeats * a.len
+ element_size: a.element_size
+ data: malloc(nr_repeats * a.len * a.element_size)
+ }
+ for i in 0 .. nr_repeats {
+ mem_copy(arr.data + i * a.len * a.element_size, a.data, a.len * a.element_size)
+ }
+ return arr
+}