-
Notifications
You must be signed in to change notification settings - Fork 9
/
listobj.h
80 lines (67 loc) · 2.16 KB
/
listobj.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
/*
$Id: listobj.h 3086 2023-09-03 06:23:08Z soci $
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef LISTOBJ_H
#define LISTOBJ_H
#include "obj.h"
#include "values.h"
#include "stdbool.h"
extern struct Type *const LIST_OBJ;
extern struct Type *const TUPLE_OBJ;
extern struct Type *const COLONLIST_OBJ;
typedef struct List {
Obj v;
size_t len;
Obj **data;
union {
Obj *val[5];
struct {
size_t max;
int hash;
} s;
} u;
} List;
typedef struct List Tuple;
typedef struct List Colonlist;
#define List(a) OBJ_CAST(List, a)
#define Tuple(a) OBJ_CAST(Tuple, a)
#define Colonlist(a) OBJ_CAST(Colonlist, a)
extern Obj *const null_tuple;
extern Obj *const null_list;
extern void listobj_init(void);
extern void listobj_names(void);
extern void listobj_destroy(void);
static inline MUST_CHECK List *new_list(void) {
return List(val_alloc(LIST_OBJ));
}
static inline MUST_CHECK Colonlist *new_colonlist(void) {
return Colonlist(val_alloc(COLONLIST_OBJ));
}
struct sliceparam_s {
uval_t length;
ival_t offset, end, step;
};
struct indexoffs_s {
Obj *val;
size_t len;
size_t offs;
linepos_t epoint;
};
extern MUST_CHECK Obj *indexoffs(struct indexoffs_s *);
extern MUST_CHECK Obj *sliceparams(struct sliceparam_s *, const struct indexoffs_s *);
extern MUST_CHECK Tuple *new_tuple(size_t);
extern Obj **list_create_elements(List *, size_t);
extern MUST_CHECK bool list_extend(List *);
extern void list_shrink(List *, size_t);
#endif