Hi Goheeca,
That is a very welcome improvement! Thank you very much. I merged it into my repository of ulisp-esp-m5stack and it improved my little m5stack-based uLisp stand-alone computer (see http://blog.matroid.org/display/88) a lot. It is much easier to learn Lisp when errors do not freeze everything. :) Also, It will help a lot with my networking code (see http://blog.matroid.org/display/86).
Can I add your commits to my github repository m-g-r/ulisp-esp-m5stack?
To circumvent the limitation of the missing multiple-values that you mentioned with regard to ignore-errors, I have added a GlobalErrorString to hold the last error message and a function get-error to retrieve it. I consider this to be a workaround but it is good enough to show error messages in the little REPL of the Lisp handheld.
I’ll push that patch also to my repository when I can add your commits.
Cheers, Max
PS: I try to add the patch here as well for convenience and hope that it is copy-able.
diff --git a/ulisp-esp.ino b/ulisp-esp.ino
index 4174067..20e028f 100644
--- a/ulisp-esp.ino
+++ b/ulisp-esp.ino
@@ -234,6 +234,7 @@ K_INPUT, K_INPUT_PULLUP, K_OUTPUT,
K_INPUT, K_INPUT_PULLUP, K_INPUT_PULLDOWN, K_OUTPUT,
#endif
USERFUNCTIONS,
+GETERROR,
// functions of m-g-r/ulisp-esp-m5stack - begin
MUTESPEAKER, SETUPBACKLIGHTPWM,
#if defined(enable_ntptime)
@@ -272,6 +273,7 @@ unsigned int TraceDepth[TRACEMAX];
object *GlobalEnv;
object *GCStack = NULL;
object *GlobalString;
+object *GlobalErrorString;
int GlobalStringIndex = 0;
uint8_t PrintCount = 0;
uint8_t BreakLevel = 0;
@@ -300,32 +302,56 @@ object *edit (object *fun);
// Error handling
-void errorsub (symbol_t fname, PGM_P string) {
- pfl(pserial); pfstring(PSTR("Error: "), pserial);
+object *errorsub (symbol_t fname, PGM_P string) {
+ if (!tstflag(MUFFLEERRORS)) {
+ pfl(pserial); pfstring(PSTR("Error: "), pserial);
+ if (fname) {
+ pserial('\'');
+ pstring(symbolname(fname), pserial);
+ pserial('\''); pserial(' ');
+ }
+ pfstring(string, pserial);
+ }
+
+ // store error message in string object for GET-ERROR
+ object *obj = startstring(SP_ERROR);
if (fname) {
- pserial('\'');
- pstring(symbolname(fname), pserial);
- pserial('\''); pserial(' ');
+ pstr('\'');
+ pstring(symbolname(fname), pstr);
+ pstr('\''); pstr(' ');
}
- pfstring(string, pserial);
+ pfstring(string, pstr); // copy to globalstring
+
+ return obj;
}
void error (symbol_t fname, PGM_P string, object *symbol) {
+ object *obj = errorsub(fname, string);
if (!tstflag(MUFFLEERRORS)) {
- errorsub(fname, string);
pserial(':'); pserial(' ');
printobject(symbol, pserial);
pln(pserial);
}
+
+ // add symbol to string object for GET-ERROR
+ pstr(':'); pstr(' ');
+ printobject(symbol, pstr); // copy to globalstring
+ // store error message in GlobalErrorString for GET-ERROR
+ GlobalErrorString = obj;
+
GCStack = NULL;
longjmp(*handler, 1);
}
void error2 (symbol_t fname, PGM_P string) {
+ object *obj = errorsub(fname, string);
if (!tstflag(MUFFLEERRORS)) {
- errorsub(fname, string);
pln(pserial);
}
+
+ // store error message in GlobalErrorString for GET-ERROR
+ GlobalErrorString = obj;
+
GCStack = NULL;
longjmp(*handler, 1);
}
@@ -486,6 +512,7 @@ void gc (object *form, object *env) {
markobject(GCStack);
markobject(form);
markobject(env);
+ markobject(GlobalErrorString);
sweep();
#if defined(printgcs)
pfl(pserial); pserial('{'); pint(Freespace - start, pserial); pserial('}');
@@ -2221,6 +2248,10 @@ object *sp_error (object *args, object *env) {
cons(symbol(FORMAT), cons(nil, cons(arg, args))),
env);
}
+
+ // store error message in GlobalErrorString for GET-ERROR
+ GlobalErrorString = message;
+
if (!tstflag(MUFFLEERRORS)) {
char temp = Flags;
clrflag(PRINTREADABLY);
@@ -2232,6 +2263,10 @@ object *sp_error (object *args, object *env) {
longjmp(*handler, 1);
}
+object *fn_geterror (object *args, object *env) {
+ return GlobalErrorString;
+}
+
// Tail-recursive forms
object *tf_progn (object *args, object *env) {
@@ -4995,6 +5030,7 @@ const char string223[] PROGMEM = "";
// Insert your own function names here
// Built-in symbol lookup table
+const char user06975b647a442ae56f6ee0abc8fb[] PROGMEM = "get-error";
// functions of m-g-r/ulisp-esp-m5stack - begin
const char user0f6db191193ec5132391e8cc3d09[] PROGMEM = "mute-speaker";
const char user1e940820e12df008e2062d387aef[] PROGMEM = "setup-backlight-pwm";
@@ -5265,6 +5301,7 @@ const tbl_entry_t lookup_table[] PROGMEM = {
{ string222, (fn_ptr_type)OUTPUT, PINMODE },
{ string223, NULL, 0x00 },
#endif
+ { user06975b647a442ae56f6ee0abc8fb, fn_geterror, 0x00 },
// functions of m-g-r/ulisp-esp-m5stack - begin
{ user0f6db191193ec5132391e8cc3d09, fn_mutespeaker, 0x00 },
{ user1e940820e12df008e2062d387aef, fn_setupbacklightpwm, 0x01 },