desc.h 1.37 KB
Newer Older
1
2
#ifndef __DESC_H
#define __DESC_H
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
3

4
#include "desc_base.h"
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
5
6
7
#include "thunk.h"
#include "code.h"

8
9
// LIMITATION: maximum 32 arguments

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
10
11
12
13
14
15
16
17
18
struct FunEntry {
    struct Desc base;
    int strictness;

    union {
        char* parseCont;
        struct Code* body;
    };
    char name[];
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
19
20
};

21
// an array of these is just before an ADTEntry/FunEntry (as many as arity)
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
22
23
24
25

struct SliceEntry {
    struct Desc base;
    Desc* forward_ptr; // FunEntry or ADTEntry
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
26
};
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
27

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
28
29
30
31
struct ADTEntry {
    struct Desc base;
    int strictness;
    char name[];
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
32
33
};

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
34
35
36
37
38
39
struct CAFEntry {
    struct Desc base;

    union {
        char* parseCont;
        Code* body;
40
        struct Thunk* value;
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
41
42
    };
    char name[];
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
43
44
};

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
45
46
47
48
49
struct RecordEntry {
    struct Desc base;
    int strictness;
    char** fields;
    char name[];
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
50
51
};

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
52
53
54
55
56
struct PrimEntry {
    struct Desc base;
    int strictness;
    struct Thunk* (*exec)(Thunk*);
    char name[];
57
58
};

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
59
void gen_slices(SliceEntry* dest, Desc* forward_ptr, int arity);
60

61
62
void init_desc();

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
63
64
void add_desc(char* fn, Desc* desc);
Desc* find_desc(char* fn);
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
65

66
67
Desc* get_slice(Desc* f, int nrargs);

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
68
69
bool is_strict_fun_arg(FunEntry* f, int nr_arg);

70
71
int printDesc(Desc* f);

72
73
74
75
76
77
78
extern struct FunEntry* __INT__;
extern struct FunEntry* __BOOL__;
extern struct FunEntry* __CHAR__;
extern struct FunEntry* __REAL__;
extern struct FunEntry* __STRING__;
extern struct FunEntry* __ARRAY__;

79
#endif // __DESC_H