ESP32 crash when using the let function


#1

Hello.
After skipping the SD card stuff (commenting out the save-image and load-image functions) I was able to use ulisp for ESP32 on an M5Stack and also on a FireBeetle.
I am using Visual Studio Code and PlatformIO to compile the code, and have had some problems with the file functions. So I commented them out for now.
Generally, the system works, but the “let” function causes ESP32 to “Core 1 panic”.

This script works as it should:

(defvar multvar '2)
(defun multtest (inputvar) (setq multvar 10) (* inputvar multvar))

7959> (multtest 12)
120
7959> 

But this script does not work:

(defun multtest2 (inputvar) (let multvar2 10) (* inputvar multvar2))

7959> (multtest2 23)
Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC      : 0x401494c3  PS      : 0x00060130  A0      : 0x800d47b5  A1      : 0x3ffb1e60  
A2      : 0x00000002  A3      : 0x00000000  A4      : 0x8008a64d  A5      : 0x3ffb1e70  
A6      : 0x00000003  A7      : 0x00060b23  A8      : 0x00000002  A9      : 0x3ffc1128  
A10     : 0x00001f0d  A11     : 0x3ffc168c  A12     : 0x4008c08f  A13     : 0x3ffb1e20  
A14     : 0x00050b23  A15     : 0x3ffb8058  SAR     : 0x0000001b  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000002  LBEG    : 0x4000c28c  LEND    : 0x4000c296  LCOUNT  : 0x00000000  

Backtrace: 0x401494c3:0x3ffb1e60 0x400d47b2:0x3ffb1e80 0x400d4fca:0x3ffb1ec0 0x400d5190:0x3ffb1ee0 0x400d49fc:0x3ffb1f20 0x400d6221:0x3ffb1f60 0x400d62bf:0x3ffb1f80 0x400da689:0x3ffb1fb0 0x40089829:0x3ffb1fd0

Rebooting...
....uLisp 3.0 
7999> 

The crash always occurs when I use the let function. The examples are meaningless, but they show when the crash occurs.
Do you have any idea what could be causing it? It happens on both systems (M5Stack and FireBeetle).

Thanks a lot and Merry Xmas.
Hans-Günther


#2

I confirm what you’re getting. The problem is that the syntax for let is slightly different from setq - you need to say:

7978> (defun multtest2 (inputvar) (let ((multvar2 10)) (* inputvar multvar2)))
multtest2

7977> (multtest2 23)
230

It’s clearer if you structure the code:

(defun multtest2 (inputvar)
  (let ((multvar2 10))
    (* inputvar multvar2)))

Having said that, your code should have generated a uLisp error rather than a core dump. I’ll fix that next release.

Thanks! David


#3

Hello David, thank you very much for the prompt reply. I was confused by the core crash, so I didn’t even look for a syntax error in the Lisp code. My Lisp knowledge is a bit rusty (more than 20 years old) but ulisp and the modern MCUs are a good reason to get back in.

Have a nice holiday.
Hans-Gunther


#4