Build a REPL for ucLISP
Still some rough edges
This commit is contained in:
@@ -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
|
||||
46
lib/README
46
lib/README
@@ -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 <Foo.h>
|
||||
#include <Bar.h>
|
||||
|
||||
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
|
||||
@@ -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
|
||||
|
||||
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