X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=jscl.lisp;h=e5b658274a21a6c2b54219d893bf9139100f064a;hb=ba8e96ec1d0ab80c668fda471f2acb6ef55c5e61;hp=9a89a5d922ed36d13ca00937ae829ea5f14912f9;hpb=b3be08ae30043a26fbc29877b42dd45aa233b178;p=jscl.git diff --git a/jscl.lisp b/jscl.lisp index 9a89a5d..e5b6582 100644 --- a/jscl.lisp +++ b/jscl.lisp @@ -16,18 +16,32 @@ ;; You should have received a copy of the GNU General Public License ;; along with JSCL. If not, see . +(defpackage :jscl + (:use :cl) + (:export #:bootstrap #:run-tests-in-host)) + +(in-package :jscl) + (defvar *source* - '(("boot" :target) - ("compat" :host) - ("utils" :both) - ("list" :target) - ("string" :target) - ("print" :target) - ("package" :target) - ("ffi" :target) - ("read" :both) - ("compiler" :both) - ("toplevel" :target))) + '(("boot" :target) + ("compat" :host) + ("utils" :both) + ("numbers" :target) + ("char" :target) + ("list" :target) + ("array" :target) + ("string" :target) + ("sequence" :target) + ("print" :target) + ("package" :target) + ("misc" :target) + ("ffi" :both) + ("read" :both) + ("defstruct" :both) + ("lambda-list" :both) + ("backquote" :both) + ("compiler" :both) + ("toplevel" :target))) (defun source-pathname (filename &key (directory '(:relative "src")) (type nil) (defaults filename)) @@ -51,7 +65,7 @@ (load (source-pathname (car input))))) (defun read-whole-file (filename) - (with-open-file (in filename :external-format :latin-1) + (with-open-file (in filename) (let ((seq (make-array (file-length in) :element-type 'character))) (read-sequence seq in) seq))) @@ -66,10 +80,9 @@ with eof-mark = (gensym) for x = (ls-read in nil eof-mark) until (eq x eof-mark) - for compilation = (ls-compile-toplevel x) - when (plusp (length compilation)) - do (write-string compilation out))))) - + do (let ((compilation (ls-compile-toplevel x))) + (when (plusp (length compilation)) + (write-string compilation out))))))) (defun dump-global-environment (stream) (flet ((late-compile (form) @@ -78,7 +91,7 @@ ;; for the compiler and it can be dumped. (dolist (b (lexenv-function *environment*)) (when (eq (binding-type b) 'macro) - (push *magic-unquote-marker* (binding-value b)))) + (setf (binding-value b) `(,*magic-unquote-marker* ,(binding-value b))))) (late-compile `(setq *environment* ',*environment*)) ;; Set some counter variable properly, so user compiled code will ;; not collide with the compiler itself. @@ -93,31 +106,34 @@ (defun bootstrap () - (setq *environment* (make-lexenv)) - (setq *literal-table* nil) - (setq *variable-counter* 0 - *gensym-counter* 0 - *literal-counter* 0) - (with-open-file (out "jscl.js" :direction :output :if-exists :supersede) - (write-string (read-whole-file (source-pathname "prelude.js")) out) - (dolist (input *source*) - (when (member (cadr input) '(:target :both)) - (ls-compile-file (source-pathname (car input) :type "lisp") out))) - (dump-global-environment out)) - ;; Tests - (with-open-file (out "tests.js" :direction :output :if-exists :supersede) - (dolist (input (append (directory "tests.lisp") - (directory "tests/*.lisp") - (directory "tests-report.lisp"))) - (ls-compile-file input out)))) + (let ((*features* (cons :jscl *features*)) + (*package* (find-package "JSCL"))) + (setq *environment* (make-lexenv)) + (setq *literal-table* nil) + (setq *variable-counter* 0 + *gensym-counter* 0 + *literal-counter* 0) + (with-open-file (out "jscl.js" :direction :output :if-exists :supersede) + (write-string (read-whole-file (source-pathname "prelude.js")) out) + (dolist (input *source*) + (when (member (cadr input) '(:target :both)) + (ls-compile-file (source-pathname (car input) :type "lisp") out))) + (dump-global-environment out)) + ;; Tests + (with-open-file (out "tests.js" :direction :output :if-exists :supersede) + (dolist (input (append (directory "tests.lisp") + (directory "tests/*.lisp") + (directory "tests-report.lisp"))) + (ls-compile-file input out))))) ;;; Run the tests in the host Lisp implementation. It is a quick way ;;; to improve the level of trust of the tests. (defun run-tests-in-host () - (load "tests.lisp") - (let ((*use-html-output-p* nil)) - (declare (special *use-html-output-p*)) - (dolist (input (directory "tests/*.lisp")) - (load input))) - (load "tests-report.lisp")) + (let ((*package* (find-package "JSCL"))) + (load "tests.lisp") + (let ((*use-html-output-p* nil)) + (declare (special *use-html-output-p*)) + (dolist (input (directory "tests/*.lisp")) + (load input))) + (load "tests-report.lisp")))