diff --git a/ulisp/platformio.ini b/ulisp/platformio.ini index 50208f0..ec41326 100644 --- a/ulisp/platformio.ini +++ b/ulisp/platformio.ini @@ -12,3 +12,4 @@ platform = atmelsam board = adafruit_feather_m4 framework = arduino +lib_deps = arduino-libraries/SD diff --git a/ulisp/src/ulisp.cc b/ulisp/src/ulisp.cc index 71e643c..a9cd616 100644 --- a/ulisp/src/ulisp.cc +++ b/ulisp/src/ulisp.cc @@ -14,7 +14,7 @@ const char LispLibrary[] PROGMEM = ""; // #define resetautorun #define printfreespace // #define printgcs -// #define sdcardsupport +#define sdcardsupport // #define gfxsupport // #define lisplibrary #define assemblerlist @@ -183,7 +183,7 @@ typedef int PinMode; #define CPU_ATSAMD21 #elif defined(ARDUINO_METRO_M4) || defined(ARDUINO_ITSYBITSY_M4) || defined(ARDUINO_FEATHER_M4) || defined(ARDUINO_PYBADGE_M4) || defined(ARDUINO_PYGAMER_M4) - #define WORKSPACESIZE 20480-SDSIZE /* Objects (8*bytes) */ + #define WORKSPACESIZE (20480-SDSIZE) /* Objects (8*bytes) */ #define DATAFLASHSIZE 2048000 /* 2 MBytes */ #define SYMBOLTABLESIZE 1024 /* Bytes */ #define CODESIZE 256 /* Bytes */ @@ -309,16 +309,55 @@ enum flag { PRINTREADABLY, RETURNFLAG, ESCAPE, EXITEDITOR, LIBRARYLOADED, NOESC volatile char Flags = 0b00001; // PRINTREADABLY set by default // Forward references +bool consp (object *x); +bool atom (object *x); +bool listp (object *x); +bool improperp (object *x); +object *quote (object *arg); object *tee; object *tf_progn (object *form, object *env); object *eval (object *form, object *env); -object *read (gfun_t gfun); -void repl (object *env); +object *read (pfun_t pfun); +void repl(object *env); void printobject (object *form, pfun_t pfun); char *lookupbuiltin (symbol_t name); -intptr_t lookupfn (symbol_t name); +int lookupfn (symbol_t name); +int lookupmin(symbol_t name); +int lookupmax(symbol_t name); int builtin (char* n); - +void Display (char c); +void error (const __FlashStringHelper *); +void pfstring (const char *s, pfun_t pfun); +void pfstring (const __FlashStringHelper *); +void pln (pfun_t pfun); +void pfl (pfun_t pfun); +void pchar (char c); +int gchar (); +object *apply (object *function, object *args, object **env); +char *lookupsymbol (symbol_t name); +void deletesymbol (symbol_t name); +object *edit(object *fun); +int subwidthlist (object *form, int w); +void superprint (object *form, int lm); +void supersub (object *form, int lm, int super, pfun_t pfun); +void pserial (char c); +char *symbolname (symbol_t x); +void pstring (char *s, pfun_t pfun); +int maxbuffer (char *buffer); +char nthchar (object *string, int n); +object *apply (symbol_t name, object *function, object *args, object *env); +int listlength (symbol_t name, object *list); +void checkminmax (symbol_t name, int nargs); +void pint (int i, pfun_t pfun); +void testescape (); +int gserial (); +void pinthex (uint32_t i, pfun_t pfun); +void printhex4 (int i, pfun_t pfun); +void prin1object (object *form, pfun_t pfun); +int assemble (int pass, int origin, object *entries, object *env, object *pcpair); +void printstring (object *form, pfun_t pfun); +int glibrary (); + // Error handling void errorsub (symbol_t fname, PGM_P string) { @@ -902,7 +941,9 @@ object *quote (object *arg) { int toradix40 (char ch) { if (ch == 0) return 0; if (ch >= '0' && ch <= '9') return ch-'0'+30; - if (ch == '$') return 27; if (ch == '*') return 28; if (ch == '-') return 29; + if (ch == '$') return 27; + if (ch == '*') return 28; + if (ch == '-') return 29; ch = ch | 0x20; if (ch >= 'a' && ch <= 'z') return ch-'a'+1; return -1; // Invalid @@ -910,7 +951,9 @@ int toradix40 (char ch) { int fromradix40 (int n) { if (n >= 1 && n <= 26) return 'a'+n-1; - if (n == 27) return '$'; if (n == 28) return '*'; if (n == 29) return '-'; + if (n == 27) return '$'; + if (n == 28) return '*'; + if (n == 29) return '-'; if (n >= 30 && n <= 39) return '0'+n-30; return 0; } @@ -3623,7 +3666,7 @@ object *fn_readfromstring (object *args, object *env) { if (!stringp(arg)) error(READFROMSTRING, notastring, arg); GlobalString = arg; GlobalStringIndex = 0; - return read(gstr); + return read((pfun_t)gstr); } object *fn_princtostring (object *args, object *env) { @@ -3734,7 +3777,7 @@ object *fn_break (object *args, object *env) { object *fn_read (object *args, object *env) { (void) env; gfun_t gfun = gstreamfun(args); - return read(gfun); + return read((pfun_t)gfun); } object *fn_prin1 (object *args, object *env) { @@ -3964,9 +4007,9 @@ object *edit (object *fun) { char c = gserial(); if (c == 'q') setflag(EXITEDITOR); else if (c == 'b') return fun; - else if (c == 'r') fun = read(gserial); + else if (c == 'r') fun = read((pfun_t)gserial); else if (c == '\n') { pfl(pserial); superprint(fun, 0, pserial); pln(pserial); } - else if (c == 'c') fun = cons(read(gserial), fun); + else if (c == 'c') fun = cons(read((pfun_t)gserial), fun); else if (atom(fun)) pserial('!'); else if (c == 'd') fun = cons(car(fun), edit(cdr(fun))); else if (c == 'a') fun = cons(edit(car(fun)), cdr(fun)); @@ -4112,7 +4155,7 @@ object *fn_require (object *args, object *env) { globals = cdr(globals); } GlobalStringIndex = 0; - object *line = read(glibrary); + object *line = read((pfun_t)glibrary); while (line != NULL) { // Is this the definition we want int fname = first(line)->name; @@ -4120,7 +4163,7 @@ object *fn_require (object *args, object *env) { eval(line, env); return tee; } - line = read(glibrary); + line = read((pfun_t)glibrary); } return nil; } @@ -4128,13 +4171,13 @@ object *fn_require (object *args, object *env) { object *fn_listlibrary (object *args, object *env) { (void) args, (void) env; GlobalStringIndex = 0; - object *line = read(glibrary); + object *line = read((pfun_t)glibrary); while (line != NULL) { int fname = first(line)->name; if (fname == DEFUN || fname == DEFVAR) { pstring(symbolname(second(line)->name), pserial); pserial(' '); } - line = read(glibrary); + line = read((pfun_t)glibrary); } return symbol(NOTHING); } @@ -5193,10 +5236,10 @@ int glibrary () { void loadfromlibrary (object *env) { GlobalStringIndex = 0; - object *line = read(glibrary); + object *line = read((pfun_t)glibrary); while (line != NULL) { eval(line, env); - line = read(glibrary); + line = read((pfun_t)glibrary); } } @@ -5370,13 +5413,13 @@ object *nextitem (gfun_t gfun) { else if (ch == '\'') return nextitem(gfun); else if (ch == '.') { setflag(NOESC); - object *result = eval(read(gfun), NULL); + object *result = eval(read((pfun_t)gfun), NULL); clrflag(NOESC); return result; } - else if (ch == '(') { LastChar = ch; return readarray(1, read(gfun)); } - else if (ch == '*') return readbitarray(gfun); - else if (ch >= '1' && ch <= '9' && (gfun() & ~0x20) == 'A') return readarray(ch - '0', read(gfun)); + else if (ch == '(') { LastChar = ch; return readarray(1, read((pfun_t)gfun)); } + else if (ch == '*') return readbitarray((gfun_t)gfun); + else if (ch >= '1' && ch <= '9' && (gfun() & ~0x20) == 'A') return readarray(ch - '0', read((pfun_t)gfun)); else error2(0, PSTR("illegal character after #")); ch = gfun(); } @@ -5447,9 +5490,9 @@ object *readrest (gfun_t gfun) { if (item == (object *)BRA) { item = readrest(gfun); } else if (item == (object *)QUO) { - item = cons(symbol(QUOTE), cons(read(gfun), NULL)); + item = cons(symbol(QUOTE), cons(read((pfun_t)gfun), NULL)); } else if (item == (object *)DOT) { - tail->cdr = read(gfun); + tail->cdr = read((pfun_t)gfun); if (readrest(gfun) != NULL) error2(0, PSTR("malformed list")); return head; } else {