port.c
1.23 KB
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
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <setjmp.h>
#include "py/nlr.h"
#include "py/compile.h"
#include "py/runtime.h"
#include "py/repl.h"
#include "py/gc.h"
#include "py/mperrno.h"
typedef jmp_buf regs_t;
STATIC void gc_helper_get_regs(regs_t arr) {
setjmp(arr);
}
static char * python_stack_top = NULL;
void mp_port_init_stack_top() {
char dummy;
python_stack_top = &dummy;
}
void gc_collect(void) {
assert(python_stack_top != NULL);
gc_collect_start();
/* get the registers.
* regs is the also the last object on the stack so the stack is bound by
* ®s and python_stack_top. */
regs_t regs;
gc_helper_get_regs(regs);
void **regs_ptr = (void**)(void*)®s;
gc_collect_root(regs_ptr, ((uintptr_t)python_stack_top - (uintptr_t)®s) / sizeof(uintptr_t));
gc_collect_end();
}
mp_lexer_t *mp_lexer_new_from_file(const char *filename) {
mp_raise_OSError(MP_ENOENT);
}
mp_import_stat_t mp_import_stat(const char *path) {
return MP_IMPORT_STAT_NO_EXIST;
}
mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);
void nlr_jump_fail(void *val) {
while (1);
}