-
Notifications
You must be signed in to change notification settings - Fork 497
/
pyextension.h
134 lines (123 loc) · 2.82 KB
/
pyextension.h
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
// Copyright (C) 2022-2024 Exaloop Inc. <https://exaloop.io>
#pragma once
#include <string>
#include <vector>
#include "codon/cir/func.h"
#include "codon/cir/types/types.h"
namespace codon {
namespace ir {
struct PyFunction {
enum Type { TOPLEVEL, METHOD, CLASS, STATIC };
std::string name;
std::string doc;
Func *func = nullptr;
Type type = Type::TOPLEVEL;
int nargs = 0;
bool keywords = false;
bool coexist = false;
};
struct PyMember {
enum Type {
SHORT = 0,
INT = 1,
LONG = 2,
FLOAT = 3,
DOUBLE = 4,
STRING = 5,
OBJECT = 6,
CHAR = 7,
BYTE = 8,
UBYTE = 9,
USHORT = 10,
UINT = 11,
ULONG = 12,
STRING_INPLACE = 13,
BOOL = 14,
OBJECT_EX = 16,
LONGLONG = 17,
ULONGLONG = 18,
PYSSIZET = 19,
};
std::string name;
std::string doc;
Type type = Type::SHORT;
bool readonly = false;
/// Indexes of the member. For example, in the
/// tuple (a, (b, c, (d,))), 'a' would have indexes
/// [0], 'b' would have indexes [1, 0], 'c' would
/// have indexes [1, 1], and 'd' would have indexes
/// [1, 2, 0]. This corresponds to an LLVM GEP.
std::vector<int> indexes;
};
struct PyGetSet {
std::string name;
std::string doc;
Func *get = nullptr;
Func *set = nullptr;
};
struct PyType {
std::string name;
std::string doc;
types::Type *type = nullptr;
PyType *base = nullptr;
Func *repr = nullptr;
Func *add = nullptr;
Func *iadd = nullptr;
Func *sub = nullptr;
Func *isub = nullptr;
Func *mul = nullptr;
Func *imul = nullptr;
Func *mod = nullptr;
Func *imod = nullptr;
Func *divmod = nullptr;
Func *pow = nullptr;
Func *ipow = nullptr;
Func *neg = nullptr;
Func *pos = nullptr;
Func *abs = nullptr;
Func *bool_ = nullptr;
Func *invert = nullptr;
Func *lshift = nullptr;
Func *ilshift = nullptr;
Func *rshift = nullptr;
Func *irshift = nullptr;
Func *and_ = nullptr;
Func *iand = nullptr;
Func *xor_ = nullptr;
Func *ixor = nullptr;
Func *or_ = nullptr;
Func *ior = nullptr;
Func *int_ = nullptr;
Func *float_ = nullptr;
Func *floordiv = nullptr;
Func *ifloordiv = nullptr;
Func *truediv = nullptr;
Func *itruediv = nullptr;
Func *index = nullptr;
Func *matmul = nullptr;
Func *imatmul = nullptr;
Func *len = nullptr;
Func *getitem = nullptr;
Func *setitem = nullptr;
Func *contains = nullptr;
Func *hash = nullptr;
Func *call = nullptr;
Func *str = nullptr;
Func *cmp = nullptr;
Func *iter = nullptr;
Func *iternext = nullptr;
Func *del = nullptr;
Func *init = nullptr;
std::vector<PyFunction> methods;
std::vector<PyMember> members;
std::vector<PyGetSet> getset;
Func *typePtrHook = nullptr;
};
struct PyModule {
std::string name;
std::string doc;
std::vector<PyFunction> functions;
std::vector<PyType> types;
};
} // namespace ir
} // namespace codon