@@ -1566,10 +1566,12 @@ static inline lisp eval_hlp(lisp e, lisp* envp) {
15661566inline lisp reduce_immediate (lisp x ) {
15671567 while (x && IS (x , immediate )) {
15681568 lisp tofree = x ;
1569+
15691570 if (trace ) // make it visible
15701571 x = evalGC (ATTR (thunk , x , e ), & ATTR (thunk , x , env ));
15711572 else
15721573 x = eval_hlp (ATTR (thunk , x , e ), & ATTR (thunk , x , env ));
1574+
15731575 // immediates are immediately consumed after evaluation, so they can be free:d directly
15741576 tofree -> tag = 0 ;
15751577 sfree ((void * )tofree , sizeof (thunk ), immediate_TAG );
@@ -1612,7 +1614,6 @@ inline int needGC() {
16121614}
16131615
16141616
1615- #define MAX_STACK 80
16161617// (de rec (n) (print n) (rec (+ n 1)) nil) // not tail recursive!
16171618// === optimized:
16181619// ...
@@ -1625,13 +1626,16 @@ inline int needGC() {
16251626// #772 0x08052d58 in readeval ()
16261627// #773 0x08048b57 in main ()
16271628
1629+ #define MAX_STACK 80
1630+
16281631static struct stack {
16291632 lisp e ;
16301633 lisp * envp ;
16311634} stack [MAX_STACK ];
16321635
16331636static int level = 0 ;
16341637
1638+ // TODO: because of tail call optimization, we can't tell where the error occurred as it's not relevant on the stack???
16351639PRIM print_detailed_stack () {
16361640 int l ;
16371641 // TODO: DONE but too much: using fargs of f can use .envp to print actual arguments!
@@ -2073,7 +2077,7 @@ PRIM heap() {
20732077
20742078
20752079////////////////////////////////////////////////////////////////////////////////
2076- // flash fielesystem
2080+ // flash file access
20772081//
20782082// - https://blog.cesanta.com/esp8266_using_flash
20792083// ~/GIT/Espruino-on-ESP8266/user/user_main.c
@@ -2097,6 +2101,20 @@ PRIM scan(lisp s) {
20972101 return nil ;
20982102}
20992103
2104+ // Highlevel
2105+
2106+ // (save '(http boot) (lambda (x) (init-web-server)) (lambda (x) (print "Done")))
2107+ //lisp save(lisp key, lisp data, lisp cb) {
2108+ //}
2109+
2110+ // tail-recurses on: cb(key, info, cb)
2111+ //lisp dir(lisp matchkey, lisp cb) {
2112+ //}
2113+
2114+ // tail-recurses on: cb(key, info, data, cb, end?)
2115+ //lisp load(lisp matchkey, lisp cb) {
2116+ //}
2117+
21002118#else
21012119
21022120// http://www.esp8266.com/wiki/doku.php?id=esp8266_memory_map
@@ -2587,21 +2605,15 @@ lisp lisp_init() {
25872605 return env ;
25882606}
25892607
2590- void hello ( ) {
2608+ void help ( lisp * envp ) {
25912609 printf ("\n\nWelcome to esp-lisp!\n" );
25922610 printf ("2015 (c) Jonas S Karlsson under MPL 2.0\n" );
2593- printf ("Read more on https://github.com/yesco/esp-lisp/\n" );
2594- printf ("\n" );
2595- }
2596-
2597- void help (lisp * envp ) {
2598- hello ();
2611+ printf ("Read more on https://github.com/yesco/esp-lisp/\n\n" );
25992612 printf ("Global/SYMBOLS: " );
26002613 PRINT ((syms (lambda (x ) (princ x ) (princ " "))));
2601- terpri ();
2602- printf ("COMMANDS: hello/help/trace on/trace off/gc on/gc off/wifi SSID PSWD/wget SERVER URL/mem EXPR/quit/exit\n" );
2603- terpri ();
2604- printf ("CTRL-T: shows current time/load status\n" );
2614+ printf ("\nCOMMANDS: help/trace on/trace off/gc on/gc off/wifi SSID PSWD/wget SERVER URL/mem EXPR/quit/exit\n\n" );
2615+ printf ("CTRL-C: to break execution, CTRL-T: shows current time/load status, CTRL-D: to exit\n\n" );
2616+ printf ("Type 'help' to get this message again\n" );
26052617}
26062618
26072619#include <setjmp.h>
@@ -2623,6 +2635,8 @@ void error(char* msg) {
26232635 printf ("\n%% error(): error inside error... recovering...\n" );
26242636 }
26252637
2638+ printf ("\n%%%% type 'help' to get help\n" );
2639+
26262640 if (memcmp (lisp_break , empty , sizeof (empty ))) { // contains valid value
26272641 // reset stack
26282642 level = 0 ;
@@ -2764,7 +2778,7 @@ int lispreadchar(char *chp) {
27642778}
27652779
27662780void readeval (lisp * envp ) {
2767- hello ( );
2781+ help ( envp );
27682782
27692783 while (1 ) {
27702784 global_envp = envp ; // allow idle to gc
@@ -2775,8 +2789,6 @@ void readeval(lisp* envp) {
27752789 break ;
27762790 } else if (strncmp (ln , ";" , 1 ) == 0 ) {
27772791 ; // comment - ignore
2778- } else if (strcmp (ln , "hello" ) == 0 ) {
2779- hello ();
27802792 } else if (strcmp (ln , "help" ) == 0 || ln [0 ] == '?' ) {
27812793 help (envp );
27822794 } else if (strcmp (ln , "gc on" ) == 0 ) {
0 commit comments