Add unit value to interpreter.
This commit is contained in:
@@ -2,8 +2,16 @@
|
||||
#include "util.h"
|
||||
#include "value.h"
|
||||
|
||||
void libab_interpreter_init(libab_interpreter* intr, libab* ab) {
|
||||
libab_result libab_interpreter_init(libab_interpreter* intr, libab* ab) {
|
||||
libab_result result;
|
||||
libab_ref unit_data;
|
||||
intr->ab = ab;
|
||||
|
||||
libab_ref_null(&unit_data);
|
||||
result = libab_create_value_ref(&intr->value_unit, &unit_data, &ab->type_unit);
|
||||
libab_ref_free(&unit_data);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
struct interpreter_state {
|
||||
@@ -844,4 +852,10 @@ libab_result libab_interpreter_run_function(libab_interpreter* intr,
|
||||
return result;
|
||||
}
|
||||
|
||||
void libab_interpreter_free(libab_interpreter* intr) {}
|
||||
void libab_interpreter_unit_value(libab_interpreter* intr, libab_ref* into) {
|
||||
libab_ref_copy(&intr->value_unit, into);
|
||||
}
|
||||
|
||||
void libab_interpreter_free(libab_interpreter* intr) {
|
||||
libab_ref_free(&intr->value_unit);
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ libab_result libab_init(libab* ab, void* (*parse_function)(const char*),
|
||||
void (*free_function)(void*)) {
|
||||
int parser_initialized = 0;
|
||||
int lexer_initialized = 0;
|
||||
int interpreter_initialized = 0;
|
||||
libab_ref null_ref;
|
||||
libab_result result;
|
||||
libab_ref_null(&null_ref);
|
||||
@@ -55,7 +56,11 @@ libab_result libab_init(libab* ab, void* (*parse_function)(const char*),
|
||||
if (result == LIBAB_SUCCESS) {
|
||||
parser_initialized = 1;
|
||||
libab_parser_init(&ab->parser, ab);
|
||||
libab_interpreter_init(&ab->intr, ab);
|
||||
result = libab_interpreter_init(&ab->intr, ab);
|
||||
}
|
||||
|
||||
if(result == LIBAB_SUCCESS) {
|
||||
interpreter_initialized = 1;
|
||||
result = libab_lexer_init(&ab->lexer);
|
||||
}
|
||||
|
||||
@@ -72,6 +77,9 @@ libab_result libab_init(libab* ab, void* (*parse_function)(const char*),
|
||||
|
||||
if (parser_initialized) {
|
||||
libab_parser_free(&ab->parser);
|
||||
}
|
||||
|
||||
if (interpreter_initialized) {
|
||||
libab_interpreter_free(&ab->intr);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user