Changeset 12617


Ignore:
Timestamp:
04/15/10 14:54:55 (13 years ago)
Author:
Mark Evenson
Message:

Move pathname functions to EXT; implement DEFSETF for URL pathnames.

Implemented DEFSETF functions for HOST, AUTHORITY, QUERY, and FRAGMENT
sections of URL pathname.

Moved PATHNAME-JAR-P and PATHNAME-URL-P to EXT.

EXT::%INVALIDATE-NAMESTRING resets the namestring after changing the
internal structure. Having to monkey around with the internal
structure of Pathname is just wrong: we should implement the get/set
accessor pattern in Java even though it would make the code more
verbose.

Location:
trunk/abcl
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/Pathname.java

    r12614 r12617  
    7575        namestring = null;
    7676    }
     77   
     78    // ### %invalidate-namestring
     79    private static final Primitive _INVALIDATE_NAMESTRING = new pf_invalidate_namestring();
     80    private static class pf_invalidate_namestring extends Primitive {
     81        pf_invalidate_namestring() {
     82            super("%invalidate-namestring", PACKAGE_EXT, false);
     83        }
     84        @Override
     85        public LispObject execute(LispObject first) {
     86            ((Pathname)coerceToPathname(first)).invalidateNamestring();
     87            return first;
     88        }
     89    }
    7790
    7891    protected Pathname() {}
     
    16111624    private static class pf_pathname_jar_p extends Primitive {
    16121625        pf_pathname_jar_p() {
    1613             super("pathname-jar-p", PACKAGE_SYS, true, "pathname",
     1626            super("pathname-jar-p", PACKAGE_EXT, true, "pathname",
    16141627                  "Predicate for whether PATHNAME references a JAR.");
    16151628        }
     
    16291642    private static class pf_pathname_url_p extends Primitive {
    16301643        pf_pathname_url_p() {
    1631             super("pathname-url-p", PACKAGE_SYS, true, "pathname",
     1644            super("pathname-url-p", PACKAGE_EXT, true, "pathname",
    16321645                  "Predicate for whether PATHNAME references a URL.");
    16331646        }
  • trunk/abcl/src/org/armedbear/lisp/Symbol.java

    r12607 r12617  
    29212921  public static final Symbol SLIME_OUTPUT_STREAM =
    29222922    PACKAGE_EXT.addExternalSymbol("SLIME-OUTPUT-STREAM");
     2923  public static final Symbol JAR_PATHNAME =
     2924    PACKAGE_EXT.addExternalSymbol("JAR-PATHNAME");
     2925  public static final Symbol URL_PATHNAME =
     2926    PACKAGE_EXT.addExternalSymbol("URL-PATHNAME");
    29232927
    29242928  // MOP.
     
    30663070  public static final Symbol JAVA_STACK_FRAME =
    30673071    PACKAGE_SYS.addInternalSymbol("JAVA-STACK-FRAME");
    3068   public static final Symbol JAR_PATHNAME =
    3069     PACKAGE_SYS.addExternalSymbol("JAR-PATHNAME");
    3070   public static final Symbol URL_PATHNAME =
    3071     PACKAGE_SYS.addExternalSymbol("URL-PATHNAME");
    30723072
    30733073  // CDR6
  • trunk/abcl/src/org/armedbear/lisp/asdf-abcl.lisp

    r12447 r12617  
    4242                                     (c cl-source-file))
    4343  (let ((files (output-files o c)))
    44     (if (every #'sys:pathname-jar-p files)
     44    (if (every #'ext:pathname-jar-p files)
    4545        t
    4646        (call-next-method))))
  • trunk/abcl/src/org/armedbear/lisp/pathnames.lisp

    r12607 r12617  
    434434            :format-control "~S cannot be converted to a pathname."
    435435            :format-arguments (list thing)))))
     436
     437
     438;;; Functions for dealing with URL Pathnames
     439
     440(in-package :extensions)
     441
     442(defun url-pathname-scheme (p)
     443  (unless (pathname-url-p p)
     444    (error "~A is not a URL pathname." p))
     445  (getf (pathname-host p) :scheme))
     446
     447(defun set-url-pathname-scheme (p v)
     448  (unless (pathname-url-p p)
     449    (error "~A is not a URL pathname." p))
     450  (let ((host (pathname-host p)))
     451    (setf (getf host :scheme) v))
     452  (%invalidate-namestring p))
     453
     454(defsetf url-pathname-scheme set-url-pathname-scheme)
     455
     456(defun url-pathname-authority (p)
     457  (unless (pathname-url-p p)
     458    (error "~A is not a URL pathname." p))
     459  (getf (pathname-host p) :authority))
     460
     461(defun set-url-pathname-authority (p v)
     462  (unless (pathname-url-p p)
     463    (error "~A is not a URL pathname." p))
     464  (let ((host (pathname-host p)))
     465    (setf (getf host :authority) v))
     466  (%invalidate-namestring p))
     467
     468(defsetf url-pathname-authority set-url-pathname-authority)
     469
     470(defun url-pathname-query (p)
     471  (unless (pathname-url-p p)
     472    (error "~A is not a URL pathname." p))
     473  (getf (pathname-host p) :query))
     474
     475(defun set-url-pathname-query (p v)
     476  (unless (pathname-url-p p)
     477    (error "~A is not a URL pathname." p))
     478  (let ((host (pathname-host p)))
     479    (setf (getf host :query) v))
     480  (%invalidate-namestring p))
     481
     482(defsetf url-pathname-query set-url-pathname-query)
     483
     484(defun url-pathname-fragment (p)
     485  (unless (pathname-url-p p)
     486    (error "~A is not a URL pathname." p))
     487  (getf (pathname-host p) :fragment))
     488
     489(defun set-url-pathname-fragment (p v)
     490  (unless (pathname-url-p p)
     491    (error "~A is not a URL pathname." p))
     492  (let ((host (pathname-host p)))
     493    (setf (getf host :fragment) v))
     494  (%invalidate-namestring p))
     495
     496(defsetf url-pathname-query set-url-pathname-fragment)
     497
     498(export '(url-pathname-scheme
     499          url-pathname-authority
     500          url-pathname-query
     501          url-pathname-fragment)
     502        'ext)
  • trunk/abcl/test/lisp/abcl/jar-pathname.lisp

    r12616 r12617  
    279279           (d (first (pathname-device p))))
    280280      (values
    281        (system:pathname-url-p d)
     281       (ext:pathname-url-p d)
    282282       (namestring d)
    283283       (pathname-directory p) (pathname-name p) (pathname-type p)))
     
    292292           (d1 (second d)))
    293293      (values
    294        (system:pathname-url-p d0)
     294       (ext:pathname-url-p d0)
    295295       (namestring d0)
    296296       (pathname-name d1) (pathname-type d1)
  • trunk/abcl/test/lisp/abcl/url-pathname.lisp

    r12616 r12617  
    3030  "query=this" 
    3131  "that-fragment")
     32
     33(deftest url-pathname.3
     34    (let* ((p (pathname
     35               "http://example.org/a/b/foo.lisp?query=this#that-fragment")))
     36      (values
     37       (ext:url-pathname-scheme p)
     38       (ext:url-pathname-authority p)
     39       (ext:url-pathname-query p)
     40       (ext:url-pathname-fragment p)))
     41  "http"
     42  "example.org"
     43  "query=this" 
     44  "that-fragment")
Note: See TracChangeset for help on using the changeset viewer.