pyscriptc 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyscriptc/__init__.py +3 -0
- pyscriptc/__main__.py +3 -0
- pyscriptc/_posthog_token.py +1 -0
- pyscriptc/builtins.py +156 -0
- pyscriptc/canonical.py +167 -0
- pyscriptc/check.py +49 -0
- pyscriptc/cli.py +271 -0
- pyscriptc/coverage.py +388 -0
- pyscriptc/debug.py +120 -0
- pyscriptc/diagnostics.py +179 -0
- pyscriptc/errors.py +56 -0
- pyscriptc/ir.py +365 -0
- pyscriptc/llvm.py +2129 -0
- pyscriptc/log.py +127 -0
- pyscriptc/lower/__init__.py +1071 -0
- pyscriptc/lower/_calls.py +1499 -0
- pyscriptc/lower/_classes.py +969 -0
- pyscriptc/lower/_core.py +301 -0
- pyscriptc/lower/_expr.py +886 -0
- pyscriptc/lower/_stdlib.py +491 -0
- pyscriptc/lower/_stdlib_shared.py +93 -0
- pyscriptc/lower/_stmt.py +1173 -0
- pyscriptc/package.py +249 -0
- pyscriptc/restlower.py +1008 -0
- pyscriptc/runtime/ps_argv.c +28 -0
- pyscriptc/runtime/ps_b64.c +168 -0
- pyscriptc/runtime/ps_coll.c +133 -0
- pyscriptc/runtime/ps_dt.c +388 -0
- pyscriptc/runtime/ps_hash.c +411 -0
- pyscriptc/runtime/ps_help.c +219 -0
- pyscriptc/runtime/ps_hmac.c +120 -0
- pyscriptc/runtime/ps_io.c +198 -0
- pyscriptc/runtime/ps_island.c +272 -0
- pyscriptc/runtime/ps_json.c +402 -0
- pyscriptc/runtime/ps_mix.c +47 -0
- pyscriptc/runtime/ps_more.c +1089 -0
- pyscriptc/runtime/ps_osmore.c +447 -0
- pyscriptc/runtime/ps_path.c +547 -0
- pyscriptc/runtime/ps_re.c +1102 -0
- pyscriptc/runtime/ps_rt.c +1175 -0
- pyscriptc/runtime/ps_rt.h +189 -0
- pyscriptc/runtime/ps_struct.c +291 -0
- pyscriptc/runtime/ps_time.c +207 -0
- pyscriptc/runtime/ps_unicode.c +1521 -0
- pyscriptc/runtime/ps_url.c +327 -0
- pyscriptc/stdlib_queue.py +191 -0
- pyscriptc/stdmore.py +1596 -0
- pyscriptc/telemetry.py +219 -0
- pyscriptc-0.1.0.dist-info/METADATA +187 -0
- pyscriptc-0.1.0.dist-info/RECORD +54 -0
- pyscriptc-0.1.0.dist-info/WHEEL +5 -0
- pyscriptc-0.1.0.dist-info/entry_points.txt +2 -0
- pyscriptc-0.1.0.dist-info/licenses/LICENSE +201 -0
- pyscriptc-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
/* importlib.resources directory lookup, tempfile, and shutil.
|
|
2
|
+
|
|
3
|
+
Resource roots are directories on the compile-time sys.path. Zip archives
|
|
4
|
+
are not searched. as_file of one of these paths is the path itself.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
#include "ps_rt.h"
|
|
8
|
+
|
|
9
|
+
#include <dirent.h>
|
|
10
|
+
#include <errno.h>
|
|
11
|
+
#include <fcntl.h>
|
|
12
|
+
#include <stdio.h>
|
|
13
|
+
#include <stdlib.h>
|
|
14
|
+
#include <string.h>
|
|
15
|
+
#include <sys/stat.h>
|
|
16
|
+
#include <unistd.h>
|
|
17
|
+
|
|
18
|
+
typedef struct PsPath {
|
|
19
|
+
PsBuf path;
|
|
20
|
+
} PsPath;
|
|
21
|
+
|
|
22
|
+
static char *ps_cstr(int64_t n, const char *s) {
|
|
23
|
+
char *text;
|
|
24
|
+
if (n < 0) {
|
|
25
|
+
ps_raise_code(PS_VALUE);
|
|
26
|
+
}
|
|
27
|
+
text = malloc((size_t)n + 1);
|
|
28
|
+
if (text == NULL) {
|
|
29
|
+
abort();
|
|
30
|
+
}
|
|
31
|
+
if (n > 0) {
|
|
32
|
+
memcpy(text, s, (size_t)n);
|
|
33
|
+
}
|
|
34
|
+
text[n] = '\0';
|
|
35
|
+
return text;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static void ps_os_fail(const char *what) { ps_raise_cstr(PS_RUNTIME, what); }
|
|
39
|
+
|
|
40
|
+
static int ps_is_dir(const char *path) {
|
|
41
|
+
struct stat st;
|
|
42
|
+
return stat(path, &st) == 0 && S_ISDIR(st.st_mode);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static int ps_is_file(const char *path) {
|
|
46
|
+
struct stat st;
|
|
47
|
+
return stat(path, &st) == 0 && S_ISREG(st.st_mode);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
static int ps_writable_dir(const char *dir) {
|
|
51
|
+
char file[4096];
|
|
52
|
+
int wrote;
|
|
53
|
+
int fd;
|
|
54
|
+
if (!ps_is_dir(dir)) {
|
|
55
|
+
return 0;
|
|
56
|
+
}
|
|
57
|
+
wrote = snprintf(file, sizeof file, "%s/.ps-temp-%d-%d", dir, (int)getpid(), rand());
|
|
58
|
+
if (wrote < 0 || (size_t)wrote >= sizeof file) {
|
|
59
|
+
return 0;
|
|
60
|
+
}
|
|
61
|
+
fd = open(file, O_CREAT | O_EXCL | O_RDWR, 0600);
|
|
62
|
+
if (fd < 0) {
|
|
63
|
+
return 0;
|
|
64
|
+
}
|
|
65
|
+
if (write(fd, "x", 1) != 1) {
|
|
66
|
+
close(fd);
|
|
67
|
+
unlink(file);
|
|
68
|
+
return 0;
|
|
69
|
+
}
|
|
70
|
+
close(fd);
|
|
71
|
+
unlink(file);
|
|
72
|
+
return 1;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
static char ps_temp_cached[4096];
|
|
76
|
+
static int ps_temp_ready = 0;
|
|
77
|
+
|
|
78
|
+
static void ps_copy_tempdir(char *out, size_t cap) {
|
|
79
|
+
const char *env_names[] = {"TMPDIR", "TEMP", "TMP"};
|
|
80
|
+
const char *fallback[] = {"/tmp", "/var/tmp", "/usr/tmp"};
|
|
81
|
+
char cwd[4096];
|
|
82
|
+
size_t i;
|
|
83
|
+
if (ps_temp_ready) {
|
|
84
|
+
if (strlen(ps_temp_cached) + 1 > cap) {
|
|
85
|
+
ps_os_fail("tempdir");
|
|
86
|
+
}
|
|
87
|
+
memcpy(out, ps_temp_cached, strlen(ps_temp_cached) + 1);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
for (i = 0; i < 3; i++) {
|
|
91
|
+
const char *env = getenv(env_names[i]);
|
|
92
|
+
if (env != NULL && env[0] != '\0' && ps_writable_dir(env)) {
|
|
93
|
+
if (strlen(env) + 1 > cap) {
|
|
94
|
+
ps_os_fail("tempdir");
|
|
95
|
+
}
|
|
96
|
+
memcpy(out, env, strlen(env) + 1);
|
|
97
|
+
goto cache;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
for (i = 0; i < 3; i++) {
|
|
101
|
+
if (ps_writable_dir(fallback[i])) {
|
|
102
|
+
memcpy(out, fallback[i], strlen(fallback[i]) + 1);
|
|
103
|
+
goto cache;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (getcwd(cwd, sizeof cwd) != NULL && ps_writable_dir(cwd)) {
|
|
107
|
+
if (strlen(cwd) + 1 > cap) {
|
|
108
|
+
ps_os_fail("tempdir");
|
|
109
|
+
}
|
|
110
|
+
memcpy(out, cwd, strlen(cwd) + 1);
|
|
111
|
+
goto cache;
|
|
112
|
+
}
|
|
113
|
+
ps_os_fail("tempdir");
|
|
114
|
+
cache:
|
|
115
|
+
if (strlen(out) + 1 < sizeof ps_temp_cached) {
|
|
116
|
+
memcpy(ps_temp_cached, out, strlen(out) + 1);
|
|
117
|
+
ps_temp_ready = 1;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
void ps_temp_getdir(PsBuf *out) {
|
|
122
|
+
char dir[4096];
|
|
123
|
+
ps_copy_tempdir(dir, sizeof dir);
|
|
124
|
+
ps_buf_copy(out, dir, (int64_t)strlen(dir));
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
void ps_temp_prefix(PsBuf *out) { ps_buf_copy(out, "tmp", 3); }
|
|
128
|
+
|
|
129
|
+
void ps_temp_mkdtemp(PsBuf *out) {
|
|
130
|
+
static const char alphabet[] = "abcdefghijklmnopqrstuvwxyz0123456789_";
|
|
131
|
+
char dir[4096];
|
|
132
|
+
char path[4096];
|
|
133
|
+
unsigned char rnd[8];
|
|
134
|
+
FILE *random;
|
|
135
|
+
int attempt;
|
|
136
|
+
size_t base;
|
|
137
|
+
ps_copy_tempdir(dir, sizeof dir);
|
|
138
|
+
base = strlen(dir);
|
|
139
|
+
random = fopen("/dev/urandom", "rb");
|
|
140
|
+
if (random == NULL) {
|
|
141
|
+
ps_os_fail("mkdtemp");
|
|
142
|
+
}
|
|
143
|
+
for (attempt = 0; attempt < 128; attempt++) {
|
|
144
|
+
int i;
|
|
145
|
+
if (fread(rnd, 1, 8, random) != 8) {
|
|
146
|
+
fclose(random);
|
|
147
|
+
ps_os_fail("mkdtemp");
|
|
148
|
+
}
|
|
149
|
+
if (base + 1 + 3 + 8 + 1 > sizeof path) {
|
|
150
|
+
fclose(random);
|
|
151
|
+
ps_os_fail("mkdtemp");
|
|
152
|
+
}
|
|
153
|
+
memcpy(path, dir, base);
|
|
154
|
+
path[base] = '/';
|
|
155
|
+
memcpy(path + base + 1, "tmp", 3);
|
|
156
|
+
for (i = 0; i < 8; i++) {
|
|
157
|
+
path[base + 4 + i] = alphabet[rnd[i] % 37];
|
|
158
|
+
}
|
|
159
|
+
path[base + 12] = '\0';
|
|
160
|
+
if (mkdir(path, 0700) == 0) {
|
|
161
|
+
fclose(random);
|
|
162
|
+
ps_buf_copy(out, path, (int64_t)strlen(path));
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (errno != EEXIST) {
|
|
166
|
+
fclose(random);
|
|
167
|
+
ps_os_fail("mkdtemp");
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
fclose(random);
|
|
171
|
+
ps_os_fail("mkdtemp");
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
static int ps_pkg_rel(int64_t n, const char *pkg, char *rel, size_t cap) {
|
|
175
|
+
int64_t i;
|
|
176
|
+
size_t w = 0;
|
|
177
|
+
int dot = 1;
|
|
178
|
+
if (n <= 0) {
|
|
179
|
+
return 0;
|
|
180
|
+
}
|
|
181
|
+
for (i = 0; i < n; i++) {
|
|
182
|
+
char c = pkg[i];
|
|
183
|
+
int ok = (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '_' || c == '.';
|
|
184
|
+
if (!ok || w + 2 >= cap) {
|
|
185
|
+
return 0;
|
|
186
|
+
}
|
|
187
|
+
if (c == '.') {
|
|
188
|
+
if (dot) {
|
|
189
|
+
return 0;
|
|
190
|
+
}
|
|
191
|
+
rel[w++] = '/';
|
|
192
|
+
dot = 1;
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
rel[w++] = c;
|
|
196
|
+
dot = 0;
|
|
197
|
+
}
|
|
198
|
+
if (dot) {
|
|
199
|
+
return 0;
|
|
200
|
+
}
|
|
201
|
+
rel[w] = '\0';
|
|
202
|
+
return 1;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
void ps_res_files(int64_t pn, const char *pkg, int64_t sn, const char *search, PsPath *out) {
|
|
206
|
+
char rel[512];
|
|
207
|
+
int64_t i = 0;
|
|
208
|
+
if (!ps_pkg_rel(pn, pkg, rel, sizeof rel)) {
|
|
209
|
+
ps_raise_cstr(PS_VALUE, "resource package name is not a dotted identifier");
|
|
210
|
+
}
|
|
211
|
+
while (i <= sn) {
|
|
212
|
+
int64_t start = i;
|
|
213
|
+
char *root;
|
|
214
|
+
char candidate[4096];
|
|
215
|
+
size_t root_n;
|
|
216
|
+
size_t rel_n;
|
|
217
|
+
while (i < sn && search[i] != '\n') {
|
|
218
|
+
i++;
|
|
219
|
+
}
|
|
220
|
+
if (i > start) {
|
|
221
|
+
root = ps_cstr(i - start, search + start);
|
|
222
|
+
root_n = strlen(root);
|
|
223
|
+
rel_n = strlen(rel);
|
|
224
|
+
if (root_n + 1 + rel_n + 4 < sizeof candidate) {
|
|
225
|
+
memcpy(candidate, root, root_n);
|
|
226
|
+
candidate[root_n] = '/';
|
|
227
|
+
memcpy(candidate + root_n + 1, rel, rel_n + 1);
|
|
228
|
+
if (ps_is_dir(candidate)) {
|
|
229
|
+
ps_buf_copy(&out->path, candidate, (int64_t)strlen(candidate));
|
|
230
|
+
free(root);
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
memcpy(candidate + root_n + 1 + rel_n, ".py", 4);
|
|
234
|
+
if (ps_is_file(candidate)) {
|
|
235
|
+
/* A module's resources live in the directory that contains the file. */
|
|
236
|
+
char *slash = strrchr(candidate, '/');
|
|
237
|
+
if (slash == NULL) {
|
|
238
|
+
free(root);
|
|
239
|
+
ps_raise_cstr(PS_VALUE, "resource package was not found on the compile-time path");
|
|
240
|
+
}
|
|
241
|
+
*slash = '\0';
|
|
242
|
+
ps_buf_copy(&out->path, candidate, (int64_t)strlen(candidate));
|
|
243
|
+
free(root);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
free(root);
|
|
248
|
+
}
|
|
249
|
+
if (i >= sn) {
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
252
|
+
i++;
|
|
253
|
+
}
|
|
254
|
+
ps_raise_cstr(PS_VALUE, "resource package was not found on the compile-time path");
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
static void ps_copy_bytes(FILE *in, FILE *out) {
|
|
258
|
+
char buf[4096];
|
|
259
|
+
size_t n;
|
|
260
|
+
while ((n = fread(buf, 1, sizeof buf, in)) > 0) {
|
|
261
|
+
if (fwrite(buf, 1, n, out) != n) {
|
|
262
|
+
ps_os_fail("copyfile");
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
if (ferror(in)) {
|
|
266
|
+
ps_os_fail("copyfile");
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
void ps_shutil_copyfile(int64_t sn, const char *src, int64_t dn, const char *dst, PsBuf *out) {
|
|
271
|
+
char *source = ps_cstr(sn, src);
|
|
272
|
+
char *dest = ps_cstr(dn, dst);
|
|
273
|
+
FILE *in;
|
|
274
|
+
FILE *outf;
|
|
275
|
+
if (strcmp(source, dest) == 0) {
|
|
276
|
+
free(source);
|
|
277
|
+
free(dest);
|
|
278
|
+
ps_raise_cstr(PS_RUNTIME, "copyfile source and destination are the same file");
|
|
279
|
+
}
|
|
280
|
+
in = fopen(source, "rb");
|
|
281
|
+
if (in == NULL) {
|
|
282
|
+
free(source);
|
|
283
|
+
free(dest);
|
|
284
|
+
ps_os_fail("copyfile");
|
|
285
|
+
}
|
|
286
|
+
outf = fopen(dest, "wb");
|
|
287
|
+
if (outf == NULL) {
|
|
288
|
+
fclose(in);
|
|
289
|
+
free(source);
|
|
290
|
+
free(dest);
|
|
291
|
+
ps_os_fail("copyfile");
|
|
292
|
+
}
|
|
293
|
+
ps_copy_bytes(in, outf);
|
|
294
|
+
if (fclose(outf) != 0) {
|
|
295
|
+
fclose(in);
|
|
296
|
+
free(source);
|
|
297
|
+
free(dest);
|
|
298
|
+
ps_os_fail("copyfile");
|
|
299
|
+
}
|
|
300
|
+
fclose(in);
|
|
301
|
+
ps_buf_copy(out, dest, (int64_t)strlen(dest));
|
|
302
|
+
free(source);
|
|
303
|
+
free(dest);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
static void ps_rm_tree(const char *path) {
|
|
307
|
+
struct stat st;
|
|
308
|
+
DIR *dir;
|
|
309
|
+
struct dirent *ent;
|
|
310
|
+
if (lstat(path, &st) != 0) {
|
|
311
|
+
ps_os_fail("rmtree");
|
|
312
|
+
}
|
|
313
|
+
if (!S_ISDIR(st.st_mode)) {
|
|
314
|
+
if (unlink(path) != 0) {
|
|
315
|
+
ps_os_fail("rmtree");
|
|
316
|
+
}
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
dir = opendir(path);
|
|
320
|
+
if (dir == NULL) {
|
|
321
|
+
ps_os_fail("rmtree");
|
|
322
|
+
}
|
|
323
|
+
while ((ent = readdir(dir)) != NULL) {
|
|
324
|
+
char child[4096];
|
|
325
|
+
size_t n;
|
|
326
|
+
size_t m;
|
|
327
|
+
if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) {
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
330
|
+
n = strlen(path);
|
|
331
|
+
m = strlen(ent->d_name);
|
|
332
|
+
if (n + 1 + m + 1 > sizeof child) {
|
|
333
|
+
closedir(dir);
|
|
334
|
+
ps_os_fail("rmtree");
|
|
335
|
+
}
|
|
336
|
+
memcpy(child, path, n);
|
|
337
|
+
child[n] = '/';
|
|
338
|
+
memcpy(child + n + 1, ent->d_name, m + 1);
|
|
339
|
+
ps_rm_tree(child);
|
|
340
|
+
}
|
|
341
|
+
closedir(dir);
|
|
342
|
+
if (rmdir(path) != 0) {
|
|
343
|
+
ps_os_fail("rmtree");
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
void ps_shutil_rmtree(int64_t n, const char *path) {
|
|
348
|
+
char *text = ps_cstr(n, path);
|
|
349
|
+
ps_rm_tree(text);
|
|
350
|
+
free(text);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/* Process-lifetime module slots. A name starts unset (`is None`) and then holds a str, an i64, or a path. */
|
|
354
|
+
|
|
355
|
+
typedef struct PsGlobal {
|
|
356
|
+
char *name;
|
|
357
|
+
int64_t name_n;
|
|
358
|
+
int set;
|
|
359
|
+
int is_int;
|
|
360
|
+
int64_t ival;
|
|
361
|
+
PsBuf buf;
|
|
362
|
+
} PsGlobal;
|
|
363
|
+
|
|
364
|
+
static PsGlobal ps_globals[64];
|
|
365
|
+
static int ps_global_n;
|
|
366
|
+
|
|
367
|
+
static PsGlobal *ps_global_slot(int64_t n, const char *name, int create) {
|
|
368
|
+
int i;
|
|
369
|
+
PsGlobal *slot;
|
|
370
|
+
for (i = 0; i < ps_global_n; i++) {
|
|
371
|
+
if (ps_globals[i].name_n == n && memcmp(ps_globals[i].name, name, (size_t)n) == 0) {
|
|
372
|
+
return &ps_globals[i];
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
if (!create) {
|
|
376
|
+
return NULL;
|
|
377
|
+
}
|
|
378
|
+
if (ps_global_n >= 64) {
|
|
379
|
+
ps_raise_cstr(PS_RUNTIME, "too many global slots");
|
|
380
|
+
}
|
|
381
|
+
slot = &ps_globals[ps_global_n++];
|
|
382
|
+
slot->name = malloc((size_t)n + 1);
|
|
383
|
+
if (slot->name == NULL) {
|
|
384
|
+
ps_raise_cstr(PS_RUNTIME, "out of memory");
|
|
385
|
+
}
|
|
386
|
+
if (n > 0) {
|
|
387
|
+
memcpy(slot->name, name, (size_t)n);
|
|
388
|
+
}
|
|
389
|
+
slot->name[n] = '\0';
|
|
390
|
+
slot->name_n = n;
|
|
391
|
+
slot->set = 0;
|
|
392
|
+
slot->is_int = 0;
|
|
393
|
+
slot->ival = 0;
|
|
394
|
+
slot->buf.len = 0;
|
|
395
|
+
slot->buf.data = &ps_empty_byte;
|
|
396
|
+
return slot;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
int32_t ps_global_is_set(int64_t n, const char *name) {
|
|
400
|
+
PsGlobal *slot = ps_global_slot(n, name, 0);
|
|
401
|
+
return slot != NULL && slot->set ? 1 : 0;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
void ps_global_set_str(int64_t nn, const char *name, int64_t vn, const char *val) {
|
|
405
|
+
PsGlobal *slot = ps_global_slot(nn, name, 1);
|
|
406
|
+
ps_buf_copy(&slot->buf, val, vn);
|
|
407
|
+
slot->is_int = 0;
|
|
408
|
+
slot->set = 1;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
void ps_global_get_str(int64_t n, const char *name, PsBuf *out) {
|
|
412
|
+
PsGlobal *slot = ps_global_slot(n, name, 0);
|
|
413
|
+
if (slot == NULL || !slot->set || slot->is_int) {
|
|
414
|
+
ps_raise_cstr(PS_RUNTIME, "global is unset");
|
|
415
|
+
}
|
|
416
|
+
ps_buf_copy(out, slot->buf.data == NULL ? "" : slot->buf.data, slot->buf.len);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
void ps_global_set_i64(int64_t n, const char *name, int64_t value) {
|
|
420
|
+
PsGlobal *slot = ps_global_slot(n, name, 1);
|
|
421
|
+
slot->ival = value;
|
|
422
|
+
slot->is_int = 1;
|
|
423
|
+
slot->set = 1;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
int64_t ps_global_get_i64(int64_t n, const char *name) {
|
|
427
|
+
PsGlobal *slot = ps_global_slot(n, name, 0);
|
|
428
|
+
if (slot == NULL || !slot->set || !slot->is_int) {
|
|
429
|
+
ps_raise_cstr(PS_RUNTIME, "global is unset");
|
|
430
|
+
}
|
|
431
|
+
return slot->ival;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
void ps_global_set_path(int64_t n, const char *name, PsPath *path) {
|
|
435
|
+
PsGlobal *slot = ps_global_slot(n, name, 1);
|
|
436
|
+
ps_buf_copy(&slot->buf, path->path.data == NULL ? "" : path->path.data, path->path.len);
|
|
437
|
+
slot->is_int = 0;
|
|
438
|
+
slot->set = 1;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
void ps_global_get_path(int64_t n, const char *name, PsPath *out) {
|
|
442
|
+
PsGlobal *slot = ps_global_slot(n, name, 0);
|
|
443
|
+
if (slot == NULL || !slot->set || slot->is_int) {
|
|
444
|
+
ps_raise_cstr(PS_RUNTIME, "global is unset");
|
|
445
|
+
}
|
|
446
|
+
ps_buf_copy(&out->path, slot->buf.data == NULL ? "" : slot->buf.data, slot->buf.len);
|
|
447
|
+
}
|