Made MAX_FRAMES, MAX_FRAME_LOCALS, MAX_GLOBALS, OUTPUT_SIZE and STACK_SIZE configurable during build configuration using cmake defines (-D). No code changes. (0.40.5)
This commit is contained in:
parent
5c57391e5d
commit
bebe6dfda0
4 changed files with 45 additions and 0 deletions
|
|
@ -33,3 +33,10 @@ endif()
|
||||||
|
|
||||||
# Debug option to enable verbose parser/VM logging
|
# Debug option to enable verbose parser/VM logging
|
||||||
option(FUN_DEBUG "Enable extra debug logging in Fun" OFF)
|
option(FUN_DEBUG "Enable extra debug logging in Fun" OFF)
|
||||||
|
|
||||||
|
# VM settings (configurable via -D...)
|
||||||
|
set(MAX_FRAMES 128 CACHE STRING "Maximum depth of the call stack (frames)")
|
||||||
|
set(MAX_FRAME_LOCALS 64 CACHE STRING "Maximum number of local variables per frame")
|
||||||
|
set(MAX_GLOBALS 128 CACHE STRING "Maximum number of global variables")
|
||||||
|
set(OUTPUT_SIZE 1024 CACHE STRING "Size of the VM output buffer (number of values)")
|
||||||
|
set(STACK_SIZE 1024 CACHE STRING "Size of the VM evaluation stack")
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,13 @@ endif()
|
||||||
target_compile_definitions(fun_core PUBLIC FUN_VERSION="${PROJECT_VERSION}")
|
target_compile_definitions(fun_core PUBLIC FUN_VERSION="${PROJECT_VERSION}")
|
||||||
target_compile_definitions(fun_core PUBLIC DEFAULT_LIB_DIR="${DEFAULT_LIB_DIR}")
|
target_compile_definitions(fun_core PUBLIC DEFAULT_LIB_DIR="${DEFAULT_LIB_DIR}")
|
||||||
|
|
||||||
|
# VM configuration
|
||||||
|
target_compile_definitions(fun_core PUBLIC MAX_FRAMES=${MAX_FRAMES})
|
||||||
|
target_compile_definitions(fun_core PUBLIC MAX_FRAME_LOCALS=${MAX_FRAME_LOCALS})
|
||||||
|
target_compile_definitions(fun_core PUBLIC MAX_GLOBALS=${MAX_GLOBALS})
|
||||||
|
target_compile_definitions(fun_core PUBLIC OUTPUT_SIZE=${OUTPUT_SIZE})
|
||||||
|
target_compile_definitions(fun_core PUBLIC STACK_SIZE=${STACK_SIZE})
|
||||||
|
|
||||||
# Apply extension include/link variables discovered in cmake/Extensions
|
# Apply extension include/link variables discovered in cmake/Extensions
|
||||||
foreach(var_pair
|
foreach(var_pair
|
||||||
PCSC
|
PCSC
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,17 @@ Fun exposes several options you can toggle at configure time:
|
||||||
- `FUN_WITH_RUST` (ON/OFF) - Build and link Rust staticlib from `src/rust/`
|
- `FUN_WITH_RUST` (ON/OFF) - Build and link Rust staticlib from `src/rust/`
|
||||||
- `FUN_WITH_OPENSSL` (ON/OFF) - Enable OpenSSL-backed helpers (MD5/SHA-256/SHA-512/RIPEMD-160)
|
- `FUN_WITH_OPENSSL` (ON/OFF) - Enable OpenSSL-backed helpers (MD5/SHA-256/SHA-512/RIPEMD-160)
|
||||||
|
|
||||||
|
### VM configuration constants
|
||||||
|
You can override internal VM limits at compile time by passing `-D<VAR>=<VALUE>` to CMake:
|
||||||
|
|
||||||
|
- `MAX_FRAMES` (default: 128) - Maximum depth of the call stack (frames)
|
||||||
|
- `MAX_FRAME_LOCALS` (default: 64) - Maximum number of local variables per frame
|
||||||
|
- `MAX_GLOBALS` (default: 128) - Maximum number of global variables
|
||||||
|
- `OUTPUT_SIZE` (default: 1024) - Size of the VM output buffer (number of values)
|
||||||
|
- `STACK_SIZE` (default: 1024) - Size of the VM evaluation stack (number of `Value` slots)
|
||||||
|
|
||||||
|
These are defined as `CACHE` variables, so they will persist in your `CMakeCache.txt`.
|
||||||
|
|
||||||
When configuring, the build prints a summary like:
|
When configuring, the build prints a summary like:
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
@ -59,6 +70,12 @@ cmake -S . -B build_release -DCMAKE_BUILD_TYPE=Release \
|
||||||
cmake --build build_release --target build
|
cmake --build build_release --target build
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Customizing VM limits
|
||||||
|
```
|
||||||
|
cmake -S . -B build_custom -DSTACK_SIZE=4096 -DMAX_GLOBALS=512
|
||||||
|
cmake --build build_custom --target fun
|
||||||
|
```
|
||||||
|
|
||||||
If `FUN_WITH_RUST` is enabled, ensure `cargo` is available in PATH; the build will invoke it and link the produced static library.
|
If `FUN_WITH_RUST` is enabled, ensure `cargo` is available in PATH; the build will invoke it and link the produced static library.
|
||||||
|
|
||||||
If `FUN_WITH_OPENSSL` is enabled, CMake must detect your system OpenSSL (libcrypto).
|
If `FUN_WITH_OPENSSL` is enabled, CMake must detect your system OpenSSL (libcrypto).
|
||||||
|
|
|
||||||
14
src/vm.h
14
src/vm.h
|
|
@ -13,11 +13,25 @@
|
||||||
#include "bytecode.h"
|
#include "bytecode.h"
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#ifndef MAX_FRAMES
|
||||||
#define MAX_FRAMES 128
|
#define MAX_FRAMES 128
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef MAX_FRAME_LOCALS
|
||||||
#define MAX_FRAME_LOCALS 64
|
#define MAX_FRAME_LOCALS 64
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef MAX_GLOBALS
|
||||||
#define MAX_GLOBALS 128
|
#define MAX_GLOBALS 128
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef OUTPUT_SIZE
|
||||||
#define OUTPUT_SIZE 1024
|
#define OUTPUT_SIZE 1024
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef STACK_SIZE
|
||||||
#define STACK_SIZE 1024
|
#define STACK_SIZE 1024
|
||||||
|
#endif
|
||||||
|
|
||||||
static const char *opcode_names[] = {
|
static const char *opcode_names[] = {
|
||||||
"NOP", "LOAD_CONST", "LOAD_LOCAL", "STORE_LOCAL",
|
"NOP", "LOAD_CONST", "LOAD_LOCAL", "STORE_LOCAL",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue