Release 4.7b - 20th March 2025

This commit is contained in:
David Johnson-Davies 2025-03-20 16:56:10 +00:00 committed by GitHub
parent 1023816f9f
commit 75b2785b5a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 99 additions and 51 deletions

View File

@ -1,5 +1,5 @@
/* uLisp ARM Release 4.7 - www.ulisp.com /* uLisp ARM Release 4.7b - www.ulisp.com
David Johnson-Davies - www.technoblogy.com - 3rd November 2024 David Johnson-Davies - www.technoblogy.com - 20th March 2025
Licensed under the MIT license: https://opensource.org/licenses/MIT Licensed under the MIT license: https://opensource.org/licenses/MIT
*/ */
@ -79,7 +79,7 @@ const char LispLibrary[] = "";
#define CPU_ATSAMD21 #define CPU_ATSAMD21
#elif defined(ARDUINO_SAMD_ZERO) /* Put this last, otherwise overrides the Adafruit boards */ #elif defined(ARDUINO_SAMD_ZERO) /* Put this last, otherwise overrides the Adafruit boards */
#define WORKSPACESIZE (2640-SDSIZE) /* Objects (8*bytes) */ #define WORKSPACESIZE (2500-SDSIZE) /* Objects (8*bytes) */
#define CPUFLASH #define CPUFLASH
#define FLASHSIZE 32768 /* Bytes */ #define FLASHSIZE 32768 /* Bytes */
#define CODESIZE 128 /* Bytes */ #define CODESIZE 128 /* Bytes */
@ -241,7 +241,7 @@ const char LispLibrary[] = "";
#define CPU_RP2040 #define CPU_RP2040
#elif defined(ARDUINO_RASPBERRY_PI_PICO_W) #elif defined(ARDUINO_RASPBERRY_PI_PICO_W)
#define WORKSPACESIZE (15536-SDSIZE) /* Objects (8*bytes) */ #define WORKSPACESIZE (15232-SDSIZE) /* Objects (8*bytes) */
#define CODESIZE 256 /* Bytes */ #define CODESIZE 256 /* Bytes */
#define STACKDIFF 480 #define STACKDIFF 480
#define LITTLEFS #define LITTLEFS
@ -268,6 +268,22 @@ const char LispLibrary[] = "";
#define FS_FILE_READ "r" #define FS_FILE_READ "r"
#define CPU_RP2350 #define CPU_RP2350
#elif defined(ARDUINO_RASPBERRY_PI_PICO_2W)
#if defined(__riscv)
#define WORKSPACESIZE (34850-SDSIZE) /* Objects (8*bytes) */
#define STACKDIFF 580
#else
#define WORKSPACESIZE (39200-SDSIZE) /* Objects (8*bytes) */
#define STACKDIFF 520
#endif
#define CODESIZE 256 /* Bytes */
#define LITTLEFS
#include <WiFi.h>
#include <LittleFS.h>
#define FS_FILE_WRITE "w"
#define FS_FILE_READ "r"
#define CPU_RP2350
#elif defined(ARDUINO_PIMORONI_PICO_PLUS_2) #elif defined(ARDUINO_PIMORONI_PICO_PLUS_2)
//#define BOARD_HAS_PSRAM /* Uncomment to use PSRAM */ //#define BOARD_HAS_PSRAM /* Uncomment to use PSRAM */
#if defined(BOARD_HAS_PSRAM) #if defined(BOARD_HAS_PSRAM)
@ -2802,26 +2818,29 @@ void I2Cstop (TwoWire *port, uint8_t read) {
|| defined(ARDUINO_PYBADGE_M4) || defined(ARDUINO_PYGAMER_M4) || defined(ARDUINO_TEENSY40) \ || defined(ARDUINO_PYBADGE_M4) || defined(ARDUINO_PYGAMER_M4) || defined(ARDUINO_TEENSY40) \
|| defined(ARDUINO_TEENSY41) || defined(ARDUINO_RASPBERRY_PI_PICO) \ || defined(ARDUINO_TEENSY41) || defined(ARDUINO_RASPBERRY_PI_PICO) \
|| defined(ARDUINO_RASPBERRY_PI_PICO_W) || defined(ARDUINO_RASPBERRY_PI_PICO_2) \ || defined(ARDUINO_RASPBERRY_PI_PICO_W) || defined(ARDUINO_RASPBERRY_PI_PICO_2) \
|| defined(ARDUINO_PIMORONI_PICO_PLUS_2) || defined(ARDUINO_RASPBERRY_PI_PICO_2W) || defined(ARDUINO_PIMORONI_PICO_PLUS_2)
#define ULISP_SPI1 #define ULISP_SPI1
#endif #endif
#if defined(ARDUINO_WIO_TERMINAL) || defined(ARDUINO_BBC_MICROBIT_V2) \ #if defined(ARDUINO_WIO_TERMINAL) || defined(ARDUINO_BBC_MICROBIT_V2) \
|| defined(ARDUINO_TEENSY40) || defined(ARDUINO_TEENSY41) || defined(MAX32620) \ || defined(ARDUINO_TEENSY40) || defined(ARDUINO_TEENSY41) || defined(MAX32620) \
|| defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_RASPBERRY_PI_PICO_W) \ || defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_RASPBERRY_PI_PICO_W) \
|| defined(ARDUINO_ADAFRUIT_QTPY_RP2040) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) \ || defined(ARDUINO_ADAFRUIT_QTPY_RP2040) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) \
|| defined(ARDUINO_RASPBERRY_PI_PICO_2) || defined(ARDUINO_PIMORONI_PICO_PLUS_2) \ || defined(ARDUINO_RASPBERRY_PI_PICO_2) || defined(ARDUINO_RASPBERRY_PI_PICO_2W) \
|| defined(ARDUINO_GRAND_CENTRAL_M4) || defined(ARDUINO_NRF52840_CIRCUITPLAY) || defined(ARDUINO_PIMORONI_PICO_PLUS_2) || defined(ARDUINO_GRAND_CENTRAL_M4) \
|| defined(ARDUINO_NRF52840_CIRCUITPLAY)
#define ULISP_I2C1 #define ULISP_I2C1
#endif #endif
#if defined(ARDUINO_SAM_DUE) || defined(ARDUINO_TEENSY40) || defined(ARDUINO_TEENSY41) #if defined(ARDUINO_SAM_DUE) || defined(ARDUINO_TEENSY40) || defined(ARDUINO_TEENSY41)
#define ULISP_SERIAL3 #define ULISP_SERIAL3
#elif defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_RASPBERRY_PI_PICO_W) \ #elif defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_RASPBERRY_PI_PICO_W) \
|| defined(ARDUINO_RASPBERRY_PI_PICO_2) || defined(ARDUINO_PIMORONI_PICO_PLUS_2) || defined(ARDUINO_RASPBERRY_PI_PICO_2) || defined(ARDUINO_RASPBERRY_PI_PICO_2W) \
|| defined(ARDUINO_PIMORONI_PICO_PLUS_2)
#define ULISP_SERIAL2 #define ULISP_SERIAL2
#elif !defined(CPU_NRF51822) && !defined(CPU_NRF52833) && !defined(ARDUINO_FEATHER_F405) #elif !defined(CPU_NRF51822) && !defined(CPU_NRF52833) && !defined(ARDUINO_FEATHER_F405)
#define ULISP_SERIAL1 #define ULISP_SERIAL1
#endif #endif
#if defined(ARDUINO_RASPBERRY_PI_PICO_W) || defined(ARDUINO_UNOWIFIR4) #if defined(ARDUINO_RASPBERRY_PI_PICO_W) || defined(ARDUINO_RASPBERRY_PI_PICO_2W) \
|| defined(ARDUINO_UNOWIFIR4)
#define ULISP_WIFI #define ULISP_WIFI
#endif #endif
@ -3073,7 +3092,8 @@ void checkanalogread (int pin) {
#elif defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_RASPBERRY_PI_PICO_W) \ #elif defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_RASPBERRY_PI_PICO_W) \
|| defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040_ADALOGGER) \ || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040_ADALOGGER) \
|| defined(ARDUINO_ADAFRUIT_QTPY_RP2040) || defined(ARDUINO_SEEED_XIAO_RP2040) \ || defined(ARDUINO_ADAFRUIT_QTPY_RP2040) || defined(ARDUINO_SEEED_XIAO_RP2040) \
|| defined(ARDUINO_RASPBERRY_PI_PICO_2) || defined(ARDUINO_PIMORONI_PICO_PLUS_2) || defined(ARDUINO_RASPBERRY_PI_PICO_2) || defined(ARDUINO_RASPBERRY_PI_PICO_2W) \
|| defined(ARDUINO_PIMORONI_PICO_PLUS_2)
if (!(pin>=26 && pin<=29)) error(invalidpin, number(pin)); if (!(pin>=26 && pin<=29)) error(invalidpin, number(pin));
#elif defined(ARDUINO_MINIMA) || defined(ARDUINO_UNOWIFIR4) #elif defined(ARDUINO_MINIMA) || defined(ARDUINO_UNOWIFIR4)
if (!((pin>=14 && pin<=21))) error(invalidpin, number(pin)); if (!((pin>=14 && pin<=21))) error(invalidpin, number(pin));
@ -3132,7 +3152,7 @@ void checkanalogwrite (int pin) {
|| defined(ARDUINO_SEEED_XIAO_RP2040) || defined(ARDUINO_RASPBERRY_PI_PICO_2) \ || defined(ARDUINO_SEEED_XIAO_RP2040) || defined(ARDUINO_RASPBERRY_PI_PICO_2) \
|| defined(ARDUINO_PIMORONI_PICO_PLUS_2) || defined(ARDUINO_PIMORONI_PICO_PLUS_2)
if (!(pin>=0 && pin<=29)) error(invalidpin, number(pin)); if (!(pin>=0 && pin<=29)) error(invalidpin, number(pin));
#elif defined(ARDUINO_RASPBERRY_PI_PICO_W) #elif defined(ARDUINO_RASPBERRY_PI_PICO_W) || defined(ARDUINO_RASPBERRY_PI_PICO_2W)
if (!((pin>=0 && pin<=29) || pin == 32)) error(invalidpin, number(pin)); if (!((pin>=0 && pin<=29) || pin == 32)) error(invalidpin, number(pin));
#elif defined(ARDUINO_MINIMA) || defined(ARDUINO_UNOWIFIR4) #elif defined(ARDUINO_MINIMA) || defined(ARDUINO_UNOWIFIR4)
if (!((pin>=0 && pin<=21))) error(invalidpin, number(pin)); if (!((pin>=0 && pin<=21))) error(invalidpin, number(pin));
@ -3147,9 +3167,9 @@ void playnote (int pin, int note, int octave) {
#if defined(ARDUINO_NRF52840_CLUE) || defined(ARDUINO_NRF52840_CIRCUITPLAY) \ #if defined(ARDUINO_NRF52840_CLUE) || defined(ARDUINO_NRF52840_CIRCUITPLAY) \
|| defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_RASPBERRY_PI_PICO_W) \ || defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_RASPBERRY_PI_PICO_W) \
|| defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040_ADALOGGER) \ || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040_ADALOGGER) \
|| defined(ARDUINO_ADAFRUIT_QTPY_RP2040) || defined(ARDUINO_WIO_TERMINAL) \ || defined(ARDUINO_ADAFRUIT_QTPY_RP2040) || defined(ARDUINO_SEEED_XIAO_RP2040) \
|| defined(ARDUINO_SEEED_XIAO_RP2040) || defined(ARDUINO_RASPBERRY_PI_PICO_2) \ || defined(ARDUINO_RASPBERRY_PI_PICO_2) || defined(ARDUINO_RASPBERRY_PI_PICO_2W) \
|| defined(ARDUINO_PIMORONI_PICO_PLUS_2) || defined(ARDUINO_PIMORONI_PICO_PLUS_2) || defined(ARDUINO_WIO_TERMINAL)
int oct = octave + note/12; int oct = octave + note/12;
int prescaler = 8 - oct; int prescaler = 8 - oct;
if (prescaler<0 || prescaler>8) error("octave out of range", number(oct)); if (prescaler<0 || prescaler>8) error("octave out of range", number(oct));
@ -3162,10 +3182,10 @@ void playnote (int pin, int note, int octave) {
void nonote (int pin) { void nonote (int pin) {
#if defined(ARDUINO_NRF52840_CLUE) || defined(ARDUINO_NRF52840_CIRCUITPLAY) \ #if defined(ARDUINO_NRF52840_CLUE) || defined(ARDUINO_NRF52840_CIRCUITPLAY) \
|| defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_RASPBERRY_PI_PICO_W) \ || defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_RASPBERRY_PI_PICO_W) \
|| defined(ARDUINO_RASPBERRY_PI_PICO_2) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) \ || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040_ADALOGGER) \
|| defined(ARDUINO_ADAFRUIT_FEATHER_RP2040_ADALOGGER) || defined(ARDUINO_ADAFRUIT_QTPY_RP2040) \ || defined(ARDUINO_ADAFRUIT_QTPY_RP2040) || defined(ARDUINO_SEEED_XIAO_RP2040) \
|| defined(ARDUINO_WIO_TERMINAL) || defined(ARDUINO_SEEED_XIAO_RP2040) \ || defined(ARDUINO_RASPBERRY_PI_PICO_2) || defined(ARDUINO_RASPBERRY_PI_PICO_2W) \
|| defined(ARDUINO_PIMORONI_PICO_PLUS_2) || defined(ARDUINO_PIMORONI_PICO_PLUS_2) || defined(ARDUINO_WIO_TERMINAL)
noTone(pin); noTone(pin);
#else #else
(void) pin; (void) pin;
@ -4533,8 +4553,8 @@ object *fn_copylist (object *args, object *env) {
if (!listp(arg)) error(notalist, arg); if (!listp(arg)) error(notalist, arg);
object *result = cons(NULL, NULL); object *result = cons(NULL, NULL);
object *ptr = result; object *ptr = result;
while (arg != NULL) { while (consp(arg)) {
cdr(ptr) = cons(car(arg), NULL); cdr(ptr) = cons(car(arg), cdr(arg));
ptr = cdr(ptr); arg = cdr(arg); ptr = cdr(ptr); arg = cdr(arg);
} }
return cdr(result); return cdr(result);
@ -5480,8 +5500,10 @@ object *fn_stringgreatereq (object *args, object *env) {
Destructively sorts list according to the test function, using an insertion sort, and returns the sorted list. Destructively sorts list according to the test function, using an insertion sort, and returns the sorted list.
*/ */
object *fn_sort (object *args, object *env) { object *fn_sort (object *args, object *env) {
if (first(args) == NULL) return nil; object *arg = first(args);
object *list = cons(nil,first(args)); if (!listp(arg)) error(notalist, arg);
if (arg == NULL) return nil;
object *list = cons(nil, arg);
protect(list); protect(list);
object *predicate = second(args); object *predicate = second(args);
object *compare = cons(NULL, cons(NULL, NULL)); object *compare = cons(NULL, cons(NULL, NULL));
@ -5894,10 +5916,13 @@ object *fn_readline (object *args, object *env) {
(write-byte number [stream]) (write-byte number [stream])
Writes a byte to a stream. Writes a byte to a stream.
*/ */
inline void serialwrite (char c) { Serial.write(c); }
object *fn_writebyte (object *args, object *env) { object *fn_writebyte (object *args, object *env) {
(void) env; (void) env;
int value = checkinteger(first(args)); int value = checkinteger(first(args));
pfun_t pfun = pstreamfun(cdr(args)); pfun_t pfun = pstreamfun(cdr(args));
if (pfun == pserial) pfun = serialwrite;
(pfun)(value); (pfun)(value);
return nil; return nil;
} }
@ -6112,10 +6137,11 @@ object *fn_analogreference (object *args, object *env) {
object *arg = first(args); object *arg = first(args);
#if defined(ARDUINO_TEENSY40) || defined(ARDUINO_TEENSY41) || defined(MAX32620) \ #if defined(ARDUINO_TEENSY40) || defined(ARDUINO_TEENSY41) || defined(MAX32620) \
|| defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_RASPBERRY_PI_PICO_W) \ || defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_RASPBERRY_PI_PICO_W) \
|| defined(ARDUINO_RASPBERRY_PI_PICO_2) || defined(ARDUINO_PIMORONI_PICO_PLUS_2) \ || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040_ADALOGGER) \
|| defined(ARDUINO_PIMORONI_TINY2350) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) \ || defined(ARDUINO_ADAFRUIT_QTPY_RP2040) || defined(ARDUINO_SEEED_XIAO_RP2040) \
|| defined(ARDUINO_ADAFRUIT_QTPY_RP2040) || defined(ARDUINO_NANO_MATTER) \ || defined(ARDUINO_RASPBERRY_PI_PICO_2) || defined(ARDUINO_RASPBERRY_PI_PICO_2W) \
|| defined(ARDUINO_ADAFRUIT_FEATHER_RP2040_ADALOGGER) || defined(ARDUINO_PIMORONI_PICO_PLUS_2) || defined(ARDUINO_PIMORONI_TINY2350) \
|| defined(ARDUINO_NANO_MATTER)
error2("not supported"); error2("not supported");
#else #else
analogReference((eAnalogReference)checkkeyword(arg)); analogReference((eAnalogReference)checkkeyword(arg));
@ -6325,7 +6351,7 @@ object *fn_format (object *args, object *env) {
object *save = NULL; object *save = NULL;
args = cddr(args); args = cddr(args);
int len = stringlength(formatstr); int len = stringlength(formatstr);
uint8_t n = 0, width = 0, w, bra = 0; uint16_t n = 0, width = 0, w, bra = 0;
char pad = ' '; char pad = ' ';
bool tilde = false, mute = false, comma = false, quote = false; bool tilde = false, mute = false, comma = false, quote = false;
while (n < len) { while (n < len) {
@ -7552,8 +7578,12 @@ const char doc22[] = "(eq item item)\n"
"or point to the same cons, and returns t or nil as appropriate."; "or point to the same cons, and returns t or nil as appropriate.";
const char doc23[] = "(car list)\n" const char doc23[] = "(car list)\n"
"Returns the first item in a list."; "Returns the first item in a list.";
const char doc24[] = "(first list)\n"
"Returns the first item in a list. Equivalent to car.";
const char doc25[] = "(cdr list)\n" const char doc25[] = "(cdr list)\n"
"Returns a list with the first item removed."; "Returns a list with the first item removed.";
const char doc26[] = "(rest list)\n"
"Returns a list with the first item removed. Equivalent to cdr.";
const char doc27[] = "(nth number list)\n" const char doc27[] = "(nth number list)\n"
"Returns the nth item in list, counting from zero."; "Returns the nth item in list, counting from zero.";
const char doc28[] = "(aref array index [index*])\n" const char doc28[] = "(aref array index [index*])\n"
@ -7659,6 +7689,8 @@ const char doc64[] = "(and item*)\n"
"Evaluates its arguments until one returns nil, and returns the last value."; "Evaluates its arguments until one returns nil, and returns the last value.";
const char doc65[] = "(not item)\n" const char doc65[] = "(not item)\n"
"Returns t if its argument is nil, or nil otherwise. Equivalent to null."; "Returns t if its argument is nil, or nil otherwise. Equivalent to null.";
const char doc66[] = "(null list)\n"
"Returns t if its argument is nil, or nil otherwise. Equivalent to not.";
const char doc67[] = "(cons item item)\n" const char doc67[] = "(cons item item)\n"
"If the second argument is a list, cons returns a new list with item added to the front of the list.\n" "If the second argument is a list, cons returns a new list with item added to the front of the list.\n"
"If the second argument isn't a list cons returns a dotted pair."; "If the second argument isn't a list cons returns a dotted pair.";
@ -7685,6 +7717,8 @@ const char doc77[] = "(equal item item)\n"
"or point to the same cons, and returns t or nil as appropriate."; "or point to the same cons, and returns t or nil as appropriate.";
const char doc78[] = "(caar list)"; const char doc78[] = "(caar list)";
const char doc79[] = "(cadr list)"; const char doc79[] = "(cadr list)";
const char doc80[] = "(second list)\n"
"Returns the second item in a list. Equivalent to cadr.";
const char doc81[] = "(cdar list)\n" const char doc81[] = "(cdar list)\n"
"Equivalent to (cdr (car list))."; "Equivalent to (cdr (car list)).";
const char doc82[] = "(cddr list)\n" const char doc82[] = "(cddr list)\n"
@ -7697,6 +7731,8 @@ const char doc85[] = "(cadar list)\n"
"Equivalent to (car (cdr (car list)))."; "Equivalent to (car (cdr (car list))).";
const char doc86[] = "(caddr list)\n" const char doc86[] = "(caddr list)\n"
"Equivalent to (car (cdr (cdr list)))."; "Equivalent to (car (cdr (cdr list))).";
const char doc87[] = "(third list)\n"
"Returns the third item in a list. Equivalent to caddr.";
const char doc88[] = "(cdaar list)\n" const char doc88[] = "(cdaar list)\n"
"Equivalent to (cdar (car (car list)))."; "Equivalent to (cdar (car (car list))).";
const char doc89[] = "(cdadr list)\n" const char doc89[] = "(cdadr list)\n"
@ -8107,9 +8143,9 @@ const tbl_entry_t lookup_table[] = {
{ string21, sp_defcode, 0307, doc21 }, { string21, sp_defcode, 0307, doc21 },
{ string22, fn_eq, 0222, doc22 }, { string22, fn_eq, 0222, doc22 },
{ string23, fn_car, 0211, doc23 }, { string23, fn_car, 0211, doc23 },
{ string24, fn_car, 0211, NULL }, { string24, fn_car, 0211, doc24 },
{ string25, fn_cdr, 0211, doc25 }, { string25, fn_cdr, 0211, doc25 },
{ string26, fn_cdr, 0211, NULL }, { string26, fn_cdr, 0211, doc26 },
{ string27, fn_nth, 0222, doc27 }, { string27, fn_nth, 0222, doc27 },
{ string28, fn_aref, 0227, doc28 }, { string28, fn_aref, 0227, doc28 },
{ string29, fn_char, 0222, doc29 }, { string29, fn_char, 0222, doc29 },
@ -8149,7 +8185,7 @@ const tbl_entry_t lookup_table[] = {
{ string63, tf_case, 0117, doc63 }, { string63, tf_case, 0117, doc63 },
{ string64, tf_and, 0107, doc64 }, { string64, tf_and, 0107, doc64 },
{ string65, fn_not, 0211, doc65 }, { string65, fn_not, 0211, doc65 },
{ string66, fn_not, 0211, NULL }, { string66, fn_not, 0211, doc66 },
{ string67, fn_cons, 0222, doc67 }, { string67, fn_cons, 0222, doc67 },
{ string68, fn_atom, 0211, doc68 }, { string68, fn_atom, 0211, doc68 },
{ string69, fn_listp, 0211, doc69 }, { string69, fn_listp, 0211, doc69 },
@ -8163,14 +8199,14 @@ const tbl_entry_t lookup_table[] = {
{ string77, fn_equal, 0222, doc77 }, { string77, fn_equal, 0222, doc77 },
{ string78, fn_caar, 0211, doc78 }, { string78, fn_caar, 0211, doc78 },
{ string79, fn_cadr, 0211, doc79 }, { string79, fn_cadr, 0211, doc79 },
{ string80, fn_cadr, 0211, NULL }, { string80, fn_cadr, 0211, doc80 },
{ string81, fn_cdar, 0211, doc81 }, { string81, fn_cdar, 0211, doc81 },
{ string82, fn_cddr, 0211, doc82 }, { string82, fn_cddr, 0211, doc82 },
{ string83, fn_caaar, 0211, doc83 }, { string83, fn_caaar, 0211, doc83 },
{ string84, fn_caadr, 0211, doc84 }, { string84, fn_caadr, 0211, doc84 },
{ string85, fn_cadar, 0211, doc85 }, { string85, fn_cadar, 0211, doc85 },
{ string86, fn_caddr, 0211, doc86 }, { string86, fn_caddr, 0211, doc86 },
{ string87, fn_caddr, 0211, NULL }, { string87, fn_caddr, 0211, doc87 },
{ string88, fn_cdaar, 0211, doc88 }, { string88, fn_cdaar, 0211, doc88 },
{ string89, fn_cdadr, 0211, doc89 }, { string89, fn_cdadr, 0211, doc89 },
{ string90, fn_cddar, 0211, doc90 }, { string90, fn_cddar, 0211, doc90 },
@ -9478,7 +9514,6 @@ void initgfx () {
#endif #endif
} }
// Entry point from the Arduino IDE
void setup () { void setup () {
Serial.begin(9600); Serial.begin(9600);
int start = millis(); int start = millis();
@ -9487,7 +9522,7 @@ void setup () {
initenv(); initenv();
initsleep(); initsleep();
initgfx(); initgfx();
pfstring(PSTR("uLisp 4.7 "), pserial); pln(pserial); pfstring(PSTR("uLisp 4.7b "), pserial); pln(pserial);
} }
// Read/Evaluate/Print loop // Read/Evaluate/Print loop

View File

@ -1,5 +1,5 @@
/* uLisp ARM Release 4.7a - www.ulisp.com /* uLisp ARM Release 4.7b - www.ulisp.com
David Johnson-Davies - www.technoblogy.com - 12th January 2025 David Johnson-Davies - www.technoblogy.com - 20th March 2025
Licensed under the MIT license: https://opensource.org/licenses/MIT Licensed under the MIT license: https://opensource.org/licenses/MIT
*/ */
@ -241,7 +241,7 @@ const char LispLibrary[] = "";
#define CPU_RP2040 #define CPU_RP2040
#elif defined(ARDUINO_RASPBERRY_PI_PICO_W) #elif defined(ARDUINO_RASPBERRY_PI_PICO_W)
#define WORKSPACESIZE (15536-SDSIZE) /* Objects (8*bytes) */ #define WORKSPACESIZE (15232-SDSIZE) /* Objects (8*bytes) */
#define CODESIZE 256 /* Bytes */ #define CODESIZE 256 /* Bytes */
#define STACKDIFF 480 #define STACKDIFF 480
#define LITTLEFS #define LITTLEFS
@ -3894,8 +3894,8 @@ object *fn_copylist (object *args, object *env) {
if (!listp(arg)) error(notalist, arg); if (!listp(arg)) error(notalist, arg);
object *result = cons(NULL, NULL); object *result = cons(NULL, NULL);
object *ptr = result; object *ptr = result;
while (arg != NULL) { while (consp(arg)) {
cdr(ptr) = cons(car(arg), NULL); cdr(ptr) = cons(car(arg), cdr(arg));
ptr = cdr(ptr); arg = cdr(arg); ptr = cdr(ptr); arg = cdr(arg);
} }
return cdr(result); return cdr(result);
@ -4822,10 +4822,13 @@ object *fn_readline (object *args, object *env) {
return readstring('\n', false, gfun); return readstring('\n', false, gfun);
} }
inline void serialwrite (char c) { Serial.write(c); }
object *fn_writebyte (object *args, object *env) { object *fn_writebyte (object *args, object *env) {
(void) env; (void) env;
int value = checkinteger(first(args)); int value = checkinteger(first(args));
pfun_t pfun = pstreamfun(cdr(args)); pfun_t pfun = pstreamfun(cdr(args));
if (pfun == pserial) pfun = serialwrite;
(pfun)(value); (pfun)(value);
return nil; return nil;
} }
@ -4981,9 +4984,10 @@ object *fn_analogreference (object *args, object *env) {
#if defined(ARDUINO_TEENSY40) || defined(ARDUINO_TEENSY41) || defined(MAX32620) \ #if defined(ARDUINO_TEENSY40) || defined(ARDUINO_TEENSY41) || defined(MAX32620) \
|| defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_RASPBERRY_PI_PICO_W) \ || defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_RASPBERRY_PI_PICO_W) \
|| defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040_ADALOGGER) \ || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040_ADALOGGER) \
|| defined(ARDUINO_ADAFRUIT_QTPY_RP2040) || defined(ARDUINO_RASPBERRY_PI_PICO_2) \ || defined(ARDUINO_ADAFRUIT_QTPY_RP2040) || defined(ARDUINO_SEEED_XIAO_RP2040) \
|| defined(ARDUINO_RASPBERRY_PI_PICO_2W) || defined(ARDUINO_PIMORONI_PICO_PLUS_2) \ || defined(ARDUINO_RASPBERRY_PI_PICO_2) || defined(ARDUINO_RASPBERRY_PI_PICO_2W) \
|| defined(ARDUINO_PIMORONI_TINY2350) || defined(ARDUINO_NANO_MATTER) || defined(ARDUINO_PIMORONI_PICO_PLUS_2) || defined(ARDUINO_PIMORONI_TINY2350) \
|| defined(ARDUINO_NANO_MATTER)
error2("not supported"); error2("not supported");
#else #else
analogReference((eAnalogReference)checkkeyword(arg)); analogReference((eAnalogReference)checkkeyword(arg));
@ -5137,7 +5141,7 @@ object *fn_format (object *args, object *env) {
object *save = NULL; object *save = NULL;
args = cddr(args); args = cddr(args);
int len = stringlength(formatstr); int len = stringlength(formatstr);
uint8_t n = 0, width = 0, w, bra = 0; uint16_t n = 0, width = 0, w, bra = 0;
char pad = ' '; char pad = ' ';
bool tilde = false, mute = false, comma = false, quote = false; bool tilde = false, mute = false, comma = false, quote = false;
while (n < len) { while (n < len) {
@ -6205,8 +6209,12 @@ const char doc22[] = "(eq item item)\n"
"or point to the same cons, and returns t or nil as appropriate."; "or point to the same cons, and returns t or nil as appropriate.";
const char doc23[] = "(car list)\n" const char doc23[] = "(car list)\n"
"Returns the first item in a list."; "Returns the first item in a list.";
const char doc24[] = "(first list)\n"
"Returns the first item in a list. Equivalent to car.";
const char doc25[] = "(cdr list)\n" const char doc25[] = "(cdr list)\n"
"Returns a list with the first item removed."; "Returns a list with the first item removed.";
const char doc26[] = "(rest list)\n"
"Returns a list with the first item removed. Equivalent to cdr.";
const char doc27[] = "(nth number list)\n" const char doc27[] = "(nth number list)\n"
"Returns the nth item in list, counting from zero."; "Returns the nth item in list, counting from zero.";
const char doc28[] = "(aref array index [index*])\n" const char doc28[] = "(aref array index [index*])\n"
@ -6312,6 +6320,8 @@ const char doc64[] = "(and item*)\n"
"Evaluates its arguments until one returns nil, and returns the last value."; "Evaluates its arguments until one returns nil, and returns the last value.";
const char doc65[] = "(not item)\n" const char doc65[] = "(not item)\n"
"Returns t if its argument is nil, or nil otherwise. Equivalent to null."; "Returns t if its argument is nil, or nil otherwise. Equivalent to null.";
const char doc66[] = "(null list)\n"
"Returns t if its argument is nil, or nil otherwise. Equivalent to not.";
const char doc67[] = "(cons item item)\n" const char doc67[] = "(cons item item)\n"
"If the second argument is a list, cons returns a new list with item added to the front of the list.\n" "If the second argument is a list, cons returns a new list with item added to the front of the list.\n"
"If the second argument isn't a list cons returns a dotted pair."; "If the second argument isn't a list cons returns a dotted pair.";
@ -6338,6 +6348,8 @@ const char doc77[] = "(equal item item)\n"
"or point to the same cons, and returns t or nil as appropriate."; "or point to the same cons, and returns t or nil as appropriate.";
const char doc78[] = "(caar list)"; const char doc78[] = "(caar list)";
const char doc79[] = "(cadr list)"; const char doc79[] = "(cadr list)";
const char doc80[] = "(second list)\n"
"Returns the second item in a list. Equivalent to cadr.";
const char doc81[] = "(cdar list)\n" const char doc81[] = "(cdar list)\n"
"Equivalent to (cdr (car list))."; "Equivalent to (cdr (car list)).";
const char doc82[] = "(cddr list)\n" const char doc82[] = "(cddr list)\n"
@ -6350,6 +6362,8 @@ const char doc85[] = "(cadar list)\n"
"Equivalent to (car (cdr (car list)))."; "Equivalent to (car (cdr (car list))).";
const char doc86[] = "(caddr list)\n" const char doc86[] = "(caddr list)\n"
"Equivalent to (car (cdr (cdr list)))."; "Equivalent to (car (cdr (cdr list))).";
const char doc87[] = "(third list)\n"
"Returns the third item in a list. Equivalent to caddr.";
const char doc88[] = "(cdaar list)\n" const char doc88[] = "(cdaar list)\n"
"Equivalent to (cdar (car (car list)))."; "Equivalent to (cdar (car (car list))).";
const char doc89[] = "(cdadr list)\n" const char doc89[] = "(cdadr list)\n"
@ -6760,9 +6774,9 @@ const tbl_entry_t lookup_table[] = {
{ string21, sp_defcode, 0307, doc21 }, { string21, sp_defcode, 0307, doc21 },
{ string22, fn_eq, 0222, doc22 }, { string22, fn_eq, 0222, doc22 },
{ string23, fn_car, 0211, doc23 }, { string23, fn_car, 0211, doc23 },
{ string24, fn_car, 0211, NULL }, { string24, fn_car, 0211, doc24 },
{ string25, fn_cdr, 0211, doc25 }, { string25, fn_cdr, 0211, doc25 },
{ string26, fn_cdr, 0211, NULL }, { string26, fn_cdr, 0211, doc26 },
{ string27, fn_nth, 0222, doc27 }, { string27, fn_nth, 0222, doc27 },
{ string28, fn_aref, 0227, doc28 }, { string28, fn_aref, 0227, doc28 },
{ string29, fn_char, 0222, doc29 }, { string29, fn_char, 0222, doc29 },
@ -6802,7 +6816,7 @@ const tbl_entry_t lookup_table[] = {
{ string63, tf_case, 0117, doc63 }, { string63, tf_case, 0117, doc63 },
{ string64, tf_and, 0107, doc64 }, { string64, tf_and, 0107, doc64 },
{ string65, fn_not, 0211, doc65 }, { string65, fn_not, 0211, doc65 },
{ string66, fn_not, 0211, NULL }, { string66, fn_not, 0211, doc66 },
{ string67, fn_cons, 0222, doc67 }, { string67, fn_cons, 0222, doc67 },
{ string68, fn_atom, 0211, doc68 }, { string68, fn_atom, 0211, doc68 },
{ string69, fn_listp, 0211, doc69 }, { string69, fn_listp, 0211, doc69 },
@ -6816,14 +6830,14 @@ const tbl_entry_t lookup_table[] = {
{ string77, fn_equal, 0222, doc77 }, { string77, fn_equal, 0222, doc77 },
{ string78, fn_caar, 0211, doc78 }, { string78, fn_caar, 0211, doc78 },
{ string79, fn_cadr, 0211, doc79 }, { string79, fn_cadr, 0211, doc79 },
{ string80, fn_cadr, 0211, NULL }, { string80, fn_cadr, 0211, doc80 },
{ string81, fn_cdar, 0211, doc81 }, { string81, fn_cdar, 0211, doc81 },
{ string82, fn_cddr, 0211, doc82 }, { string82, fn_cddr, 0211, doc82 },
{ string83, fn_caaar, 0211, doc83 }, { string83, fn_caaar, 0211, doc83 },
{ string84, fn_caadr, 0211, doc84 }, { string84, fn_caadr, 0211, doc84 },
{ string85, fn_cadar, 0211, doc85 }, { string85, fn_cadar, 0211, doc85 },
{ string86, fn_caddr, 0211, doc86 }, { string86, fn_caddr, 0211, doc86 },
{ string87, fn_caddr, 0211, NULL }, { string87, fn_caddr, 0211, doc87 },
{ string88, fn_cdaar, 0211, doc88 }, { string88, fn_cdaar, 0211, doc88 },
{ string89, fn_cdadr, 0211, doc89 }, { string89, fn_cdadr, 0211, doc89 },
{ string90, fn_cddar, 0211, doc90 }, { string90, fn_cddar, 0211, doc90 },
@ -7999,7 +8013,6 @@ void initgfx () {
#endif #endif
} }
// Entry point from the Arduino IDE
void setup () { void setup () {
Serial.begin(9600); Serial.begin(9600);
int start = millis(); int start = millis();
@ -8008,7 +8021,7 @@ void setup () {
initenv(); initenv();
initsleep(); initsleep();
initgfx(); initgfx();
pfstring(PSTR("uLisp 4.7a "), pserial); pln(pserial); pfstring(PSTR("uLisp 4.7b "), pserial); pln(pserial);
} }
// Read/Evaluate/Print loop // Read/Evaluate/Print loop