*features* support for the reader
authorDavid Vázquez <davazp@gmail.com>
Wed, 8 May 2013 21:43:02 +0000 (22:43 +0100)
committerDavid Vázquez <davazp@gmail.com>
Wed, 8 May 2013 21:43:02 +0000 (22:43 +0100)
jscl.lisp
src/compiler.lisp
src/lambda-list.lisp
src/read.lisp
src/utils.lisp

index 01f75c6..5e393d6 100644 (file)
--- a/jscl.lisp
+++ b/jscl.lisp
 
 
 (defun bootstrap ()
-  (let ((*package* (find-package "JSCL")))
+  (let ((*features* (cons :jscl *features*))
+        (*package* (find-package "JSCL")))
     (setq *environment* (make-lexenv))
     (setq *literal-table* nil)
     (setq *variable-counter* 0
index 61c57a4..4a27413 100644 (file)
@@ -68,7 +68,7 @@
         (incf index))
       output)))
 
-#+common-lisp
+#-jscl
 (defun indent (&rest string)
   (with-output-to-string (*standard-output*)
     (with-input-from-string (input (apply #'code string))
 ;;; evaluated. For this reason we define a valid macro-function for
 ;;; this symbol.
 (defvar *magic-unquote-marker* (gensym "MAGIC-UNQUOTE"))
-#+common-lisp
+#-jscl
 (setf (macro-function *magic-unquote-marker*)
       (lambda (form &optional environment)
         (declare (ignore environment))
   (code "l" (incf *literal-counter*)))
 
 (defun dump-symbol (symbol)
-  #+common-lisp
+  #-jscl
   (let ((package (symbol-package symbol)))
     (if (eq package (find-package "KEYWORD"))
         (code "(new Symbol(" (dump-string (symbol-name symbol)) ", " (dump-string (package-name package)) "))")
             `(%js-vref ,var))))
 
 
-#+common-lisp
+#-jscl
 (defvar *macroexpander-cache*
   (make-hash-table :test #'eq))
 
     (if (and b (eq (binding-type b) 'macro))
         (let ((expander (binding-value b)))
           (cond
-            #+common-lisp
+            #-jscl
             ((gethash b *macroexpander-cache*)
              (setq expander (gethash b *macroexpander-cache*)))
             ((listp expander)
                ;; function with the compiled one.
                ;;
                #+jscl (setf (binding-value b) compiled)
-               #+common-lisp (setf (gethash b *macroexpander-cache*) compiled)
+               #-jscl (setf (gethash b *macroexpander-cache*) compiled)
                (setq expander compiled))))
           expander)
         nil)))
        (concat (translate-function function) arglist))
       ((and (symbolp function)
             #+jscl (eq (symbol-package function) (find-package "COMMON-LISP"))
-            #+common-lisp t)
+            #-jscl t)
        (code (ls-compile `',function) ".fvalue" arglist))
       (t
        (code (ls-compile `#',function) arglist)))))
index d706d50..34f7419 100644 (file)
 ;;; defmacro to avoid a circularity. So just define the macro function
 ;;; explicitly.
 
-#+common-lisp
+#-jscl
 (defmacro !destructuring-bind (lambda-list expression &body body)
   (apply #'!expand-destructuring-bind lambda-list expression body))
 
index c3cde1b..3c15f9d 100644 (file)
            ((string= cname "tab") #\tab)
            ((string= cname "newline") #\newline)
            (t (char cname 0)))))
-      ((char= ch #\+)
+      ((or (char= ch #\+)
+           (char= ch #\-))
        (let ((feature (let ((symbol (ls-read stream eof-error-p eof-value t)))
                         (unless (symbolp symbol)
                           (error "Invalid feature ~S" symbol))
                         (intern (string symbol) "KEYWORD"))))
-         (ecase feature
-           (:common-lisp
-              (ls-read stream)
-              (ls-read stream eof-error-p eof-value t))
-           (:jscl
-              (ls-read stream eof-error-p eof-value t))
-           (:nil
-              (ls-read stream)
-              (ls-read stream eof-error-p eof-value t)))))
+         (if (eql (char= ch #\+)
+                  (and (find feature *features*) t))
+              (ls-read stream eof-error-p eof-value t)
+              (prog2 (ls-read stream)
+                  (ls-read stream eof-error-p eof-value t)))))
       ((and ch (digit-char-p ch))
        (let ((id (digit-char-p ch)))
          (while (and (%peek-char stream)
index d586cdd..430b6a7 100644 (file)
@@ -83,4 +83,4 @@
 
 (defun float-to-string (x)
   #+jscl (float-to-string x)
-  #+common-lisp (format nil "~f" x))
+  #-jscl (format nil "~f" x))