60 lines
1.3 KiB
C
60 lines
1.3 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#ifndef NO_READLINE
|
|
#include <readline/readline.h>
|
|
#include <readline/history.h>
|
|
#endif
|
|
|
|
#include "uclisp.h"
|
|
|
|
// TODO: Make anything needed in this file public
|
|
#include "common.h"
|
|
#include "scope.h"
|
|
#include "special.h"
|
|
#include "builtins.h"
|
|
#include "memory.h"
|
|
|
|
int main(int argc, const char **argv) {
|
|
(void) argc, (void) argv;
|
|
|
|
struct ucl *ucl = ucl_create();
|
|
|
|
if (argc < 2) {
|
|
while (1) {
|
|
char *line = NULL;
|
|
#ifndef NO_READLINE
|
|
line = readline("> ");
|
|
if (line == NULL) {
|
|
break;
|
|
}
|
|
if (strlen(line) > 0) {
|
|
add_history(line);
|
|
}
|
|
#else
|
|
// TODO
|
|
#endif
|
|
struct ucl_object *sexp = ucl_parse(ucl, line);
|
|
struct ucl_object *result = NULL;
|
|
if (sexp->type == UCL_TYPE_ERROR) {
|
|
result = sexp;
|
|
} else {
|
|
result = ucl_evaluate(ucl, ucl_car(ucl, sexp));
|
|
}
|
|
ucl_print_obj(result);
|
|
printf("\n");
|
|
|
|
free(line);
|
|
ucl_gc(ucl);
|
|
}
|
|
} else {
|
|
struct ucl_object *sexp = ucl_parse(ucl, argv[1]);
|
|
struct ucl_object *result = ucl_evaluate(ucl, ucl_car(ucl, sexp));
|
|
|
|
ucl_print_obj(result);
|
|
printf("\n");
|
|
|
|
return 0;
|
|
}
|
|
}
|