From fe4e42411c6a65fa5430fb017cf3afed734b8027 Mon Sep 17 00:00:00 2001 From: Max Regan Date: Fri, 25 Nov 2022 22:18:25 -0500 Subject: [PATCH] Build a REPL for ucLISP Still some rough edges --- include/README | 39 ----------------------------------- lib/README | 46 ----------------------------------------- platformio.ini | 52 +++++++++++++++++++++++++++++++++++++++++++++++ src/main.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 107 insertions(+), 85 deletions(-) delete mode 100644 include/README delete mode 100644 lib/README create mode 100644 src/main.c diff --git a/include/README b/include/README deleted file mode 100644 index 194dcd4..0000000 --- a/include/README +++ /dev/null @@ -1,39 +0,0 @@ - -This directory is intended for project header files. - -A header file is a file containing C declarations and macro definitions -to be shared between several project source files. You request the use of a -header file in your project source file (C, C++, etc) located in `src` folder -by including it, with the C preprocessing directive `#include'. - -```src/main.c - -#include "header.h" - -int main (void) -{ - ... -} -``` - -Including a header file produces the same results as copying the header file -into each source file that needs it. Such copying would be time-consuming -and error-prone. With a header file, the related declarations appear -in only one place. If they need to be changed, they can be changed in one -place, and programs that include the header file will automatically use the -new version when next recompiled. The header file eliminates the labor of -finding and changing all the copies as well as the risk that a failure to -find one copy will result in inconsistencies within a program. - -In C, the usual convention is to give header files names that end with `.h'. -It is most portable to use only letters, digits, dashes, and underscores in -header file names, and at most one dot. - -Read more about using header files in official GCC documentation: - -* Include Syntax -* Include Operation -* Once-Only Headers -* Computed Includes - -https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/lib/README b/lib/README deleted file mode 100644 index 6debab1..0000000 --- a/lib/README +++ /dev/null @@ -1,46 +0,0 @@ - -This directory is intended for project specific (private) libraries. -PlatformIO will compile them to static libraries and link into executable file. - -The source code of each library should be placed in a an own separate directory -("lib/your_library_name/[here are source files]"). - -For example, see a structure of the following two libraries `Foo` and `Bar`: - -|--lib -| | -| |--Bar -| | |--docs -| | |--examples -| | |--src -| | |- Bar.c -| | |- Bar.h -| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html -| | -| |--Foo -| | |- Foo.c -| | |- Foo.h -| | -| |- README --> THIS FILE -| -|- platformio.ini -|--src - |- main.c - -and a contents of `src/main.c`: -``` -#include -#include - -int main (void) -{ - ... -} - -``` - -PlatformIO Library Dependency Finder will find automatically dependent -libraries scanning project source files. - -More information about PlatformIO Library Dependency Finder -- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/platformio.ini b/platformio.ini index ebc510b..02998b5 100644 --- a/platformio.ini +++ b/platformio.ini @@ -7,3 +7,55 @@ ; ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html + +[env] +;; TODO: Make uclisp to a remote git repo +lib_deps = ../uclisp/ + +[common] +build_flags = + -Wall + -Werror + -Wextra + ;;-Wpedantic + -D NO_READLINE +release_build_flags = + -O2 + -flto +debug_build_flags = + -ggdb + -O0 + + +[env:pico-debug] +platform = https://github.com/Wiz-IO/wizio-pico.git +framework = baremetal +board = raspberry-pi-pico +build_flags = + ${common.build_flags} + ${common.debug_build_flags} + -D PLATFORM_PICO_SDK + -D LIB_PICO_STDIO_USB + -D PICO_USB + +upload_protocol = uf2 +upload_port = /run/media/max/RPI-RP2 +lib_deps = /home/max/repos/uclisp/ + +[env:native-debug] +platform = native +build_flags = + ${common.build_flags} + ${common.debug_build_flags} + -D PLATFORM_NATIVE + +[env:native-release] +platform = native +build_flags = + ${common.build_flags} + ${common.release_build_flags} + -D PLATFORM_NATIVE + + +;monitor_port = SELECT SERIAL PORT +;monitor_speed = 115200 diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..cd6b649 --- /dev/null +++ b/src/main.c @@ -0,0 +1,55 @@ +#include +#include + +#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; +}