aboutsummaryrefslogtreecommitdiff
path: root/src/prc1/div.c
blob: 5c6422f20e166494b64befc7e005fa007f701016 (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
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
#include "div.h"
#include "fn.h"
#include "gl.h"
#include "im.h"
#include "lk.h"
#include "pr.h"
#include "td.h"
#include "ws.h"

static const struct seq
    externals = {(struct step[]){{ID, "externals"}, {0}}, .fn = lk},
    types = {(struct step[]){{ID, "types"}, {0}}, .fn = td},
    imports = {(struct step[]){{ID, "imports"}, {0}}, .fn = im},
    procedure = {(struct step[]){{ID, "procedure"}, {0}}, .fn = pr};

static const struct seq fnseq[] =
{
    externals,
    types,
    imports,
    procedure,
    {(struct step[]){{ID, "locals"}, {0}}, .fn = ws},
    {(struct step[]){{ID, "globals"}, {0}}, .fn = gl},
    {0}
};

static const struct seq imseq[] =
{
    externals,
    types,
    imports,
    {0}
};

static const struct seq pseq[] =
{
    externals,
    procedure,
    {0}
};

int div_fn(const struct lex *l, struct prv *p)
{
    struct pos init =
    {
        .name = __func__,
        .seq = fnseq,
        .end = fn_end
    };

    if (push(&init, p))
        return -1;

    p->stk = p->tk;
    return 0;
}

int div_im(const struct lex *l, struct prv *p)
{
    struct pos init =
    {
        .name = __func__,
        .seq = imseq,
    };

    if (push(&init, p))
        return -1;

    p->stk = p->tk;
    return 0;
}

static int endp(const struct lex *l, struct prv *p)
{
    if (fn_end(l, p))
        return -1;

    p->proto = NULL;
    return 0;
}

int div_p(const struct lex *l, struct prv *p)
{
    struct pos init =
    {
        .name = __func__,
        .seq = pseq,
        .end = endp
    };

    if (push(&init, p))
        return -1;

    p->stk = p->tk;
    return 0;
}