aboutsummaryrefslogtreecommitdiff
path: root/builtins/nextline.c
blob: 3fa37412c7f9331310afa8a6a84dd93bebadbbfd (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
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
// An enum used for iterating over lines in a file
// Most of the code here was generated by compiling:
//    enum NextLine(Done, Next(line:Text))

#include <stdbool.h>
#include <stdint.h>

#include "siphash.h"
#include "datatypes.h"
#include "nextline.h"
#include "text.h"
#include "util.h"

static Text_t NextLine$Next$as_text(NextLine$Next_t *obj, bool use_color)
{
    if (!obj)
        return Text("Next");
    return Text$concat(use_color ? Text("\x1b[0;1mNext\x1b[m(") : Text("Next("), Text("line="),
                       Text$as_text((Text_t[1]){obj->$line}, use_color, &Text$info), Text(")"));
}

public inline NextLine_t NextLine$tagged$Next(Text_t $line)
{
    return (NextLine_t) {
        .tag = NextLine$tag$Next,.$Next = { $line }
    };
}

static Text_t NextLine$as_text(NextLine_t *obj, bool use_color)
{
    if (!obj)
        return Text("NextLine");
    switch (obj->tag) {
    case NextLine$tag$Done:
        return use_color ? Text("\x1b[36;1mNextLine.Done\x1b[m") : Text("NextLine.Done");
    case NextLine$tag$Next:
        return Text$concat(use_color ? Text("\x1b[36;1mNextLine.Next\x1b[m(") :
                           Text("NextLine.Next("), Text("line="),
                           Text$as_text((Text_t[1]){obj->$Next.$line}, use_color, &Text$info), Text(")"));
    default:
        return (Text_t) {
        .length = 0};
    }
}

static bool NextLine$equal(const NextLine_t *x, const NextLine_t *y,
                               const TypeInfo *info)
{
    (void) info;
    if (x->tag != y->tag)
        return false;
    switch (x->tag) {
    case NextLine$tag$Done:
        return false;
    case NextLine$tag$Next:
        return generic_equal(&x->$Next, &y->$Next, (&NextLine$Next));
    default:
        return 0;
    }
}

static int NextLine$compare(const NextLine_t *x, const NextLine_t *y,
                                const TypeInfo *info)
{
    (void) info;
    int diff = (int)x->tag - (int)y->tag;
    if (diff)
        return diff;
    switch (x->tag) {
    case NextLine$tag$Done:
        return 0;
    case NextLine$tag$Next:
        return generic_compare(&x->$Next, &y->$Next, (&NextLine$Next));
    default:
        return 0;
    }
}

static uint64_t NextLine$hash(const NextLine_t *obj, const TypeInfo *info)
{
    (void) info;
    uint64_t hashes[2] = { (uint64_t) obj->tag, 0 };
    switch (obj->tag) {
    case NextLine$tag$Done:
        break;
    case NextLine$tag$Next:
        hashes[1] = generic_hash(&obj->$Next, (&NextLine$Next));
        break;
    default: break;
    }
    return siphash24((void *) &hashes, sizeof(hashes));
}

public const TypeInfo NextLine$Done = { 0, 0, {.tag = EmptyStruct,.EmptyStruct.name =
                                                   "NextLine$Done" } };
public const TypeInfo NextLine$Next = { 24, 8, {.tag = CustomInfo,.CustomInfo =
                                                    {.as_text =
                                                     (void *) NextLine$Next$as_text,.hash =
                                                     (void *) Text$hash,.compare =
                                                     (void *) Text$compare,.equal =
                                                     (void *) Text$equal,} } };
public const TypeInfo NextLine = { 32, 8, {.tag = CustomInfo,.CustomInfo =
                                               {.as_text = (void *) NextLine$as_text,.equal =
                                                (void *) NextLine$equal,.hash =
                                                (void *) NextLine$hash,.compare =
                                                (void *) NextLine$compare} } };

// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0