The REPL is now an option at compile time using -DFUN_WITH_REPL=ON. (0.17.6)
This commit is contained in:
parent
4e5d104e48
commit
f68d09c596
2 changed files with 31 additions and 8 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
cmake_minimum_required(VERSION 3.16)
|
cmake_minimum_required(VERSION 3.16)
|
||||||
project(fun VERSION 0.17.4 LANGUAGES C)
|
project(fun VERSION 0.17.6 LANGUAGES C)
|
||||||
|
|
||||||
set(CMAKE_C_STANDARD 11)
|
set(CMAKE_C_STANDARD 11)
|
||||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||||
|
|
@ -86,12 +86,16 @@ if(Threads_FOUND)
|
||||||
target_link_libraries(fun_core PUBLIC Threads::Threads)
|
target_link_libraries(fun_core PUBLIC Threads::Threads)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Playground / interpreter (future /usr/bin/fun)
|
# Interpreter /usr/bin/fun
|
||||||
|
option(FUN_WITH_REPL "Enable interactive REPL in the fun CLI" OFF)
|
||||||
add_executable(fun
|
add_executable(fun
|
||||||
src/fun.c
|
src/fun.c
|
||||||
)
|
)
|
||||||
# Provide version string to the CLI
|
# Provide version string to the CLI
|
||||||
target_compile_definitions(fun PRIVATE FUN_VERSION=\"${PROJECT_VERSION}\")
|
target_compile_definitions(fun PRIVATE FUN_VERSION=\"${PROJECT_VERSION}\")
|
||||||
|
if(FUN_WITH_REPL)
|
||||||
|
target_compile_definitions(fun PRIVATE FUN_WITH_REPL=0)
|
||||||
|
endif()
|
||||||
target_link_libraries(fun PRIVATE fun_core)
|
target_link_libraries(fun PRIVATE fun_core)
|
||||||
|
|
||||||
# Internal test programs
|
# Internal test programs
|
||||||
|
|
@ -113,12 +117,14 @@ add_custom_target(build
|
||||||
# Convenience targets: repl, run, threads-demo, ops, examples
|
# Convenience targets: repl, run, threads-demo, ops, examples
|
||||||
set(FUN_RUN_SCRIPT "" CACHE STRING "Script to run with the 'run' target, e.g. -DFUN_RUN_SCRIPT=examples/strings_test.fun")
|
set(FUN_RUN_SCRIPT "" CACHE STRING "Script to run with the 'run' target, e.g. -DFUN_RUN_SCRIPT=examples/strings_test.fun")
|
||||||
|
|
||||||
add_custom_target(repl
|
if(FUN_WITH_REPL)
|
||||||
COMMAND $<TARGET_FILE:fun>
|
add_custom_target(repl
|
||||||
DEPENDS fun
|
COMMAND $<TARGET_FILE:fun>
|
||||||
USES_TERMINAL
|
DEPENDS fun
|
||||||
COMMENT "Run Fun REPL"
|
USES_TERMINAL
|
||||||
)
|
COMMENT "Run Fun REPL"
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_custom_target(run
|
add_custom_target(run
|
||||||
COMMAND $<TARGET_FILE:fun> ${FUN_RUN_SCRIPT}
|
COMMAND $<TARGET_FILE:fun> ${FUN_RUN_SCRIPT}
|
||||||
|
|
|
||||||
17
src/fun.c
17
src/fun.c
|
|
@ -710,11 +710,19 @@ static int buffer_looks_incomplete(const char *buf) {
|
||||||
static void print_usage(const char *prog) {
|
static void print_usage(const char *prog) {
|
||||||
printf("Fun %s\n", FUN_VERSION);
|
printf("Fun %s\n", FUN_VERSION);
|
||||||
printf("Usage:\n");
|
printf("Usage:\n");
|
||||||
|
#ifdef FUN_WITH_REPL
|
||||||
printf(" %s [script.fun]\n", prog ? prog : "fun");
|
printf(" %s [script.fun]\n", prog ? prog : "fun");
|
||||||
printf(" %s --help | -h\n", prog ? prog : "fun");
|
printf(" %s --help | -h\n", prog ? prog : "fun");
|
||||||
printf(" %s --version | -V\n", prog ? prog : "fun");
|
printf(" %s --version | -V\n", prog ? prog : "fun");
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("When no script is provided, a REPL starts. Submit an empty line to execute the buffer.\n");
|
printf("When no script is provided, a REPL starts. Submit an empty line to execute the buffer.\n");
|
||||||
|
#else
|
||||||
|
printf(" %s <script.fun>\n", prog ? prog : "fun");
|
||||||
|
printf(" %s --help | -h\n", prog ? prog : "fun");
|
||||||
|
printf(" %s --version | -V\n", prog ? prog : "fun");
|
||||||
|
printf("\n");
|
||||||
|
printf("REPL is disabled in this build. Please provide a script file to run.\n");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void show_repl_help(void) {
|
static void show_repl_help(void) {
|
||||||
|
|
@ -836,6 +844,15 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef FUN_WITH_REPL
|
||||||
|
// When REPL is disabled, require a script file argument (allow --help/--version above).
|
||||||
|
if (argc <= 1) {
|
||||||
|
fprintf(stderr, "Error: REPL is disabled. Please provide a script to run.\n");
|
||||||
|
print_usage(argv[0]);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// If a script path is provided, parse and run it
|
// If a script path is provided, parse and run it
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
const char *path = argv[1];
|
const char *path = argv[1];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue