Extract line reading logic to reader and remove REPL tests

Reading a line into the buffer was the only logic complex enough to be
worth testing really, and exposing the necessary parts of it to test
it effectively was a pain.  Makes more sense to move read_line out and
throw away most of the tests.
This commit is contained in:
2024-10-24 21:46:59 +01:00
parent ecd50c76c5
commit acb4cd38d7
9 changed files with 81 additions and 192 deletions

View File

@@ -3,6 +3,8 @@
#include "memory_pool.h"
int read_line(int (*get_byte)(void), char *buffer, int buffer_size);
const expression_t *
read_expression(memory_pool_t *pool, const char *input, int len);

View File

@@ -3,23 +3,11 @@
#include "memory_pool.h"
#define REPL_LINE_BUFFER_SIZE 128
#define REPL_RESULT_BUFFER_SIZE 128
typedef int (*get_byte_fn_t)(void);
typedef const expression_t *(*read_fn_t)(
memory_pool_t *pool, const char *input, int len);
typedef int (*evaluate_fn_t)(const expression_t *expression);
typedef void (*print_fn_t)(const char *output, int len);
#define REPL_BUFFER_SIZE 128
typedef struct {
get_byte_fn_t get_byte;
read_fn_t read;
evaluate_fn_t evaluate;
print_fn_t print;
memory_pool_t pool;
char line_buffer[REPL_LINE_BUFFER_SIZE];
char result_buffer[REPL_RESULT_BUFFER_SIZE];
char buffer[REPL_BUFFER_SIZE];
} repl_t;
bool step_repl(repl_t *repl);