shithub: femtolisp

Download patch

ref: 1dcc71ec821e945158fa057a7ac07a60b91f5ed6
parent: eec95c17b8912b9ce79617bc23263d26ed1d71f6
author: JeffBezanson <[email protected]>
date: Thu Apr 29 14:39:17 EDT 2010

factoring out startup routine for embedded use


--- a/femtolisp/flisp.c
+++ b/femtolisp/flisp.c
@@ -2258,7 +2258,7 @@
 
 extern value_t fl_file(value_t *args, uint32_t nargs);
 
-int main(int argc, char *argv[])
+int fl_startup()
 {
     value_t e;
     int saveSP;
@@ -2303,17 +2303,31 @@
         }
         ios_close(value2c(ios_t*,Stack[SP-1]));
         POPN(1);
+    }
+    FL_CATCH {
+        ios_puts("fatal error during bootstrap:\n", ios_stderr);
+        fl_print(ios_stderr, lasterror);
+        ios_putc('\n', ios_stderr);
+        return 1;
+    }
+    return 0;
+}
 
+int main(int argc, char *argv[])
+{
+    if (fl_startup())
+        return 1;
+
+    FL_TRY {
         PUSH(symbol_value(symbol("__start")));
         PUSH(argv_list(argc, argv));
         (void)_applyn(1);
     }
     FL_CATCH {
-        ios_puts("fatal error during bootstrap:\n", ios_stderr);
+        ios_puts("fatal error:\n", ios_stderr);
         fl_print(ios_stderr, lasterror);
         ios_putc('\n', ios_stderr);
         return 1;
     }
-
     return 0;
 }
--- a/femtolisp/flisp.h
+++ b/femtolisp/flisp.h
@@ -322,4 +322,6 @@
 value_t cvalue_byte(value_t *args, uint32_t nargs);
 value_t cvalue_wchar(value_t *args, uint32_t nargs);
 
+int fl_startup();
+
 #endif