Minor restructure for platformio compatibility

This commit is contained in:
2022-11-25 21:59:10 -05:00
parent 6cc27427cf
commit d965ca142d
8 changed files with 41 additions and 12 deletions

59
examples/repl/main.c Normal file
View File

@@ -0,0 +1,59 @@
#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;
}
}