|
8 | 8 | #include "py/runtime.h" |
9 | 9 | #include "py/repl.h" |
10 | 10 | #include "py/pfenv.h" |
| 11 | +#include "py/gc.h" |
| 12 | +#include "pyexec.h" |
| 13 | +#include "pybstdio.h" |
11 | 14 |
|
12 | 15 | void do_str(const char *src) { |
13 | 16 | mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0); |
@@ -46,14 +49,31 @@ void do_str(const char *src) { |
46 | 49 | } |
47 | 50 | } |
48 | 51 |
|
| 52 | +static char *stack_top; |
| 53 | +static char heap[2048]; |
| 54 | + |
49 | 55 | int main(int argc, char **argv) { |
| 56 | + int stack_dummy; |
| 57 | + stack_top = (char*)&stack_dummy; |
| 58 | + |
| 59 | +#if MICROPY_ENABLE_GC |
| 60 | + gc_init(heap, heap + sizeof(heap)); |
| 61 | +#endif |
50 | 62 | mp_init(); |
51 | | - do_str("print('hello world!', list(x+1 for x in range(10)), end='eol\n')"); |
| 63 | + pyexec_friendly_repl(); |
| 64 | + //do_str("print('hello world!', list(x+1 for x in range(10)), end='eol\\n')"); |
52 | 65 | mp_deinit(); |
53 | 66 | return 0; |
54 | 67 | } |
55 | 68 |
|
56 | 69 | void gc_collect(void) { |
| 70 | + // WARNING: This gc_collect implementation doesn't try to get root |
| 71 | + // pointers from CPU registers, and thus may function incorrectly. |
| 72 | + void *dummy; |
| 73 | + gc_collect_start(); |
| 74 | + gc_collect_root(&dummy, ((mp_uint_t)stack_top - (mp_uint_t)&dummy) / sizeof(mp_uint_t)); |
| 75 | + gc_collect_end(); |
| 76 | + gc_dump_info(); |
57 | 77 | } |
58 | 78 |
|
59 | 79 | mp_lexer_t *mp_lexer_new_from_file(const char *filename) { |
@@ -83,39 +103,6 @@ void MP_WEAK __assert_func(const char *file, int line, const char *func, const c |
83 | 103 | } |
84 | 104 | #endif |
85 | 105 |
|
86 | | -/* |
87 | | -int _lseek() {return 0;} |
88 | | -int _read() {return 0;} |
89 | | -int _write() {return 0;} |
90 | | -int _close() {return 0;} |
91 | | -void _exit(int x) {for(;;){}} |
92 | | -int _sbrk() {return 0;} |
93 | | -int _kill() {return 0;} |
94 | | -int _getpid() {return 0;} |
95 | | -int _fstat() {return 0;} |
96 | | -int _isatty() {return 0;} |
97 | | -*/ |
98 | | - |
99 | | -void *malloc(size_t n) {return NULL;} |
100 | | -void *calloc(size_t nmemb, size_t size) {return NULL;} |
101 | | -void *realloc(void *ptr, size_t size) {return NULL;} |
102 | | -void free(void *p) {} |
103 | | -int printf(const char *m, ...) {return 0;} |
104 | | -void *memcpy(void *dest, const void *src, size_t n) {return NULL;} |
105 | | -int memcmp(const void *s1, const void *s2, size_t n) {return 0;} |
106 | | -void *memmove(void *dest, const void *src, size_t n) {return NULL;} |
107 | | -void *memset(void *s, int c, size_t n) {return NULL;} |
108 | | -int strcmp(const char *s1, const char* s2) {return 0;} |
109 | | -int strncmp(const char *s1, const char* s2, size_t n) {return 0;} |
110 | | -size_t strlen(const char *s) {return 0;} |
111 | | -char *strcat(char *dest, const char *src) {return NULL;} |
112 | | -char *strchr(const char *dest, int c) {return NULL;} |
113 | | -#include <stdarg.h> |
114 | | -int vprintf(const char *format, va_list ap) {return 0;} |
115 | | -int vsnprintf(char *str, size_t size, const char *format, va_list ap) {return 0;} |
116 | | - |
117 | | -#undef putchar |
118 | | -int putchar(int c) {return 0;} |
119 | | -int puts(const char *s) {return 0;} |
120 | | - |
| 106 | +#if !MICROPY_MIN_USE_STDOUT |
121 | 107 | void _start(void) {main(0, NULL);} |
| 108 | +#endif |
0 commit comments