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>
This commit is contained in:
Andrew Leech
2025-05-26 20:25:01 +10:00
committed by Damien George
parent 7b3a0fc6b7
commit 7ac8fcf752
4 changed files with 13 additions and 3 deletions

View File

@@ -58,7 +58,7 @@
#include "shared/runtime/pyexec.h"
// Command line options, with their defaults
static bool compile_only = false;
bool mp_compile_only = false;
static uint emit_opt = MP_EMIT_OPT_NONE;
#if MICROPY_ENABLE_GC
@@ -159,7 +159,7 @@ static int execute_from_lexer(int source_kind, const void *source, mp_parse_inpu
mp_obj_t module_fun = mp_compile(&parse_tree, source_name, is_repl);
if (!compile_only) {
if (!mp_compile_only) {
// execute it
mp_call_function_0(module_fun);
}
@@ -325,7 +325,7 @@ static void pre_process_options(int argc, char **argv) {
}
if (0) {
} else if (strcmp(argv[a + 1], "compile-only") == 0) {
compile_only = true;
mp_compile_only = true;
} else if (strcmp(argv[a + 1], "emit=bytecode") == 0) {
emit_opt = MP_EMIT_OPT_BYTECODE;
#if MICROPY_EMIT_NATIVE

View File

@@ -151,6 +151,9 @@ typedef long mp_off_t;
// Enable sys.executable.
#define MICROPY_PY_SYS_EXECUTABLE (1)
// Enable support for compile-only mode.
#define MICROPY_PYEXEC_COMPILE_ONLY (1)
#define MICROPY_PY_SOCKET_LISTEN_BACKLOG_DEFAULT (SOMAXCONN < 128 ? SOMAXCONN : 128)
// Bare-metal ports don't have stderr. Printing debug to stderr may give tests

View File

@@ -25,6 +25,7 @@
*/
#include <errno.h>
#include <unistd.h>
#include <stdbool.h>
#ifndef CHAR_CTRL_C
#define CHAR_CTRL_C (3)
@@ -117,3 +118,6 @@ enum {
void mp_hal_get_mac(int idx, uint8_t buf[6]);
#endif
// Global variable to control compile-only mode.
extern bool mp_compile_only;

View File

@@ -161,6 +161,9 @@
#define MICROPY_MACHINE_MEM_GET_READ_ADDR mod_machine_mem_get_addr
#define MICROPY_MACHINE_MEM_GET_WRITE_ADDR mod_machine_mem_get_addr
// Enable support for compile-only mode.
#define MICROPY_PYEXEC_COMPILE_ONLY (1)
#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_DETAILED)
#define MICROPY_ERROR_PRINTER (&mp_stderr_print)
#define MICROPY_WARNINGS (1)