author | Alan Dipert
<alan@dipert.org> 2020-02-24 03:59:54 UTC |
committer | Alan Dipert
<alan@dipert.org> 2020-02-24 03:59:54 UTC |
parent | 5c20c4569decaf926cb3c3e7a30949818f559dc0 |
boot.lisp | +42 | -43 |
index.html | +4 | -2 |
jacl-tests.lisp | +49 | -0 |
jacl.js | +2 | -2 |
diff --git a/boot.lisp b/boot.lisp index be5f2f0..b06b4af 100644 --- a/boot.lisp +++ b/boot.lisp @@ -181,49 +181,48 @@ (defmacro lambda (params &rest body) `(jacl:%lambda ,params ,@body)) -(defun %designated-string (x) - (cond ((stringp x) x) - ((symbolp x) - (jacl:\. (jacl:%js "LispString") (|fromString| (jacl:\. x |name|)))) - (t (%type-error "string or symbol")))) - -(defun %designated-symbols (x) - (cond ((symbolp x) (list x)) - ((listp x) x) - (t (%type-error "symbol or list of symbols")))) - -(%export 'let*) -(defmacro let* (bindings &rest body) - (if bindings - `(let (,(car bindings)) - (let* ,(cdr bindings) - ,@body)) - `(progn ,@body))) - -(%export 'function) -(defmacro function (x) - `(jacl:%js "~{}.func()" x)) - -(%export 'functionp) -(defun functionp (x) - (jacl:%js "~{} instanceof Function ? true : null" x)) - -(%export 'funcall) -(defun funcall (f &rest args) - (when (not (functionp f)) - (%type-error "function")) - (jacl:%js "~{}.call(null, List.toArray(~{}))" f args)) - -;; TODO -(%export 'export) -(defun export (symbols &optional (package *package*)) - (let ((syms (designated-symbols symbols))) - (tagbody - start - (when syms - (%export (car syms) package) - (jacl:%setq syms (cdr syms)) - (go start))))) +;;(defun %designated-string (x) +;; (cond ((stringp x) x) +;; ((symbolp x) +;; (jacl:\. (jacl:%js "LispString") (|fromString| (jacl:\. x |name|)))) +;; (t (%type-error "string or symbol")))) +;; +;;(defun %designated-symbols (x) +;; (cond ((symbolp x) (list x)) +;; ((listp x) x) +;; (t (%type-error "symbol or list of symbols")))) +;; +;;(%export 'let*) +;;(defmacro let* (bindings &rest body) +;; (if bindings +;; `(let (,(car bindings)) +;; (let* ,(cdr bindings) +;; ,@body)) +;; `(progn ,@body))) +;; +;;(%export 'function) +;;(defmacro function (x) +;; `(jacl:%js "~{}.func()" x)) +;; +;;(%export 'functionp) +;;(defun functionp (x) +;; (jacl:%js "~{} instanceof Function ? true : null" x)) +;; +;;(%export 'funcall) +;;(defun funcall (f &rest args) +;; (when (not (functionp f)) +;; (%type-error "function")) +;; (jacl:%js "~{}.call(null, List.toArray(~{}))" f args)) +;; +;;(%export 'export) +;;(defun export (symbols &optional (package *package*)) +;; (let ((syms (designated-symbols symbols))) +;; (tagbody +;; start +;; (when syms +;; (%export (car syms) package) +;; (jacl:%setq syms (cdr syms)) +;; (go start))))) ;; Use COMMON-LISP from COMMON-LISP-USER and switch to ;; COMMON-LISP-USER diff --git a/index.html b/index.html index 2e083ff..0fd7ee5 100644 --- a/index.html +++ b/index.html @@ -13,11 +13,13 @@ } } </style> - <script src="qunit-2.9.2.js"></script> <script src="jacl.js"></script> - <!--<script src="jacl-tests.js"></script>--> <script type="application/lisp" src="boot.lisp"></script> <script type="application/lisp" src="jacl-tests.lisp"></script> + <script src="qunit-2.9.2.js"></script> + <script type="text/javascript"> + QUnit.config.autostart = false; + </script> </head> <body> <div id="qunit"></div> diff --git a/jacl-tests.lisp b/jacl-tests.lisp new file mode 100644 index 0000000..8c6994c --- /dev/null +++ b/jacl-tests.lisp @@ -0,0 +1,49 @@ +(jacl:enable-js-syntax) + +(let* ((jpkg (jacl:\. (jacl:%js "Package") (|get| @"JACL")))) + (jacl:\. *package* (|usePackage| jpkg))) + +(\. @|QUnit.config.testTimeout| (= 100)) +(\. @|QUnit.config.autoStart| (= js:+false+)) + +(defun read1 (s) + (\. (%new @|Reader| (%new @|StringStream| s)) (|read|))) + +(\. @|QUnit| (|module| @"Reader")) + +(defmacro deftest (name is &rest body) + `(\. @|QUnit| (|test| + (\. ,name (|toString|)) + (lambda (,is) + (declare (async)) + ,@body)))) + +(deftest @"Integers" is + (\. is (|strictEqual| @@(read1 @"123 ") 123 @"single integer")) + (\. is (|strictEqual| @@(read1 @"+9912 ") 9912 @"integer with leading +")) + (\. is (|strictEqual| @@(read1 @"0 ") 0 @"zero")) + (\. is (|strictEqual| @@(read1 @"-32 ") -32 @"negative number")) + (\. is (|strictEqual| @@(read1 @"1. ") 1. @"number with trailing dot"))) + +(deftest @"Symbols" is + (let ((sym @@(read1 @"somesym "))) + (\. is (|strictEqual| (\. sym |name|) @"SOMESYM" @"simple symbol name")) + )) + +(\. @|QUnit| (|start|)) + + + + +;;(jacl:\. *package* +;; (|usePackage| (jacl:\. (jacl:%js "Package") (|get| )))) +;;(let* ((x 1) +;; (y (1+ x))) +;; (jacl:\. (jacl:%js "console") (|log| x y))) +;;(let* ((pkg (jacl:%js "Package")) +;; (jacl-pkg (jacl:\. pkg (|get| "JACL")))) +;; (jacl:\. (jacl:%js "console") (|log| jacl-pkg)) +;; (jacl:\. *package* (|usePackage| jacl-pkg)) +;; ) +;; +;;(\. (%js "console") (|log| *package*)) diff --git a/jacl.js b/jacl.js index 0daadd3..27e5c35 100644 --- a/jacl.js +++ b/jacl.js @@ -2133,7 +2133,7 @@ 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 code = await (await fetch(child.src)).text(); + const code = await (await fetch(child.src, {cache: "reload"})).text(); const start = new Date(); const ss = new StringStream(code); const rdr = new Reader(ss); @@ -2151,6 +2151,6 @@ const loadLispScripts = async () => { window.addEventListener('load', async () => { await loadLispScripts(); - QUnit.start(); + //QUnit.start(); await startRepl(); });