summaryrefslogtreecommitdiff
path: root/src/lib/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/main.c')
-rw-r--r--src/lib/main.c43
1 files changed, 40 insertions, 3 deletions
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);
+ }
+}