git » jacl.git » commit 121f8dc

Load boot.lisp; require local webserver for dev

author Alan Dipert
2020-01-14 05:58:37 UTC
committer Alan Dipert
2020-01-14 05:58:37 UTC
parent 8adc105130cad86d2aa750acad157f146611c88c

Load boot.lisp; require local webserver for dev

boot.lisp +7 -8
index.html +5 -4
jacl.js +22 -1

diff --git a/boot.lisp b/boot.lisp
index 8adb06f..6b89d64 100644
--- a/boot.lisp
+++ b/boot.lisp
@@ -54,14 +54,13 @@
 (%let ((cl-user-pkg (\. (%js "Package") (|get| (\. '#:common-lisp-user |name|)))))
   (\. cl-user-pkg (|usePackage| cl:*package*))
   (%setq cl:*package* cl-user-pkg))
-
 ;; Testing things
 
-(defvar *x*)
-
-(defun observe-*x* ()
-  *x*)
-
-(let ((*x* 123))
-  (observe-*x*))
+;;(defvar *x*)
+;;
+;;(defun observe-*x* ()
+;;  *x*)
+;;
+;;(let ((*x* 123))
+;;  (observe-*x*))
 
diff --git a/index.html b/index.html
index 1c905dd..0d1eab0 100644
--- a/index.html
+++ b/index.html
@@ -13,13 +13,14 @@
       }
     }
     </style>
-  </head>
-  <body>
-    <div id="qunit"></div>
-    <div id="qunit-fixture"></div>
     <script src="qunit-2.9.2.js"></script>
     <script src="multimethod.js"></script>
     <script src="jacl.js"></script>
     <script src="jacl-tests.js"></script>
+    <script type="application/lisp" src="boot.lisp"></script>
+  </head>
+  <body>
+    <div id="qunit"></div>
+    <div id="qunit-fixture"></div>
   </body>
 </html>
diff --git a/jacl.js b/jacl.js
index 97f08b1..d0c6f03 100644
--- a/jacl.js
+++ b/jacl.js
@@ -1940,7 +1940,28 @@ const startRepl = async () => {
   }
 };
 
-startRepl();
+const loadLispScripts = async () => {
+  for (let i = 0; i < document.head.childNodes.length; i++) {
+    const child = document.head.childNodes[i];
+    if (child.nodeName === 'SCRIPT' && child.src.endsWith('.lisp')) {
+      const bs = new BufferedStream();
+      const rdr = new Reader(bs);
+      const code = await (await fetch(child.src)).text();
+      bs.writeEach(code);
+      for await(const obj of rdr) {
+        const node = analyze(emptyEnv, null, obj);
+        const sb = new StringBuffer();
+        emitNode(sb.append.bind(sb), node);
+        eval(sb.toString());
+      }
+    }
+  }
+};
+
+document.addEventListener('DOMContentLoaded', async () => {
+  await loadLispScripts();
+  startRepl();
+});
 
 //var buf = new BufferedStream(),
 //    rdr = new Reader(buf);