Build a REPL for ucLISP
Still some rough edges
This commit is contained in:
55
src/main.c
Normal file
55
src/main.c
Normal file
@@ -0,0 +1,55 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "uclisp.h"
|
||||
#include "types.h"
|
||||
|
||||
#ifdef PLATFORM_PICO_SDK
|
||||
#include "pico/stdio.h"
|
||||
#include "pico/stdlib.h"
|
||||
#endif
|
||||
|
||||
struct ucl *ucl;
|
||||
|
||||
// TODO: Get these from a header
|
||||
struct ucl_object *ucl_car(struct ucl*, struct ucl_object *);
|
||||
void ucl_print_obj(struct ucl_object *);
|
||||
|
||||
int main() {
|
||||
|
||||
#ifdef PLATFORM_PICO_SDK
|
||||
stdio_usb_init();
|
||||
gpio_init(PICO_DEFAULT_LED_PIN);
|
||||
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
|
||||
bool gpio_state = false;
|
||||
#endif
|
||||
|
||||
ucl = ucl_create();
|
||||
|
||||
while(1) {
|
||||
#ifdef PLATFORM_PICO_SDK
|
||||
gpio_put(PICO_DEFAULT_LED_PIN, gpio_state);
|
||||
gpio_state = !gpio_state;
|
||||
#endif
|
||||
|
||||
// TODO: Work out input for pico
|
||||
size_t line_len = 512;
|
||||
char *line = NULL;
|
||||
printf("> ");
|
||||
getline(&line, &line_len, stdin);
|
||||
|
||||
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");
|
||||
ucl_gc(ucl);
|
||||
free(line);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user