Commit a374d9c8 authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

unix: Allow to set heap size using "-X heapsize=N" option.

parent 25f5a30e
......@@ -24,9 +24,10 @@
#include <readline/history.h>
#endif
#if MICROPY_ENABLE_GC
// Heap size of GC heap (if enabled)
// TODO: allow to specify on command line
#define HEAP_SIZE 128*1024
long heap_size = 128*1024;
#endif
// Stack top at the start of program
void *stack_top;
......@@ -233,13 +234,34 @@ static mp_obj_t pyb_gc(void) {
MP_DEFINE_CONST_FUN_OBJ_0(pyb_gc_obj, pyb_gc);
#endif
// Process options which set interpreter init options
void pre_process_options(int argc, char **argv) {
for (int a = 1; a < argc; a++) {
if (argv[a][0] == '-') {
if (strcmp(argv[a], "-X") == 0) {
if (a + 1 >= argc) {
exit(usage());
}
#if MICROPY_ENABLE_GC
if (strncmp(argv[a + 1], "heapsize=", sizeof("heapsize=") - 1) == 0) {
heap_size = strtol(argv[a + 1] + sizeof("heapsize=") - 1, NULL, 0);
}
#endif
a++;
}
}
}
}
int main(int argc, char **argv) {
volatile int stack_dummy;
stack_top = (void*)&stack_dummy;
pre_process_options(argc, argv);
#if MICROPY_ENABLE_GC
char *heap = malloc(HEAP_SIZE);
gc_init(heap, heap + HEAP_SIZE);
char *heap = malloc(heap_size);
gc_init(heap, heap + heap_size);
#endif
qstr_init();
......@@ -319,9 +341,7 @@ int main(int argc, char **argv) {
printf(" peak %d\n", m_get_peak_bytes_allocated());
*/
if (argc == 1) {
do_repl();
} else {
bool executed = false;
for (int a = 1; a < argc; a++) {
if (argv[a][0] == '-') {
if (strcmp(argv[a], "-c") == 0) {
......@@ -329,6 +349,9 @@ int main(int argc, char **argv) {
return usage();
}
do_str(argv[a + 1]);
executed = true;
a += 1;
} else if (strcmp(argv[a], "-X") == 0) {
a += 1;
} else {
return usage();
......@@ -345,9 +368,13 @@ int main(int argc, char **argv) {
rt_list_append(py_argv, MP_OBJ_NEW_QSTR(qstr_from_str(argv[i])));
}
do_file(argv[a]);
executed = true;
break;
}
}
if (!executed) {
do_repl();
}
rt_deinit();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment