aboutsummaryrefslogtreecommitdiff
path: root/source/config.c
diff options
context:
space:
mode:
authornodist <kevin.comas.git@gmail.com>2026-09-23 12:32:31 -0400
committernodist <kevin.comas.git@gmail.com>2026-09-23 12:32:31 -0400
commit07af98f3a5a54a8736109ed031d3177508943299 (patch)
tree032427fabed19c59349c51ce842517e6895a33b8 /source/config.c
parentd93466b950ff760a1dd7fd0c2d8ae72c8f1ee0b5 (diff)
add task queues
Diffstat (limited to 'source/config.c')
-rw-r--r--source/config.c124
1 files changed, 94 insertions, 30 deletions
diff --git a/source/config.c b/source/config.c
index 461197d..31de7d4 100644
--- a/source/config.c
+++ b/source/config.c
@@ -1,15 +1,25 @@
#include "kpl.h"
-static kpl_config default_config = {
- .argc = -1, .main_module_arg_index = -1,
+static const kpl_config default_config = {
+ .argc = -1, .main_module_arg_index = -1, .version = KPL_VERSION,
.argv = NULL, .module_extension = ".kpl",
.flags = 0,
.io = {
- .queue_pow = KPL_IO_QUEUE_POW_DEFAULT
+ .queue_pow2 = KPL_CONFIG_IO_QUEUE_POW2_DEFAULT
},
.thread = {
- .count = -1
+ .count = KPL_CONFIG_THREAD_COUNT_AFFINITY,
+ .ring_pool_entries_pow2 = {
+ [0] = 0, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 13,
+ [6] = 13, [7] = 13, [8] = 13, [9] = 13, [10] = 13, [11] = 13,
+ [12] = 13, [13] = 13, [14] = 13, [15] = 13, [16] = 13, [17] = 13,
+ [18] = 13, [19] = 13, [20] = 13, [21] = 13, [22] = 13, [23] = 13,
+ [24] = 13, [25] = 13, [26] = 13, [27] = 13
+ }
+ },
+ .code = {
+ .queue_pow2 = KPL_CONFIG_CODE_QUEUE_POW2_DEFAULT
}
};
@@ -30,6 +40,46 @@ static int32_t kpl_arg_match_module_extension(const char *match_str, const int32
return KPL_EXIT_CODE_SUCCESS;
}
+static int32_t kpl_arg_match_io_queue_pow2(const char *match_str, const int32_t match_str_index, kpl_config *config) {
+ int32_t queue_pow2 = atoi(match_str + match_str_index);
+ if (queue_pow2 < KPL_CONFIG_IO_QUEUE_POW2_MIN || queue_pow2 > KPL_CONFIG_IO_QUEUE_POW2_MAX)
+ return KPL_EXIT_CODE_ERROR;
+ config->io.queue_pow2 = queue_pow2;
+ return KPL_EXIT_CODE_SUCCESS;
+}
+
+static int32_t kpl_arg_match_thread_count(const char *match_str, const int32_t match_str_index, kpl_config *config) {
+ int32_t thread_count = atoi(match_str + match_str_index);
+ if (thread_count <= 0 || thread_count > KPL_CONFIG_THREAD_COUNT_MAX)
+ return KPL_EXIT_CODE_ERROR;
+ config->thread.count = thread_count;
+ return KPL_EXIT_CODE_SUCCESS;
+}
+
+static int32_t kpl_arg_match_memory_pool_pow2(const char *match_str, const int32_t match_str_index, kpl_config *config) {
+ char *endptr;
+ int32_t object_size_pow2 = strtol(match_str + match_str_index, &endptr, 10);
+ if (object_size_pow2 < KPL_CONFIG_THREAD_RING_POOL_MIN_OBJECT_SIZE_POW2 ||
+ object_size_pow2 > KPL_CONFIG_THREAD_RING_POOL_MAX_OBJECT_SIZE_POW2)
+ return KPL_EXIT_CODE_ERROR;
+ while (*endptr && !isdigit(*endptr))
+ endptr++;
+ int32_t entry_size_pow2 = strtol(endptr, NULL, 10);
+ if (entry_size_pow2 < KPL_CONFIG_THREAD_RING_POOL_MIN_RING_SIZE_POW2 ||
+ entry_size_pow2 > KPL_CONFIG_THREAD_RING_POOL_MAX_RING_SIZE_POW2)
+ return KPL_EXIT_CODE_ERROR;
+ config->thread.ring_pool_entries_pow2[object_size_pow2] = entry_size_pow2;
+ return KPL_EXIT_CODE_SUCCESS;
+}
+
+static int32_t kpl_arg_match_code_queue_pow2(const char *match_str, const int32_t match_str_index, kpl_config *config) {
+ int32_t queue_pow2 = atoi(match_str + match_str_index);
+ if (queue_pow2 < KPL_CONFIG_CODE_QUEUE_POW2_MIN || queue_pow2 > KPL_CONFIG_CODE_QUEUE_POW2_MAX)
+ return KPL_EXIT_CODE_ERROR;
+ config->code.queue_pow2 = queue_pow2;
+ return KPL_EXIT_CODE_SUCCESS;
+}
+
static int32_t kpl_arg_match_eval(const char *match_str, const int32_t match_str_index, kpl_config *config) {
(void) match_str;
(void) match_str_index;
@@ -44,20 +94,14 @@ static int32_t kpl_arg_match_repl(const char *match_str, const int32_t match_str
return KPL_EXIT_CODE_SUCCESS;
}
-static int32_t kpl_arg_match_io_queue_pow(const char *match_str, const int32_t match_str_index, kpl_config *config) {
- int32_t queue_pow = atoi(match_str + match_str_index);
- if (queue_pow < KPL_IO_QUEUE_POW_MIN || queue_pow > KPL_IO_QUEUE_POW_MAX)
- return KPL_EXIT_CODE_ERROR;
- config->io.queue_pow = queue_pow;
- return KPL_EXIT_CODE_SUCCESS;
-}
-
-static int32_t kpl_arg_match_thread_count(const char *match_str, const int32_t match_str_index, kpl_config *config) {
- int32_t thread_count = atoi(match_str + match_str_index);
- if (!thread_count)
- return KPL_EXIT_CODE_ERROR;
- config->thread.count = thread_count;
- return KPL_EXIT_CODE_SUCCESS;
+static int32_t kpl_arg_match_version(const char *match_str, const int32_t match_str_index, kpl_config *config) {
+ (void) match_str_index;
+ printf("\nKevin's Programming Language (" KPL_COLOR(LIGHT_BLUE) "KPL" KPL_COLOR(RESET)
+ "), Version: " KPL_COLOR(LIGHT_GREEN) "%s\n" KPL_COLOR(RESET),
+ config->version);
+ if (match_str)
+ putchar('\n');
+ return KPL_EXIT_CODE_HELP;
}
static int32_t kpl_arg_match_help(const char *match_str, const int32_t match_str_index, kpl_config *config);
@@ -65,36 +109,56 @@ static int32_t kpl_arg_match_help(const char *match_str, const int32_t match_str
static kpl_arg_match arg_match_array[] = {
{
.match_str = "--module-extension=",
- .help_message="[WORD], Change the module extension for imports (default .kpl)",
+ .help_message="[WORD]; Change the module extension for imports (default .kpl)",
.arg_match_fn = kpl_arg_match_module_extension
},
{
- .match_str = "--eval",
- .help_message = " [STRING...], Evaluate next argument(s) as modules",
- .arg_match_fn = kpl_arg_match_eval
- },
- {
- .match_str = "--io-queue-pow=",
- .help_message = "[NUMBER], Power of two for calculating the size of the io_uring queue",
- .arg_match_fn = kpl_arg_match_io_queue_pow
+ .match_str = "--io-queue-pow2=",
+ .help_message = "[NUMBER]; Power of 2 for calculating the size of the io_uring queue",
+ .arg_match_fn = kpl_arg_match_io_queue_pow2
},
{
.match_str = "--thread-count=",
- .help_message = "[NUMBER], Number of running threads, minimum is 1",
+ .help_message = "[NUMBER]; Number of running threads, minimum is 1",
.arg_match_fn = kpl_arg_match_thread_count
},
{
+ .match_str = "--memory-pool-pow2=",
+ .help_message = "[NUMBER1],[NUMBER2]; Set the memory pool [NUMBER1] to have 2 ** [NUMBER2] entires",
+ .arg_match_fn = kpl_arg_match_memory_pool_pow2
+ },
+ {
+ .match_str = "--code-queue-pow2=",
+ .help_message = "[NUMBER]; Power of 2 for calculating the size of the code queue",
+ .arg_match_fn = kpl_arg_match_code_queue_pow2
+ },
+ {
+ .match_str = "--eval",
+ .help_message = " [STRING...]; Evaluate next argument(s) as modules",
+ .arg_match_fn = kpl_arg_match_eval
+ },
+ {
.match_str = "--repl",
- .help_message = ", Start (R)ead, (E)valuate, (P)rint, (L)oop",
+ .help_message = "; Start (R)ead, (E)valuate, (P)rint, (L)oop",
.arg_match_fn = kpl_arg_match_repl
},
- { .match_str = "--help", .help_message = ", Show help", .arg_match_fn = kpl_arg_match_help },
+ {
+ .match_str = "--version",
+ .help_message = "; Show version",
+ .arg_match_fn = kpl_arg_match_version
+ },
+ {
+ .match_str = "--help",
+ .help_message = "; Show help",
+ .arg_match_fn = kpl_arg_match_help
+ },
{ .match_str = NULL, .help_message = NULL, .arg_match_fn = NULL }
};
static int32_t kpl_arg_match_help(const char *match_str, const int32_t match_str_index, kpl_config *config) {
(void) match_str;
(void) match_str_index;
+ kpl_arg_match_version(NULL, 0, config);
printf("\nUsage " KPL_COLOR(BOLD) "%s" KPL_COLOR(RESET) KPL_COLOR(WHITE) " [OPTIONS] [MODULE]" KPL_COLOR(RESET)
KPL_COLOR(BOLD) "%s\n\n" KPL_COLOR(RESET), config->argv[0], config->module_extension);
printf("Where " KPL_COLOR(WHITE) "[OPTIONS]" KPL_COLOR(RESET) " are:\n");