1
- /* uLisp ESP Version 4.3 - www.ulisp.com
2
- David Johnson-Davies - www.technoblogy.com - 15th September 2022
1
+ /* uLisp ESP Version 4.3a - www.ulisp.com
2
+ David Johnson-Davies - www.technoblogy.com - 25th September 2022
3
3
4
4
Licensed under the MIT license: https://opensource.org/licenses/MIT
5
5
*/
@@ -173,6 +173,7 @@ Adafruit_SSD1306 tft(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire);
173
173
#define tstflag (x ) (Flags & 1 <<(x))
174
174
175
175
#define issp (x ) (x == ' ' || x == ' \n ' || x == ' \r ' || x == ' \t ' )
176
+ #define isbr (x ) (x == ' )' || x == ' (' || x == ' "' || x == ' #' )
176
177
#define longsymbolp (x ) (((x)->name & 0x03 ) == 0 )
177
178
#define twist (x ) ((uint32_t )((x)<<2 ) | (((x) & 0xC0000000 )>>30 ))
178
179
#define untwist (x ) (((x)>>2 & 0x3FFFFFFF ) | ((x) & 0x03 )<<30 )
@@ -634,11 +635,14 @@ unsigned int saveimage (object *arg) {
634
635
SD.begin (SDCARD_SS_PIN);
635
636
File file;
636
637
if (stringp (arg)) {
637
- file = SD.open (MakeFilename (arg), FILE_WRITE);
638
+ char buffer[BUFFERSIZE];
639
+ file = SD.open (MakeFilename (arg, buffer), FILE_WRITE);
640
+ if (!file) error2 (SAVEIMAGE, PSTR (" problem saving to SD card or invalid filename" ));
638
641
arg = NULL ;
639
- } else if (arg == NULL || listp (arg)) file = SD.open (" /ULISP.IMG" , FILE_WRITE);
640
- else error (SAVEIMAGE, PSTR (" illegal argument" ), arg);
641
- if (!file) error2 (SAVEIMAGE, PSTR (" problem saving to SD card" ));
642
+ } else if (arg == NULL || listp (arg)) {
643
+ file = SD.open (" /ULISP.IMG" , FILE_WRITE);
644
+ if (!file) error2 (SAVEIMAGE, PSTR (" problem saving to SD card" ));
645
+ } else error (SAVEIMAGE, invalidarg, arg);
642
646
SDWriteInt (file, (uintptr_t )arg);
643
647
SDWriteInt (file, imagesize);
644
648
SDWriteInt (file, (uintptr_t )GlobalEnv);
@@ -703,10 +707,14 @@ unsigned int loadimage (object *arg) {
703
707
#if defined(sdcardsupport)
704
708
SD.begin (SDCARD_SS_PIN);
705
709
File file;
706
- if (stringp (arg)) file = SD.open (MakeFilename (arg));
707
- else if (arg == NULL ) file = SD.open (" /ULISP.IMG" );
708
- else error (LOADIMAGE, PSTR (" illegal argument" ), arg);
709
- if (!file) error2 (LOADIMAGE, PSTR (" problem loading from SD card" ));
710
+ if (stringp (arg)) {
711
+ char buffer[BUFFERSIZE];
712
+ file = SD.open (MakeFilename (arg, buffer));
713
+ if (!file) error2 (LOADIMAGE, PSTR (" problem loading from SD card or invalid filename" ));
714
+ } else if (arg == NULL ) {
715
+ file = SD.open (" /ULISP.IMG" );
716
+ if (!file) error2 (LOADIMAGE, PSTR (" problem loading from SD card" ));
717
+ } else error (LOADIMAGE, invalidarg, arg);
710
718
SDReadInt (file);
711
719
unsigned int imagesize = SDReadInt (file);
712
720
GlobalEnv = (object *)SDReadInt (file);
@@ -1200,7 +1208,7 @@ object *readbitarray (gfun_t gfun) {
1200
1208
char ch = gfun ();
1201
1209
object *head = NULL ;
1202
1210
object *tail = NULL ;
1203
- while (!issp (ch) && ch != ' ) ' && ch != ' ( ' ) {
1211
+ while (!issp (ch) && ! isbr (ch) ) {
1204
1212
if (ch != ' 0' && ch != ' 1' ) error2 (NIL, PSTR (" illegal character in bit array" ));
1205
1213
object *cell = cons (number (ch - ' 0' ), NULL );
1206
1214
if (head == NULL ) head = cell;
@@ -1210,7 +1218,7 @@ object *readbitarray (gfun_t gfun) {
1210
1218
}
1211
1219
LastChar = ch;
1212
1220
int size = listlength (NIL, head);
1213
- object *array = makearray (NIL , cons (number (size), NULL ), 0 , true );
1221
+ object *array = makearray (MAKEARRAY , cons (number (size), NULL ), number ( 0 ) , true );
1214
1222
size = (size + sizeof (int )*8 - 1 )/(sizeof (int )*8 );
1215
1223
int index = 0 ;
1216
1224
while (head != NULL ) {
@@ -1419,7 +1427,7 @@ char *cstring (builtin_t name, object *form, char *buffer, int buflen) {
1419
1427
return buffer;
1420
1428
}
1421
1429
1422
- IPAddress ipstring (builtin_t name, object *form) {
1430
+ uint32_t ipstring (builtin_t name, object *form) {
1423
1431
form = cdr (checkstring (name, form));
1424
1432
int p = 0 ;
1425
1433
union { uint32_t ipaddress; uint8_t ipbytes[4 ]; } ;
@@ -2379,9 +2387,12 @@ object *sp_withspi (object *args, object *env) {
2379
2387
object *sp_withsdcard (object *args, object *env) {
2380
2388
#if defined(sdcardsupport)
2381
2389
object *params = first (args);
2390
+ if (params == NULL ) error2 (WITHSDCARD, nostream);
2382
2391
object *var = first (params);
2383
- object *filename = eval (second (params), env);
2384
- params = cddr (params);
2392
+ params = cdr (params);
2393
+ if (params == NULL ) error2 (WITHSDCARD, PSTR (" no filename specified" ));
2394
+ object *filename = eval (first (params), env);
2395
+ params = cdr (params);
2385
2396
SD.begin ();
2386
2397
int mode = 0 ;
2387
2398
if (params != NULL && first (params) != NULL ) mode = checkinteger (WITHSDCARD, first (params));
@@ -3395,7 +3406,9 @@ object *fn_readfromstring (object *args, object *env) {
3395
3406
object *arg = checkstring (READFROMSTRING, first (args));
3396
3407
GlobalString = arg;
3397
3408
GlobalStringIndex = 0 ;
3398
- return read (gstr);
3409
+ object *val = read (gstr);
3410
+ LastChar = 0 ;
3411
+ return val;
3399
3412
}
3400
3413
3401
3414
object *fn_princtostring (object *args, object *env) {
@@ -3822,7 +3835,7 @@ object *fn_format (object *args, object *env) {
3822
3835
int len = stringlength (formatstr);
3823
3836
uint8_t n = 0 , width = 0 , w, bra = 0 ;
3824
3837
char pad = ' ' ;
3825
- bool tilde = false , mute = false , comma, quote;
3838
+ bool tilde = false , mute = false , comma = false , quote = false ;
3826
3839
while (n < len) {
3827
3840
char ch = nthchar (formatstr, n);
3828
3841
char ch2 = ch & ~0x20 ; // force to upper case
@@ -4904,7 +4917,7 @@ const char doc191[] PROGMEM = "(pprint item [str])\n"
4904
4917
" If str is specified it prints to the specified stream. It returns no value." ;
4905
4918
const char doc192[] PROGMEM = " (pprintall [str])\n "
4906
4919
" Pretty-prints the definition of every function and variable defined in the uLisp workspace.\n "
4907
- " Is str is specified it prints to the specified stream. It returns no value." ;
4920
+ " If str is specified it prints to the specified stream. It returns no value." ;
4908
4921
const char doc193[] PROGMEM = " (format output controlstring arguments*)\n "
4909
4922
" Outputs its arguments formatted according to the format directives in controlstring." ;
4910
4923
const char doc194[] PROGMEM = " (require 'symbol)\n "
@@ -5802,7 +5815,7 @@ object *nextitem (gfun_t gfun) {
5802
5815
char ch2 = ch & ~0x20 ; // force to upper case
5803
5816
if (ch == ' \\ ' ) { // Character
5804
5817
base = 0 ; ch = gfun ();
5805
- if (issp (ch) || ch == ' ) ' || ch == ' ( ' ) return character (ch);
5818
+ if (issp (ch) || isbr (ch) ) return character (ch);
5806
5819
else LastChar = ch;
5807
5820
} else if (ch == ' |' ) {
5808
5821
do { while (gfun () != ' |' ); }
@@ -5831,7 +5844,7 @@ object *nextitem (gfun_t gfun) {
5831
5844
buffer[2 ] = ' \0 ' ; buffer[3 ] = ' \0 ' ; buffer[4 ] = ' \0 ' ; buffer[5 ] = ' \0 ' ; // In case symbol is < 5 letters
5832
5845
float divisor = 10.0 ;
5833
5846
5834
- while (!issp (ch) && ch != ' ) ' && ch != ' ( ' && index < bufmax) {
5847
+ while (!issp (ch) && ! isbr (ch) && index < bufmax) {
5835
5848
buffer[index ++] = ch;
5836
5849
if (base == 10 && ch == ' .' && !isexponent) {
5837
5850
isfloat = true ;
@@ -5859,7 +5872,7 @@ object *nextitem (gfun_t gfun) {
5859
5872
}
5860
5873
5861
5874
buffer[index ] = ' \0 ' ;
5862
- if (ch == ' ) ' || ch == ' ( ' ) LastChar = ch;
5875
+ if (isbr (ch) ) LastChar = ch;
5863
5876
if (isfloat && valid == 1 ) return makefloat (fresult * sign * pow (10 , exponent * esign));
5864
5877
else if (valid == 1 ) {
5865
5878
if (base == 10 && result > ((unsigned int )INT_MAX+(1 -sign)/2 ))
@@ -5942,7 +5955,7 @@ void setup () {
5942
5955
initenv ();
5943
5956
initsleep ();
5944
5957
initgfx ();
5945
- pfstring (PSTR (" uLisp 4.3 " ), pserial); pln (pserial);
5958
+ pfstring (PSTR (" uLisp 4.3a " ), pserial); pln (pserial);
5946
5959
}
5947
5960
5948
5961
// Read/Evaluate/Print loop
@@ -5994,4 +6007,4 @@ void loop () {
5994
6007
#endif
5995
6008
client.stop ();
5996
6009
repl (NULL );
5997
- }
6010
+ }
0 commit comments