-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhdc_ss.c
More file actions
3128 lines (2701 loc) · 63.9 KB
/
Copy pathhdc_ss.c
File metadata and controls
3128 lines (2701 loc) · 63.9 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <stdbool.h>
#include <math.h>
#include <string.h>
#include <stdarg.h>
#include <execinfo.h>
#include <stdlib.h>
#include <stdio.h>
/**
* @file hdc.h
* @author Jon Voigt Tøttrup (jvoi@itu.dk)
* @brief The HighDefinitionC library, ready for action.
* @version 0.1
* @date 2018-10-30
*
* @copyright WingCorp (c) 2018
*
*/
#ifndef FAIL_H
#define FAIL_H
/**
* @brief The fail-module.
*
* @file fail.h
* @author WingCorp
* @date 2018-06-19
*/
/**
* @brief Exit the program with an error value.
*/
void fail();
/**
* @brief Print the error cause and exit the program with an error value.
*
* @param cause the cause to print before exiting.
*/
void failwith(char* cause);
#endif
#define FAIL_RED "\x1b[31m"
#define FAIL_RESET "\x1b[0m"
void* callstack[1024];
void trace_stack()
{
int frames = backtrace(callstack, 1024);
char** strs = backtrace_symbols(callstack, frames);
int i;
printf(FAIL_RED);
for (i = 0; i < frames; i++)
{
printf("%s\n", strs[i]);
}
printf(FAIL_RESET);
free(strs);
}
void fail()
{
trace_stack();
exit(EXIT_FAILURE);
}
void failwith(char* cause)
{
printf(FAIL_RED);
printf("%s\n", cause);
printf(FAIL_RESET);
trace_stack();
exit(EXIT_FAILURE);
}
#ifndef DYNAMIC_H
#define DYNAMIC_H
/**
* @brief Union type for emulating dynamic typing.
*
* @file dynamic.h
* @author WingCorp
* @date 2018-06-15
*/
typedef struct _Dynamic Dynamic;
typedef enum _DynType
{
BOOL,
CHAR,
INT,
LONG,
UINT,
ULONG,
FLOAT,
DOUBLE,
REFERENCE,
PAIR
} DynType;
typedef struct _Pair
{
Dynamic* left;
Dynamic* right;
} Pair;
typedef union _DynValue
{
bool bol;
char chr;
int i32;
unsigned int ui32;
long i64;
unsigned long ui64;
float f32;
double f64;
void* ref;
Pair pair;
} DynValue;
typedef struct _Dynamic
{
DynType type;
DynValue value;
} Dynamic;
/**
* @brief Creates a new pair from two dynamic values.
*
* @param left The left value.
* @param right The right value.
* @return Pair The constructed pair.
*/
Dynamic pair(Dynamic left, Dynamic right);
/**
* @brief Get the first value (leftmost) stored in a pair.
*
* @param pair The pair.
* @return Dynamic The first value.
*/
Dynamic fst(Dynamic pair);
/**
* @brief Returns the type of the first value of the pair.
*
* @param pair The pair.
* @return DynType The type of the first value.
*/
DynType t_fst(Dynamic pair);
/**
* @brief Get the second value (rightmost) stored in a pair.
*
* @param pair The pair.
* @return Dynamic The second value.
*/
Dynamic snd(Dynamic pair);
/**
* @brief Return the type of the second value of the pair.
*
* @param pair The pair.
* @return DynType The type of the second value.
*/
DynType t_snd(Dynamic pair);
Dynamic dbol(bool val);
Dynamic dchr(char val);
Dynamic di32(int val);
Dynamic dui32(unsigned int val);
Dynamic di64(long i64);
Dynamic dui64(unsigned long ui64);
Dynamic df32(float val);
Dynamic df64(double val);
Dynamic dref(void* ref);
//Shorthands to get the values of a dynamic.
//Be wary of segmentation fault.
bool bol(Dynamic dyn);
char chr(Dynamic dyn);
int i32(Dynamic dyn);
unsigned int ui32(Dynamic dyn);
long i64(Dynamic dyn);
unsigned long ui64(Dynamic dyn);
float f32(Dynamic dyn);
double f64(Dynamic dyn);
void* ref(Dynamic dyn);
/**
* @brief Delete a dynamic if it is on the heap.
* Frees the memory held by a dynamic reference or a dynamic pair.
*
* @param dyn A dynamic holding a reference or a pair-dynamic.
*/
void delete(Dynamic dyn);
#endif
Dynamic dbol(bool val)
{
return (Dynamic) { .type = BOOL, .value = (DynValue) { .chr = val } };
}
Dynamic dchr(char val)
{
return (Dynamic) { .type = CHAR, .value = (DynValue) { .chr = val } };
}
Dynamic di32(int val)
{
return (Dynamic) { .type = INT, .value = (DynValue) { .i32 = val } };
}
Dynamic dui32(unsigned int val)
{
return (Dynamic) { .type = UINT, .value = (DynValue) { .ui32 = val } };
}
Dynamic di64(long val)
{
return (Dynamic) { .type = LONG, .value = (DynValue) { .i64 = val } };
}
Dynamic dui64(unsigned long val)
{
return (Dynamic) { .type = ULONG, .value = (DynValue) { .ui64 = val } };
}
Dynamic df32(float val)
{
return (Dynamic) { .type = FLOAT, .value = (DynValue) { .f32 = val } };
}
Dynamic df64(double val)
{
return (Dynamic) { .type = DOUBLE, .value = (DynValue) { .f64 = val } };
}
Dynamic dref(void* ref)
{
return (Dynamic) { .type = REFERENCE, .value = (DynValue) { .ref = ref } };
}
Dynamic pair(Dynamic left, Dynamic right)
{
Dynamic* lp = malloc(sizeof(Dynamic));
lp->type = left.type;
lp->value = left.value;
Dynamic* rp = malloc(sizeof(Dynamic));
rp->type = right.type;
rp->value = right.value;
return (Dynamic)
{
.type = PAIR,
.value = (DynValue)
{
.pair = (Pair)
{
.left = lp,
.right = rp
}
}
};
}
Dynamic fst(Dynamic pair)
{
if (pair.type != PAIR)
{
failwith("Call to fst() expected Dynamic of type PAIR!");
}
return (*pair.value.pair.left);
}
DynType t_fst(Dynamic pair)
{
if (pair.type != PAIR)
{
failwith("Call to t_fst() expected Dynamic of type PAIR!");
}
return pair.value.pair.left->type;
}
Dynamic snd(Dynamic pair)
{
if (pair.type != PAIR)
{
failwith("Call to snd() expected Dynamic of type PAIR!");
}
return (*pair.value.pair.right);
}
DynType t_snd(Dynamic pair)
{
if (pair.type != PAIR)
{
failwith("Call to t_snd() expected Dynamic of type PAIR!");
}
return pair.value.pair.right->type;
}
bool bol(Dynamic dyn)
{
if (dyn.type != BOOL)
{
failwith("Call to bol() expected Dynamic of type BOOL!");
}
return dyn.value.bol;
}
char chr(Dynamic dyn)
{
if (dyn.type != CHAR)
{
failwith("Call to chr() expected Dynamic of type CHAR!");
}
return dyn.value.chr;
}
int i32(Dynamic dyn)
{
if (dyn.type != INT)
{
failwith("Call to i32() expected Dynamic of type INT!");
}
return dyn.value.i32;
}
unsigned int ui32(Dynamic dyn)
{
if (dyn.type != UINT)
{
failwith("Call to ui32() expected Dynamic of type UINT!");
}
return dyn.value.ui32;
}
long i64(Dynamic dyn)
{
if (dyn.type != LONG)
{
failwith("Call to i64() expected Dynamic of type LONG!");
}
return dyn.value.i64;
}
unsigned long ui64(Dynamic dyn)
{
if (dyn.type != ULONG)
{
failwith("Call to ui64() expected Dynamic of type ULONG!");
}
return dyn.value.ui64;
}
float f32(Dynamic dyn)
{
if (dyn.type != FLOAT)
{
failwith("Call to f32() expected Dynamic of type FLOAT!");
}
return dyn.value.f32;
}
double f64(Dynamic dyn)
{
if (dyn.type != DOUBLE)
{
failwith("Call to f64() expected Dynamic of type DOUBLE!");
}
return dyn.value.f64;
}
void* ref(Dynamic dyn)
{
if (dyn.type != REFERENCE)
{
failwith("Call to ref() expected Dynamic of type REFERENCE!");
}
return dyn.value.ref;
}
void delete(Dynamic dyn)
{
if (dyn.type != REFERENCE || dyn.type != PAIR) {
failwith("Call to delete() expected Dynamic of type REFERENCE or PAIR!");
}
if (dyn.type == REFERENCE) {
free(dyn.value.ref);
}
if (dyn.type == PAIR) {
free(dyn.value.pair.left);
free(dyn.value.pair.right);
}
}
#ifndef OPTION_H
#define OPTION_H
/**
* @brief The option monad
*
* @file option.h
* @author WingCorp
* @date 2018-06-15
*/
typedef enum _OptionType
{
NONE,
SOME
} OptionType;
typedef struct _Option
{
OptionType type;
Dynamic value;
} Option;
/**
* @brief The 'none' return-function.
*
* @return Option
*/
Option none();
/**
* @brief The 'some' return-function
*
* @param value
* @return Option
*/
Option some(Dynamic value);
/**
* @brief Takes an option and a function
* that takes the result of the given option
* and applies the option to the given function
* if the option was some.
*
* @param opt an Option value.
* @param optFunc a function of signature: Option <name>(Dynamic <arg>);
* @return Option an option value.
*/
Option success(Option opt, Option (*optFunc)(Dynamic));
/**
* @brief Coerces an option to its value.
* Might cause a failure, if no value is present.
*
* @param opt the option to coerce.
* @return Dynamic the value to find;
*/
Dynamic coerce(Option opt);
#endif
Option none()
{
return (Option) { .type = NONE };
}
Option some(Dynamic value)
{
return (Option) { .type = SOME, .value = value };
}
Option success(Option opt, Option (*optFunc)(Dynamic))
{
if (opt.type == NONE)
{
return none();
}
return (*optFunc)(opt.value);
}
Dynamic coerce(Option opt)
{
if (opt.type == NONE)
{
failwith("Could not coerce value from empty option!\n");
}
return opt.value;
}
#ifndef COMPARABLE_H
#define COMPARABLE_H
/**
* @file comparable.h
* @author Jon Voigt Tøttrup (jvoi@itu.dk)
* @brief A wrapper for Dynamics that allow them to be compared,
* given, that they are the same type.
* @version 0.1
* @date 2018-11-01
*
* @copyright WingCorp (c) 2018
*
*/
typedef struct _Comparable
{
Dynamic value;
} Comparable;
/**
* @brief Creates a Comparable from a Dynamic
*
* Fails if the dynamic cannot be converted to a Comparable.
*
* @param dynamic The dynamic value.
* @return Comparable The value, wrapped in a Comparable.
*/
Comparable comparable(Dynamic dynamic);
/**
* @brief Compares two Comparables
*
* @param a
* @param b
* @return int 0 if a == b, 1 if a > b, -1 if a < b
*/
int compare(Comparable a, Comparable b);
#endif
/**
* @file comparable.c
* @author your name (you@domain.com)
* @brief
* @version 0.1
* @date 2018-11-01
*
* @copyright Copyright (c) 2018
*
*/
Comparable comparable(Dynamic dynamic)
{
switch(dynamic.type)
{
case BOOL:
failwith("Cannot construct comparable from a BOOL value.\n");
break;
case REFERENCE:
failwith("Cannot construct comparable from a REFERENCE value.\n");
break;
default:
break;
}
return (Comparable) { .value = dynamic};
}
int compare(Comparable a, Comparable b)
{
if(a.value.type != b.value.type)
{
failwith("Cannot compare comparables of different dynamic types!\n");
}
Dynamic aVal = a.value;
Dynamic bVal = b.value;
switch(a.value.type)
{
case CHAR:
if (chr(aVal) == chr(bVal))
{
return 0;
}
else
{
return (chr(aVal)) > (chr(bVal)) ? 1 : -1;
}
case INT:
if (i32(aVal) == i32(bVal))
{
return 0;
}
else
{
return (i32(aVal)) > (i32(bVal)) ? 1 : -1;
}
case FLOAT:
if (f32(aVal) == f32(bVal))
{
return 0;
}
else
{
return (f32(aVal)) > (f32(bVal)) ? 1 : -1;
}
case DOUBLE:
if (f64(aVal) == f64(bVal))
{
return 0;
}
else
{
return (f64(aVal)) > (f64(bVal)) ? 1 : -1;
}
case LONG:
if (i64(aVal) == i64(bVal))
{
return 0;
}
else
{
return (i64(aVal)) > (i64(bVal)) ? 1 : -1;
}
default:
failwith("Cannot create comparable from unknown dynamic type!\n");
break;
}
int f = 0;
return 0 / f; //So, we have to return an integer, but we should not.
//We should never reach these statements, but if we do, I've made a terrible mistake somewhere.
}
#ifndef HASH_H
#define HASH_H
/**
* @file hash.h
* @author Jon Voigt Tøttrup (jvoi@itu.dk)
*
* @brief A module responisble for hashing things
* @version 0.1
* @date 2018-11-08
*
* @copyright WingCorp (c) 2018
*
*/
unsigned long hash(char* s);
#endif
/**
* @brief Hashes a char* to an unsigned long.
* K&R's hash function.
*
* @param s A string.
* @return unsigned long A hash of the string.
*/
unsigned long hash(char* s)
{
unsigned long hash = 5381;
int c;
while((c = *s++))
{
hash = ((hash << 5) + hash) + c;
}
return hash;
}
#ifndef ITERATOR_H
#define ITERATOR_H
typedef struct _Iterator Iterator;
/**
* @brief Initializes a new iterator from a Dynamic pointer.
*
* @param data The data to iterate from.
* @param length The length of the data.
* @return Iterator An Iterator struct.
*/
Iterator* iterator_init_eager(Dynamic* data, int length);
/**
* @brief Initializes a new iterator from an int -> Dynamic function.
*
* @param nextFun A function that takes the position of the iterator
* and returns the corresponding Dynamic.
* @param length The length of the iterator.
* @return Iterator* An Iterator struct.
*/
Iterator* iterator_init_lazy(Dynamic (*nextFun)(int), int length);
/**
* @brief Whether an iterator holds another value.
*
* @param iterator
* @return bool a bool value.
*/
bool iterator_hasNext(Iterator* iterator);
/**
* @brief Retrieves the next value from the iterator.
*
* @param iterator the iterator to get the value from.
* @return Option some if there is a value, none if there isn't.
*/
Option iterator_next(Iterator* iterator);
/**
* @brief How many entries that remain in the iterator.
*
* @param iterator
* @return int
*/
int iterator_remaining(Iterator* iterator);
/**
* @brief Resets iterator.
*
* @param iterator the iterator.
*/
void iterator_reset(Iterator* iterator);
/**
* @brief Destroys the iterator and the values that the iterator is reading from.
*
* @param iterator the iterator to destroy.
*/
void iterator_destroy(Iterator* iterator);
#endif
typedef union _Source
{
Dynamic* data;
Dynamic (*nextFun)(int);
} Source;
typedef enum _Type
{
EAGER,
LAZY
} Type;
typedef struct _Iterator
{
int position;
int length;
Source* source;
Type type;
} Iterator;
Iterator* iterator_init_eager(Dynamic* data, int length)
{
Iterator* iterator = malloc(sizeof(Iterator));
iterator->position = 0;
iterator->length = length;
iterator->type = EAGER;
iterator->source = malloc(sizeof(Source));
iterator->source->data = data;
return iterator;
}
Iterator* iterator_init_lazy(Dynamic (*nextFun)(int), int length)
{
Iterator* iterator = malloc(sizeof(Iterator));
iterator->position = 0;
iterator->length = length;
iterator->type = LAZY;
iterator->source = malloc(sizeof(Source));
iterator->source->nextFun = nextFun;
return iterator;
}
bool iterator_hasNext(Iterator* iterator)
{
return iterator->position < iterator->length;
}
Option iterator_next(Iterator* iterator)
{
if(iterator->position < iterator->length)
{
Dynamic toReturn;
switch(iterator->type)
{
case EAGER:
toReturn = iterator->source->data[iterator->position];
break;
case LAZY:
toReturn = iterator->source->nextFun(iterator->position);
break;
}
iterator->position += 1;
return some(toReturn);
}
else
{
return none();
}
}
int iterator_remaining(Iterator* iterator)
{
return iterator->length - iterator->position;
}
void iterator_reset(Iterator* iterator)
{
iterator->position = 0;
}
void iterator_destroy(Iterator* iterator)
{
free(iterator);
}
#ifndef FOREACH_H
#define FOREACH_H
/**
* @brief The foreach function.
*
* @file foreach.h
* @author WingCorp
* @date 2018-06-16
*/
/**
* @brief Performs an action on every value from an iterator using an action function.
*
* @param iterator the iterator to loop through.
* @param action the action function, must have signature: void <name>(Dynamic <arg>)
*/
void foreach(Iterator* iterator, void (*action) (Dynamic));
#endif
void foreach(Iterator* iterator, void (*action) (Dynamic))
{
while (iterator_hasNext(iterator))
{
(*action)(iterator_next(iterator).value);
}
iterator_reset(iterator);
}
#ifndef MAP_H
#define MAP_H
/**
* @brief The 'map' monad, as known from FP.
*
* @file map.h
* @author WingCorp
* @date 2018-06-16
*/
/**
* @brief maps every value from an iterator with a mapper function.
*
* ATTENTION: this function will allocate memory to the mapped values.
* To free memory of old values or of mapped values, use iterator_destroy.
*
* @param iterator the iterator to map.
* @param mapper the mapper function, must have signature: Dynamic <name>(Dynamic <arg>)
* @return Iterator a new iterator for the new values.
*/
Iterator* map(Iterator* iterator, Dynamic (*mapper) (Dynamic));
#endif
Iterator* map(Iterator* ite, Dynamic (*mapper) (Dynamic))
{
int size = iterator_remaining(ite);
Dynamic* mappedValues = malloc(size * sizeof(Dynamic));
int i = 0;
while(iterator_hasNext(ite))
{
mappedValues[i] = (*mapper)(iterator_next(ite).value);
i += 1;
}
iterator_reset(ite);
return iterator_init_eager(mappedValues, size);
}
#ifndef FOLD_H
#define FOLD_H
/**
* @brief The 'fold' monad, as known from FP.
*
* @file fold.h
* @author WingCorp
* @date 2018-06-16
*/
/**
* @brief Folds over every entry in the iterator.
*
* @param iterator the iterator to fold over..
* @param initialState the initial state to fold onto.
* @param folder the folder function with the signature Dynamic folder(Dynamic acc, Dynamic i)
* @return Dynamic the final state.
*/
Dynamic fold(Iterator* iterator, Dynamic initialState, Dynamic (*folder) (Dynamic, Dynamic));
#endif
Dynamic fold(Iterator* iterator, Dynamic initialState, Dynamic (*folder) (Dynamic, Dynamic))
{
Dynamic current_state = initialState;
while (iterator_hasNext(iterator))
{
Dynamic currentValue = iterator_next(iterator).value;
current_state = (*folder)(current_state, currentValue);
}
iterator_reset(iterator);
return current_state;
}
#ifndef ARRAY_H
#define ARRAY_H
/**
* @brief Wrapper for dynamic pointers, so that they include length as well.
*
* @file array.h
* @author WingCorp
* @date 2018-06-17
*/
typedef struct _Array Array;
/**
* @brief Initializes an empty array of a given length.
*
* @param length
* @return Array*
*/
Array* array_empty(int length);
/**
* @brief Initializes the array with a Dynamic* and a specified length.
*
* Copies all given Dynamic values to a new memory space on heap.
*
* @param dynamics A Dynamic pointer to a primitive array of dynamics.
* @param length the length of the dynamic array.
* @return Array* an Array*
*/
Array* array_init(Dynamic* dynamics, int length);
/**
* @brief Retrieves the length of the array.
*
* @param array the array.
* @return int the length,
*/
int array_length(Array* array);
/**
* @brief Get an item from the array.
*
* @param array the array.
* @param index the index for the array.
* @return Option an option value, some if index < length and index > 0
* else returns none.
*/
Option array_item(Array* array, int index);
/**
* @brief Sets an item in the array to a new value.
*
* @param array the array.
* @param index the index to modify.
* @param value the new value.
*/
void array_setItem(Array* array, int index, Dynamic value);
/**