Skip to content

Commit e0c79ba

Browse files
committed
add spiffs support!
- configured as required - add SPIFFS directory - add lisp.hlp file - moved process_file - temporary disable *TR stuff, as symbol is required - "docs" function that types lisp.hlp - load works on ESP!
1 parent dfb25d7 commit e0c79ba

File tree

8 files changed

+124
-66
lines changed

8 files changed

+124
-66
lines changed

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
# Simple makefile for eps-lisp
22
PROGRAM=esp-lisp
3+
CFLAGS += -std=gnu99
4+
5+
# spiffs configuration
6+
EXTRA_COMPONENTS=extras/spiffs
7+
FLASH_SIZE=32
8+
SPIFFS_SINGLETON=1
9+
10+
SPIFFS_BASE_ADDR=0x200000
11+
12+
#SPIFFS_SIZE=0x100000 # 1MB
13+
SPIFFS_SIZE=0x10000 # 128K
14+
315
include ../esp-open-rtos/common.mk
416

17+
$(eval $(call make_spiffs_image,SPIFFS))

SPIFFS/lisp.hlp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
* ESP-LISP HELP *
2+
=================
3+
4+
help file for
5+
esp8266 lisp
6+
x

common.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1+
/* Distributed under Mozilla Public Licence 2.0 */
2+
/* https://www.mozilla.org/en-US/MPL/2.0/ */
3+
/* 2016-08-16 (C) Jonas S Karlsson, [email protected] */
4+
/* common code for all platforms */
5+
16
#include <string.h>
27
#include <stdio.h>
8+
#include <stdlib.h>
39
#include <errno.h>
410
#include <sys/types.h>
511
#include <netdb.h>
612
#include <unistd.h>
13+
#include <ctype.h>
714

815
#ifndef UNIX
916
#include "FreeRTOS.h"
@@ -317,3 +324,59 @@ int wget(wget_data* data, char* url, char* server) {
317324
return 0;
318325
}
319326

327+
int iscomment(char* s) {
328+
while (s && *s && isspace(*s++));
329+
return (s && *s == ';');
330+
}
331+
332+
// line is increased in increments of this
333+
#define MAXLINE 1024
334+
335+
int process_file(char* filename, process_input process) {
336+
FILE *file = fopen(filename, "r");
337+
if (!file) {
338+
perror(filename);
339+
return -1;
340+
}
341+
342+
char* input = calloc(MAXLINE, 1);
343+
int sz = 0;
344+
int len = 0;
345+
346+
char line[MAXLINE] = {0};
347+
int lineno = 0;
348+
int startno = 0;
349+
350+
int end = 0;
351+
do {
352+
// printf("%s.%d: %s", filename, lineno, line);
353+
354+
// chunk finished (non-empty line with some input)
355+
if (end || !isspace(line[0])) {
356+
process(input, filename, startno, lineno - 1);
357+
input[0] = 0;
358+
len = 0;
359+
startno = lineno;
360+
}
361+
362+
if (end) break;
363+
364+
// append line
365+
// TODO: move comment handling to reader!!!
366+
if (line[0] && !iscomment(line)) {
367+
if (sz < len + strlen(line) + 1) {
368+
sz += MAXLINE;
369+
input = realloc(input, sz);
370+
}
371+
strcat(input+len, line); // safe!
372+
len += strlen(line);
373+
}
374+
375+
end = !fgets(line, sizeof(line) - 1, file);
376+
lineno++;
377+
} while(1);
378+
379+
free(input);
380+
fclose(file);
381+
return 0;
382+
}

esplisp.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@
2626

2727
#include <esp/uart.h>
2828

29+
#include "esp_spiffs.h"
30+
#include "spiffs.h"
31+
2932
#include "lisp.h"
3033

34+
3135
int startTask, afterInit;
3236

3337
#include "compat.h"
@@ -249,6 +253,11 @@ void user_init(void) {
249253

250254
sdk_uart_div_modify(0, UART_CLK_FREQ / 115200);
251255

256+
// enable file system
257+
esp_spiffs_init();
258+
esp_spiffs_mount();
259+
260+
// disable buffering
252261
setbuf(stdin, NULL);
253262
setbuf(stdout, NULL);
254263

@@ -276,11 +285,6 @@ int closedir(DIR* dp) {
276285
return 0;
277286
}
278287

279-
int process_file(char* filename, process_input process) {
280-
error("process_file: not implemented!");
281-
return -1;
282-
}
283-
284288
void exit(int e) {
285289
printf("\n\n=============== EXIT=%d ===============\n", e);
286290
while(1);

init.lsp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
(princ "--- LOADING init.lsp FOR STARTUP ---")
2+
(terpri)
3+
14
;; init.lsp is loaded at startup, add stuff here
2-
(load "env.lsp")
5+
;; TODO: at the moment this is very important to load for the *TR?
6+
;(load "env.lsp")
37

48
;; enable to use "long words"
59
;(load "scheme.lsp")
10+
(princ "--- SUCCESSFULLY LOADED init.lsp ---")
11+
(terpri)
612

lisp.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,7 @@ inline lisp getBind(lisp* envp, lisp name, int create) {
13331333

13341334
// if we're at top level create a global binding and entry in the hashtable
13351335
if (create && envp == global_envp) return hashsym(name, NULL, 0, create);
1336-
// if (create) return nil;
1336+
if (create) return nil;
13371337

13381338
// first search local lexical env
13391339
lisp bind = assoc(name, *envp);
@@ -1356,6 +1356,7 @@ lisp getBind(lisp* envp, lisp name, int create);
13561356
// - if function return 0 directly still 5% overhead
13571357
// ==> other sourced of changes that slowed down... (like evallist)
13581358
static inline int tracep(lisp f) {
1359+
return 0;
13591360
static lisp vb = 0;
13601361
if (!vb && global_envp) vb = getBind(global_envp, symbol("*TR"), 0);
13611362
lisp x = cdr(vb);
@@ -2560,9 +2561,27 @@ PRIM load(lisp* envp, lisp name, lisp verbosity) {
25602561
}
25612562

25622563
int r = process_file(filename, evalIt);
2563-
return mkint(r);
2564+
return r ? nil : name;
25642565
}
25652566

2567+
PRIM docs() {
2568+
FILE* f = fopen("lisp.hlp", "r");
2569+
if (!f) {
2570+
perror("lisp.hlp");
2571+
return nil;
2572+
}
2573+
2574+
char line[257];
2575+
do {
2576+
if (!fgets(line, sizeof(line)-1, f)) break;
2577+
puts(line);
2578+
} while (1);
2579+
2580+
fclose(f);
2581+
return t;
2582+
}
2583+
2584+
25662585
PRIM directory(lisp name) {
25672586
DIR *dp;
25682587
struct dirent *ep;
@@ -3290,6 +3309,7 @@ lisp lisp_init() {
32903309

32913310
DEFPRIM(load, -3, load);
32923311
DEFPRIM(directory, 1, directory);
3312+
DEFPRIM(docs, 0, docs);
32933313

32943314
// debugging - http://www.gnu.org/software/mit-scheme/documentation/mit-scheme-user/Debugging-Aids.html
32953315
// http://www.gnu.org/software/mit-scheme/documentation/mit-scheme-user/Command_002dLine-Debugger.html#Command_002dLine-Debugger

lisp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ lisp quote(lisp x);
5555
lisp nil;
5656
lisp t;
5757
lisp LAMBDA;
58+
59+
// TODO: move out
5860
lisp _FREE_;
5961
lisp ATSYMBOL;
6062

tlisp.ccc

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* Distributed under Mozilla Public Licence 2.0 */
22
/* https://www.mozilla.org/en-US/MPL/2.0/ */
33
/* 2016-08-14 (C) Jonas S Karlsson, [email protected] */
4-
/* "test" driver for "unix" */
5-
/* provides alt implementations to esplisp.c */
4+
/* "test" driver for "unix" */
5+
/* provides alt implementations to esplisp.c */
66

77
#include <stdio.h>
88
#include <time.h>
@@ -136,62 +136,6 @@ int nonblock_getch() {
136136
return r;
137137
}
138138

139-
#define MAXLINE 1024
140-
141-
int iscomment(char* s) {
142-
while (s && *s && isspace(*s++));
143-
return (s && *s == ';');
144-
}
145-
146-
int process_file(char* filename, process_input process) {
147-
FILE *file = fopen(filename, "r");
148-
if (!file) {
149-
perror(filename);
150-
return -1;
151-
}
152-
153-
char* input = calloc(MAXLINE, 1);
154-
int sz = 0;
155-
int len = 0;
156-
157-
char line[MAXLINE] = {0};
158-
int lineno = 0;
159-
int startno = 0;
160-
161-
int end = 0;
162-
do {
163-
// printf("%s.%d: %s", filename, lineno, line);
164-
165-
// chunk finished (non-empty line with some input)
166-
if (end || !isspace(line[0])) {
167-
process(input, filename, startno, lineno - 1);
168-
input[0] = 0;
169-
len = 0;
170-
startno = lineno;
171-
}
172-
173-
if (end) break;
174-
175-
// append line
176-
// TODO: move comment handling to reader!!!
177-
if (line[0] && !iscomment(line)) {
178-
if (sz < len + strlen(line) + 1) {
179-
sz += 1024;
180-
input = realloc(input, sz);
181-
}
182-
strcat(input+len, line); // safe!
183-
len += strlen(line);
184-
}
185-
186-
end = !fgets(line, sizeof(line) - 1, file);
187-
lineno++;
188-
} while(1);
189-
190-
free(input);
191-
fclose(file);
192-
return 0;
193-
}
194-
195139
//////////////////////////////////////////////////////////////////////
196140
// simulate flash in RAM! (including EOR flash overwrite)
197141
// TODO: verify "correctness" compared to esp8266 truth, but works othewise

0 commit comments

Comments
 (0)