From 86a65e695b9dc1fb7a20094204339f5bf168fb92 Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 25 Aug 2026 20:56:55 +0000 Subject: Start working on modules, including a built-in "boot" module FossilOrigin-Name: 4829dbeb2071fe0be41ded66a61ba2e156119a47def8a23415b8227a00d53ce7 --- src/lib/main.c | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) (limited to 'src/lib/main.c') diff --git a/src/lib/main.c b/src/lib/main.c index e9d33cb..ae17f34 100644 --- a/src/lib/main.c +++ b/src/lib/main.c @@ -1,4 +1,5 @@ #include "aplwc_internal.h" +#include "boot.h" enum aplwc_rc aplwc_new(struct aplwc **p, uint8_t *data, size_t size) @@ -12,7 +13,7 @@ aplwc_new(struct aplwc **p, uint8_t *data, size_t size) return APLWC_OUT_OF_MEMORY; (*p)->memory = m; - return APLWC_OK; + return aplwc_load_module(*p, "Boot", (const char *)boot_src, boot_src_len); } void @@ -70,11 +71,11 @@ aplwc_read(struct aplwc *aplwc, const char *line) struct token_list *tokens; struct aplwc_line *ret; - text = chars_to_string(aplwc, line); + text = chars_to_string(aplwc, line, -1); if(text == NULL) return NULL; - tokens = scan_line(aplwc, text); + tokens = scan_string(aplwc, text, 1); if(tokens == NULL) return NULL; @@ -124,3 +125,39 @@ aplwc_value_string(struct aplwc_value *value) return "???"; } } + +enum aplwc_rc +aplwc_load_module(struct aplwc *aplwc, const char *name, const char *src, int srclen) +{ + struct string *text, *namestr; + struct token_list *tokens; + + namestr = NULL; + text = NULL; + tokens = NULL; + + namestr = chars_to_string(aplwc, name, -1); + if(namestr == NULL) + goto error; + + text = chars_to_string(aplwc, src, srclen); + if(text == NULL) + goto error; + + tokens = scan_string(aplwc, text, 0); + if(tokens == NULL) + goto error; + + if(load_module(aplwc, namestr, tokens) == APLWC_OK) + return APLWC_OK; + else{ +error: + if(tokens != NULL) + memory_free_token_list(&aplwc->memory, tokens); + if(text != NULL) + memory_free_string(&aplwc->memory, text); + if(namestr != NULL) + memory_free_string(&aplwc->memory, namestr); + return aplwc_last_error(aplwc); + } +} -- cgit v1.2.3