~lattis/muon

ref: f9a8cbad39b665a9496cd3adb4756e85ee5ec97c muon/include/lang/object.h -rw-r--r-- 5.3 KiB
f9a8cbadStone Tickle print stdout/stderr of failing test 8 months ago
                                                                                
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#ifndef MUON_LANG_OBJECT_H
#define MUON_LANG_OBJECT_H

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

#include "compilers.h"
#include "iterator.h"

enum obj_type {
	obj_any, // used for argument type checking
	obj_default,
	obj_null,
	obj_string,
	obj_number,
	obj_compiler,
	obj_meson,
	obj_array,
	obj_dict,
	obj_bool,
	obj_file,
	obj_build_target,
	obj_custom_target,
	obj_subproject,
	obj_dependency,
	obj_feature_opt,
	obj_machine,
	obj_external_program,
	obj_external_library,
	obj_run_result,
	obj_configuration_data,
	obj_test,
	obj_module,
	obj_install_target,

	obj_type_count,

	ARG_TYPE_NULL     = 1000,
	ARG_TYPE_GLOB     = 1001,
	ARG_TYPE_ARRAY_OF = 1 << 20,
};

typedef uint32_t obj;

// this has to be included here so that obj_type and obj can be defined already
#include "lang/workspace.h"

enum tgt_type {
	tgt_executable,
	tgt_library
};

enum feature_opt_state {
	feature_opt_auto,
	feature_opt_enabled,
	feature_opt_disabled,
};

enum dep_flags {
	dep_flag_found = 1 << 0,
	dep_flag_pkg_config = 1 << 1,
};

enum custom_target_flags {
	custom_target_capture = 1 << 0,
};

enum module {
	module_fs,
	module_python,
	module_python3,
	module_pkgconfig,
	module_count,
};

struct obj {
	enum obj_type type;
	union {
		str str;
		str file;
		int64_t num;
		bool boolean;
		uint32_t subproj;
		enum module module;
		struct {
			obj val; // obj_any
			obj next; // obj_array
			obj tail; // obj_array
			uint32_t len;
			bool have_next;
		} arr;
		struct {
			obj key; // obj_string
			obj val; // obj_any
			obj next; // obj_array
			obj tail; // obj_array
			uint32_t len;
			bool have_next;
		} dict;
		struct {
			str name;
			str build_name;
			str cwd;
			str build_dir;
			obj src; // obj_array
			obj link_with; // obj_array
			obj include_directories; // obj_array
			obj deps; // obj_array
			obj args; // obj_dict
			obj link_args; // obj_array
			enum tgt_type type;
		} tgt;
		struct {
			str name;
			obj args; // obj_array
			obj input; // obj_array
			obj output; // obj_array
			enum custom_target_flags flags;
		} custom_target;
		struct {
			obj name; // obj_string
			obj version; // obj_string
			obj link_with; // obj_array
			obj link_args; // obj_array
			obj include_directories; // obj_array
			enum dep_flags flags;
		} dep;
		struct {
			enum feature_opt_state state;
		} feature_opt;
		struct {
			bool found;
			uint32_t full_path;
		} external_program;
		struct {
			str full_path;
			bool found;
		} external_library;
		struct {
			str out;
			str err;
			int32_t status;
		} run_result;
		struct {
			obj dict; // obj_dict
		} configuration_data;
		struct {
			obj name; // obj_string
			obj exe; // obj_string
			obj args; // obj_array
			obj env; // obj_array
			bool should_fail;
		} test;
		struct {
			str name;
			str version;
			enum compiler_type type;
			enum compiler_language lang;
		} compiler;
		struct {
			str base_path;
			str filename;
			str install_dir;
			uint32_t install_mode;
		} install_target;
	} dat;
};

const char *obj_type_to_s(enum obj_type t);
bool obj_to_s(struct workspace *wk, obj obj, char *buf, uint32_t len);
bool obj_equal(struct workspace *wk, obj left, obj right);
bool obj_clone(struct workspace *wk_src, struct workspace *wk_dest, obj val, obj *ret);

bool obj_vsnprintf(struct workspace *wk, char *out_buf, uint32_t buflen, const char *fmt, va_list ap_orig)
__attribute__ ((format(printf, 4, 0)));
bool obj_snprintf(struct workspace *wk, char *out_buf, uint32_t buflen, const char *fmt, ...)
__attribute__ ((format(printf, 4, 5)));
bool obj_vfprintf(struct workspace *wk, FILE *f, const char *fmt, va_list ap)
__attribute__ ((format(printf, 3, 0)));
bool obj_fprintf(struct workspace *wk, FILE *f, const char *fmt, ...)
__attribute__ ((format(printf, 3, 4)));
bool obj_printf(struct workspace *wk, const char *fmt, ...)
__attribute__ ((format(printf, 2, 3)));

typedef enum iteration_result (*obj_array_iterator)(struct workspace *wk, void *ctx, obj val);
void obj_array_push(struct workspace *wk, obj arr, obj child);
bool obj_array_foreach(struct workspace *wk, obj arr, void *ctx, obj_array_iterator cb);
bool obj_array_foreach_flat(struct workspace *wk, obj arr, void *usr_ctx, obj_array_iterator cb);
bool obj_array_in(struct workspace *wk, obj arr, obj val);
bool obj_array_index(struct workspace *wk, obj arr, int64_t i, obj *res);
void obj_array_extend(struct workspace *wk, obj arr, obj arr2);
bool obj_array_dup(struct workspace *wk, obj arr, obj *res);
bool obj_array_join(struct workspace *wk, obj arr, obj join, obj *res);
void obj_array_set(struct workspace *wk, obj arr, int64_t i, obj v);

typedef enum iteration_result (*obj_dict_iterator)(struct workspace *wk, void *ctx, obj key, obj val);
bool obj_dict_foreach(struct workspace *wk, obj dict, void *ctx, obj_dict_iterator cb);
bool obj_dict_in(struct workspace *wk, obj dict, obj key);
bool obj_dict_index(struct workspace *wk, obj dict, obj key, obj *res);
bool obj_dict_index_strn(struct workspace *wk, obj dict, const char *str, uint32_t len, obj *res);
void obj_dict_set(struct workspace *wk, obj dict, obj key, obj val);
bool obj_dict_dup(struct workspace *wk, obj dict, obj *res);
bool obj_dict_merge(struct workspace *wk, obj dict, obj dict2, obj *res);
void obj_dict_seti(struct workspace *wk, obj dict, uint32_t key, obj val);
bool obj_dict_geti(struct workspace *wk, obj dict, uint32_t key, obj *val);
#endif