aboutsummaryrefslogtreecommitdiff
path: root/main.c
blob: 0abfa69c883fd7d37ae41a7521dd1ccadb4249c3 (plain) (blame)
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
// This is the test unit, not the actual code.

#include "moonshine.h"

const enum { test_datatype, test_linkedlist, test_hashtable, test_alloc, test_array } current_test = test_array;

int main() {
    if (current_test == test_alloc) {
        auto v1 = obj(i4);
        auto v2 = obj(u8);

        for (u8 i = 1; i <= 1000; i++) print(alloc(i * 1000));

        *v1 = 2;
        *v2 = 99;

        print(*v1, *v2);
        release(v1);

        print(*v2);
    } else if (current_test == test_array) {
        auto arr = new (int);
        push(arr, 4);
        push(arr, 9);
        set(arr, 0, 2);
        print(get(arr, 0));
    } else if (current_test == test_datatype) {
        datatype(binarytree, ((leaf, int), (node, binarytree *, int, binarytree *) ));
        const auto tree = instance(binarytree, leaf, 3);

        print(&tree);

        match(tree) {
            of(leaf, v) print("Leafy ", v);
            of(node, _, v, _) print("Nodey ", v);
            other() print("Idk man");
        }
    } else if (current_test == test_linkedlist) {
        const auto ll = create_linkedlist();

        for (u8 i = 0; i < 100; i++) push_linkedlist(ll, (var) i);

        print((u8) index_to_ptr(ll, 12)->data);
    } else if (current_test == test_hashtable) {
        const auto ht = create_table(
            table_hash_2, (struct hashtable_optimizations) { .run_ptr_check = true, .collision_character_check_count = 10 });

        for (u8 i = 0; i < 10000; i++) {
            if (i % 1000 == 0) print("I ", i);
            set_hashtable(ht, "hello", "world");
            set_hashtable(ht, "how", "are you");
        }

        print((string) get_hashtable(ht, "hello"), ' ', (string) get_hashtable(ht, "how"), ' ', get_hashtable(ht, "wowie"));
    }

    else {
        print("Unknown test.");
    }

    return 0;
}