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.
33 lines
546 B
C
33 lines
546 B
C
#include "repl.h"
|
|
|
|
#include "evaluator.h"
|
|
#include "reader.h"
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
bool step_repl(repl_t *repl)
|
|
{
|
|
init_memory_pool(&repl->pool);
|
|
|
|
const int len = read_line(getchar, repl->buffer, REPL_BUFFER_SIZE);
|
|
if (len < 0)
|
|
return false;
|
|
const expression_t *e = read_expression(&repl->pool, repl->buffer, len);
|
|
if (NULL == e) {
|
|
puts("Invalid expression\n");
|
|
return true;
|
|
}
|
|
|
|
const int result = evaluate(e);
|
|
printf("%d\n", result);
|
|
|
|
return true;
|
|
}
|
|
|
|
void run_repl(repl_t *repl)
|
|
{
|
|
while (step_repl(repl))
|
|
;
|
|
}
|