Skip to content

Commit 7ac8fcf

Browse files
pi-anldpgeorge
authored andcommitted
unix: Enable compile-only mode with shared pyexec REPL.
Provides support for command line `-X compile-only` option on unix port. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
1 parent 7b3a0fc commit 7ac8fcf

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

ports/unix/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
#include "shared/runtime/pyexec.h"
5959

6060
// Command line options, with their defaults
61-
static bool compile_only = false;
61+
bool mp_compile_only = false;
6262
static uint emit_opt = MP_EMIT_OPT_NONE;
6363

6464
#if MICROPY_ENABLE_GC
@@ -159,7 +159,7 @@ static int execute_from_lexer(int source_kind, const void *source, mp_parse_inpu
159159

160160
mp_obj_t module_fun = mp_compile(&parse_tree, source_name, is_repl);
161161

162-
if (!compile_only) {
162+
if (!mp_compile_only) {
163163
// execute it
164164
mp_call_function_0(module_fun);
165165
}
@@ -325,7 +325,7 @@ static void pre_process_options(int argc, char **argv) {
325325
}
326326
if (0) {
327327
} else if (strcmp(argv[a + 1], "compile-only") == 0) {
328-
compile_only = true;
328+
mp_compile_only = true;
329329
} else if (strcmp(argv[a + 1], "emit=bytecode") == 0) {
330330
emit_opt = MP_EMIT_OPT_BYTECODE;
331331
#if MICROPY_EMIT_NATIVE

ports/unix/mpconfigport.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ typedef long mp_off_t;
151151
// Enable sys.executable.
152152
#define MICROPY_PY_SYS_EXECUTABLE (1)
153153

154+
// Enable support for compile-only mode.
155+
#define MICROPY_PYEXEC_COMPILE_ONLY (1)
156+
154157
#define MICROPY_PY_SOCKET_LISTEN_BACKLOG_DEFAULT (SOMAXCONN < 128 ? SOMAXCONN : 128)
155158

156159
// Bare-metal ports don't have stderr. Printing debug to stderr may give tests

ports/unix/mphalport.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
*/
2626
#include <errno.h>
2727
#include <unistd.h>
28+
#include <stdbool.h>
2829

2930
#ifndef CHAR_CTRL_C
3031
#define CHAR_CTRL_C (3)
@@ -117,3 +118,6 @@ enum {
117118

118119
void mp_hal_get_mac(int idx, uint8_t buf[6]);
119120
#endif
121+
122+
// Global variable to control compile-only mode.
123+
extern bool mp_compile_only;

ports/windows/mpconfigport.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@
161161
#define MICROPY_MACHINE_MEM_GET_READ_ADDR mod_machine_mem_get_addr
162162
#define MICROPY_MACHINE_MEM_GET_WRITE_ADDR mod_machine_mem_get_addr
163163

164+
// Enable support for compile-only mode.
165+
#define MICROPY_PYEXEC_COMPILE_ONLY (1)
166+
164167
#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_DETAILED)
165168
#define MICROPY_ERROR_PRINTER (&mp_stderr_print)
166169
#define MICROPY_WARNINGS (1)

0 commit comments

Comments
 (0)