X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcode%2Fsharpm.lisp;h=f091b65cbec0223627593731978c71052b0962e8;hb=5e291412ff095a2016388eee8ac265e12d565119;hp=63e88d1d5acd51c92e5d8279753d216094d37e4c;hpb=22b8c6a91a89d0710db10e88f76ce0f2a245905d;p=sbcl.git diff --git a/src/code/sharpm.lisp b/src/code/sharpm.lisp index 63e88d1..f091b65 100644 --- a/src/code/sharpm.lisp +++ b/src/code/sharpm.lisp @@ -119,18 +119,54 @@ (%reader-error stream "non-list following #S: ~S" body)) (unless (symbolp (car body)) (%reader-error stream "Structure type is not a symbol: ~S" (car body))) - (let ((class (sb!xc:find-class (car body) nil))) - (unless (typep class 'sb!xc:structure-class) + (let ((classoid (find-classoid (car body) nil))) + (unless (typep classoid 'structure-classoid) (%reader-error stream "~S is not a defined structure type." (car body))) (let ((def-con (dd-default-constructor (layout-info - (class-layout class))))) + (classoid-layout classoid))))) (unless def-con (%reader-error stream "The ~S structure does not have a default constructor." (car body))) - (apply (fdefinition def-con) (rest body)))))) + (when (and (atom (rest body)) + (not (null (rest body)))) + (%reader-error + stream "improper list for #S: ~S." body)) + (apply (fdefinition def-con) + (loop for tail on (rest body) by #'cddr + with slot-name = (and (consp tail) (car tail)) + do (progn + (when (null (cdr tail)) + (%reader-error + stream + "the arglist for the ~S constructor in #S ~ + has an odd length: ~S." + (car body) (rest body))) + (when (or (atom (cdr tail)) + (and (atom (cddr tail)) + (not (null (cddr tail))))) + (%reader-error + stream + "the arglist for the ~S constructor in #S ~ + is improper: ~S." + (car body) (rest body))) + (when (not (typep (car tail) 'string-designator)) + (%reader-error + stream + "a slot name in #S is not a string ~ + designator: ~S." + slot-name)) + (when (not (keywordp slot-name)) + (warn 'structure-initarg-not-keyword + :format-control + "in #S ~S, the use of non-keywords ~ + as slot specifiers is deprecated: ~S." + :format-arguments + (list (car body) slot-name)))) + collect (intern (string (car tail)) *keyword-package*) + collect (cadr tail))))))) ;;;; reading numbers: the #B, #C, #O, #R, and #X readmacros @@ -184,7 +220,8 @@ ;; substitutes in arrays and structures as well as lists. The first arg is an ;; alist of the things to be replaced assoc'd with the things to replace them. (defun circle-subst (old-new-alist tree) - (cond ((not (typep tree '(or cons (array t) structure-object standard-object))) + (cond ((not (typep tree + '(or cons (array t) structure-object standard-object))) (let ((entry (find tree old-new-alist :key #'second))) (if entry (third entry) tree))) ((null (gethash tree *sharp-equal-circle-table*)) @@ -313,35 +350,41 @@ (defun sharp-vertical-bar (stream sub-char numarg) (ignore-numarg sub-char numarg) - (let ((stream (in-synonym-of stream))) - (if (ansi-stream-p stream) - (prepare-for-fast-read-char stream + (handler-bind + ((character-decoding-error + #'(lambda (decoding-error) + (declare (ignorable decoding-error)) + (style-warn "Character decoding error in a #|-comment at position ~A reading source file ~A, resyncing." (file-position stream) stream) + (invoke-restart 'attempt-resync)))) + (let ((stream (in-synonym-of stream))) + (if (ansi-stream-p stream) + (prepare-for-fast-read-char stream + (do ((level 1) + (prev (fast-read-char) char) + (char (fast-read-char) (fast-read-char))) + (()) + (cond ((and (char= prev #\|) (char= char #\#)) + (setq level (1- level)) + (when (zerop level) + (done-with-fast-read-char) + (return (values))) + (setq char (fast-read-char))) + ((and (char= prev #\#) (char= char #\|)) + (setq char (fast-read-char)) + (setq level (1+ level)))))) + ;; fundamental-stream (do ((level 1) - (prev (fast-read-char) char) - (char (fast-read-char) (fast-read-char))) + (prev (read-char stream t) char) + (char (read-char stream t) (read-char stream t))) (()) (cond ((and (char= prev #\|) (char= char #\#)) (setq level (1- level)) (when (zerop level) - (done-with-fast-read-char) (return (values))) - (setq char (fast-read-char))) + (setq char (read-char stream t))) ((and (char= prev #\#) (char= char #\|)) - (setq char (fast-read-char)) - (setq level (1+ level)))))) - ;; fundamental-stream - (do ((level 1) - (prev (read-char stream t) char) - (char (read-char stream t) (read-char stream t))) - (()) - (cond ((and (char= prev #\|) (char= char #\#)) - (setq level (1- level)) - (when (zerop level) - (return (values))) - (setq char (read-char stream t))) - ((and (char= prev #\#) (char= char #\|)) - (setq char (read-char stream t)) - (setq level (1+ level)))))))) + (setq char (read-char stream t)) + (setq level (1+ level))))))))) ;;;; a grab bag of other sharp readmacros: #', #:, and #.