From a819b141b8133f2d9241edfde3878a45cf6c2642 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20V=C3=A1zquez?= Date: Wed, 19 Feb 2014 02:48:57 +0100 Subject: [PATCH] Rewrite the REPL in Lisp using FFI --- jscl.html | 109 ++------------------------------------------ src/compiler/compiler.lisp | 3 -- src/stream.lisp | 3 ++ src/toplevel.lisp | 35 ++++++++++---- tests-report.lisp | 2 + tests.html | 66 +-------------------------- tests.lisp | 3 +- 7 files changed, 37 insertions(+), 184 deletions(-) diff --git a/jscl.html b/jscl.html index ade16ec..4e29546 100644 --- a/jscl.html +++ b/jscl.html @@ -1,116 +1,13 @@ - + -
- - + + diff --git a/src/compiler/compiler.lisp b/src/compiler/compiler.lisp index 1ea5259..222f660 100644 --- a/src/compiler/compiler.lisp +++ b/src/compiler/compiler.lisp @@ -1155,9 +1155,6 @@ (define-builtin functionp (x) `(bool (=== (typeof ,x) "function"))) -(define-builtin %write-string (x) - `(method-call |lisp| "write" ,x)) - (define-builtin /debug (x) `(method-call |console| "log" (call |xstring| ,x))) diff --git a/src/stream.lisp b/src/stream.lisp index 086b145..d08f52c 100644 --- a/src/stream.lisp +++ b/src/stream.lisp @@ -21,6 +21,9 @@ (/debug "loading stream.lisp!") +(defun %write-string (string) + (#j:jqconsole:Write string "jqconsole-output")) + (defvar *standard-output* (vector 'stream (lambda (ch) (%write-string (string ch))) diff --git a/src/toplevel.lisp b/src/toplevel.lisp index 7dddf6e..3c38003 100644 --- a/src/toplevel.lisp +++ b/src/toplevel.lisp @@ -252,14 +252,29 @@ (defvar *root* (%js-vref "window")) -;;; Set some external entry point to the Lisp implementation to the -;;; console. It would not be necessary when FFI is finished. -(let ((*root* #j:lisp)) - (setf #j:read #'ls-read-from-string) - (setf #j:print #'prin1-to-string) - (setf #j:eval #'eval) - (setf #j:compile (lambda (s) (compile-toplevel s t))) - (setf #j:evalString (lambda (str) (eval (ls-read-from-string str)))) - (setf #j:evalInput (lambda (str) (eval-interactive (ls-read-from-string str)))) - (setf #j:compileString (lambda (str) (compile-toplevel (ls-read-from-string str) t)))) +(defun load-history () + (#j:jqconsole:SetHistory (#j:JSON:parse (#j:localStorage:getItem "jqhist")))) + +(defun save-history () + (#j:localStorage:setItem "jqhist" (#j:JSON:stringify (#j:jqconsole:GetHistory)))) + +(defun toplevel () + (let ((prompt (format nil "~a> " (package-name *package*)))) + (#j:jqconsole:Write prompt "jqconsole-prompt")) + (flet ((process-input (input) + (let* ((form (read-from-string input)) + (result (multiple-value-list (eval-interactive form)))) + (dolist (x result) + (#j:jqconsole:Write (format nil "~S~%" x) "jqconsole-return")) + (save-history)) + (toplevel))) + (#j:jqconsole:Prompt t #'process-input))) + + +(defun init (&rest args) + (#j:jqconsole:RegisterMatching "(" ")" "parents") + (load-history) + (toplevel)) + +(#j:window:addEventListener "load" #'init) diff --git a/tests-report.lisp b/tests-report.lisp index 19a95a7..1b44496 100644 --- a/tests-report.lisp +++ b/tests-report.lisp @@ -10,3 +10,5 @@ (unless (zerop *unexpected-passes*) (format t "~a test(s) passed unexpectedly.~%" *unexpected-passes*)) + +(terpri) diff --git a/tests.html b/tests.html index 92a5f13..b814558 100644 --- a/tests.html +++ b/tests.html @@ -1,76 +1,14 @@ - +
+ - diff --git a/tests.lisp b/tests.lisp index a09ee75..1eca341 100644 --- a/tests.lisp +++ b/tests.lisp @@ -41,5 +41,6 @@ (defmacro test-equal (form value) `(test (equal ,form, value))) -(format t "Running tests...~%~%") (setq *timestamp* (get-internal-real-time)) + +(terpri) -- 1.7.10.4