git » jacl.git » commit cd8deae

boot.lisp loading improvements

author Alan Dipert
2020-01-14 14:16:30 UTC
committer Alan Dipert
2020-01-14 14:16:30 UTC
parent 121f8dcded28d5c639ee60a2a1754ecfa41b81cf

boot.lisp loading improvements

boot.lisp +0 -10
jacl-tests.js +4 -3
jacl.js +11 -2

diff --git a/boot.lisp b/boot.lisp
index 6b89d64..2c276ce 100644
--- a/boot.lisp
+++ b/boot.lisp
@@ -54,13 +54,3 @@
 (%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*))
-
diff --git a/jacl-tests.js b/jacl-tests.js
index cdd2a58..48370fc 100644
--- a/jacl-tests.js
+++ b/jacl-tests.js
@@ -1,4 +1,5 @@
 QUnit.config.testTimeout = 100; // milliseconds
+QUnit.config.autostart = false;
 
 QUnit.module('Reader');
 
@@ -33,7 +34,7 @@ QUnit.test('Symbols', async is => {
 
   sym = await read1('somesym ');
   is.strictEqual(sym.name, 'SOMESYM', 'simple symbol name');
-  is.strictEqual(sym.packageName, 'JACL', 'simple symbol package');
+  is.strictEqual(sym.packageName, 'COMMON-LISP-USER', 'simple symbol package');
 
   sym = await read1('|Alan| ');
   is.strictEqual(sym.name, 'Alan', 'simple symbol name');
@@ -59,7 +60,7 @@ QUnit.test('Symbols', async is => {
   testPkg1.intern("some symbol")
   sym = await read1('|TEST-PACKAGE1::some symbol| ');
   is.strictEqual(sym.name, 'TEST-PACKAGE1::some symbol', 'pipe/qualified symbol');
-  is.strictEqual(sym.packageName, 'JACL', 'pipe/qualified symbol');
+  is.strictEqual(sym.packageName, 'COMMON-LISP-USER', 'pipe/qualified symbol');
 
   sym = await read1('test-package1::|some symbol| ');
   is.strictEqual(sym.name, 'some symbol', 'pipe/qualified symbol');
@@ -71,7 +72,7 @@ QUnit.test('Symbols', async is => {
 
   sym = await read1("test-package1|::lol| ");
   is.strictEqual(sym.name, 'TEST-PACKAGE1::lol', 'pipe without package');
-  is.strictEqual(sym.packageName, 'JACL', 'pipe without package has default package');
+  is.strictEqual(sym.packageName, 'COMMON-LISP-USER', 'pipe without package has default package');
 
   is.rejects(
     read1('test-package1:|some symbol| ', false),
diff --git a/jacl.js b/jacl.js
index d0c6f03..141ab1d 100644
--- a/jacl.js
+++ b/jacl.js
@@ -1,5 +1,7 @@
 // Sentinel used in a few places to indicate absence of a user-provided value
 const UNDEFINED = new Object();
+// Sentinel used to indicate EOF, should generally be a parameter
+const EOF = new Object();
 
 class TagEx extends Error {
   constructor(name) {
@@ -737,7 +739,9 @@ class Reader {
   async read(internSymbols = true) {
     let macroFun;
     for await(const x of this.stream) {
-      if (isWhitespace(x)) {
+      if (x === EOF) {
+        return EOF;
+      } else if (isWhitespace(x)) {
         continue;
       } else if (macroFun = READTABLE.val().getMacro(x)) {
         const vals = await macroFun(this.stream);
@@ -1944,22 +1948,27 @@ 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 start = new Date();
       const bs = new BufferedStream();
       const rdr = new Reader(bs);
       const code = await (await fetch(child.src)).text();
       bs.writeEach(code);
+      bs.write(EOF);
       for await(const obj of rdr) {
+        if (obj === EOF) break;
         const node = analyze(emptyEnv, null, obj);
         const sb = new StringBuffer();
         emitNode(sb.append.bind(sb), node);
         eval(sb.toString());
       }
+      console.log(`;Loaded ${child.src} in ${(new Date())-start} ms`);
     }
   }
 };
 
-document.addEventListener('DOMContentLoaded', async () => {
+window.addEventListener('load', async () => {
   await loadLispScripts();
+  QUnit.start();
   startRepl();
 });