Remove the implementation struct.

This commit is contained in:
Danila Fedorin 2018-04-24 16:34:10 -07:00
parent 735e8715a8
commit 14e9ddea23
5 changed files with 3 additions and 50 deletions

View File

@ -2,18 +2,16 @@
#define LIBABACUS_INTERPRETER_H
#include "table.h"
#include "number.h"
#include "tree.h"
struct libab_interpreter_s {
libab_ref base_table;
libab_number_impl* impl;
};
typedef struct libab_interpreter_s libab_interpreter;
void libab_interpreter_init(libab_interpreter* intr,
libab_ref* table, libab_number_impl* impl);
libab_ref* table);
libab_result libab_interpreter_run(libab_interpreter* intr,
libab_tree* tree, libab_ref* into);
void libab_interpreter_free(libab_interpreter* intr);

View File

@ -8,7 +8,6 @@
#include "interpreter.h"
#include "result.h"
#include "table.h"
#include "number.h"
/**
* The main struct of libabacus,
@ -36,10 +35,6 @@ struct libab_s {
* things like functions and operators.
*/
libab_ref table;
/**
* The number implementation used by this instance.
*/
libab_number_impl impl;
};
typedef struct libab_s libab;

View File

@ -1,37 +0,0 @@
#ifndef LIBABACUS_NUMBER_H
#define LIBABACUS_NUMBER_H
typedef void (*libab_num_function)(void*, void*, void*);
typedef void (*libab_num_function_unary)(void*, void*);
/**
* Struct that holds information
* about the implementation of numbers
* that is being used by libab. This is not
* assumed or inferred, and it's necessary to
* provide all of these definitions.
*/
struct libab_number_impl_s {
/**
* The function used to allocate a number.
*/
void* (*allocate)();
/**
* The function used to free a number.
*/
void (*free)(void*);
/**
* The function used to construct a number
* out of a string.
*/
void* (*parse)(const char*);
/**
* A function to copy the value of one number
* into the value of another.
*/
void (*copy)(void*, void*);
};
typedef struct libab_number_impl_s libab_number_impl;
#endif

View File

@ -2,20 +2,17 @@
#include "util.h"
void libab_interpreter_init(libab_interpreter* intr,
libab_ref* table, libab_number_impl* impl) {
libab_ref* table) {
libab_ref_copy(table, &intr->base_table);
intr->impl = impl;
}
struct interpreter_state {
libab_number_impl* impl;
libab_ref num_ref;
};
libab_result _interpreter_init(struct interpreter_state* state, libab_interpreter* intr) {
libab_result result = LIBAB_SUCCESS;
libab_basetype* num_type;
state->impl = intr->impl;
libab_ref_null(&state->num_ref);
num_type = libab_table_search_basetype(libab_ref_get(&intr->base_table), "num");

View File

@ -12,7 +12,7 @@ libab_result libab_init(libab* ab) {
if(result == LIBAB_SUCCESS) {
libab_parser_init(&ab->parser, &ab->table);
libab_interpreter_init(&ab->intr, &ab->table, &ab->impl);
libab_interpreter_init(&ab->intr, &ab->table);
result = libab_lexer_init(&ab->lexer);
}