diff --git a/books/bookvol9.pamphlet b/books/bookvol9.pamphlet index ad6b13e..0e11cf4 100644 --- a/books/bookvol9.pamphlet +++ b/books/bookvol9.pamphlet @@ -1228,15 +1228,15 @@ REREAD (cond ((initial-substring ")if" line) (if (eval (|string2BootTree| (storeblanks line 3))) - (preparseReadLine X) + (preparseReadLine x) (skip-ifblock x))) ((initial-substring ")elseif" line) (skip-to-endif x)) ((initial-substring ")else" line) (skip-to-endif x)) ((initial-substring ")endif" line) (preparseReadLine x)) ((initial-substring ")fin" line) (setq *eof* t) - (cons ind nil)))) - (t (cons ind line))))) + (cons ind nil))))) + (cons ind line))) @ @@ -1274,6 +1274,91 @@ REREAD @ +\section{Line Handling} + +\defun{storeblanks}{storeblanks} +<>= +(defun storeblanks (line n) + (do ((i 0 (1+ i))) + ((= i n) line) + (setf (char line i) #\ ))) + +@ + +\defun{initial-substring}{initial-substring} +\calls{initial-substring}{mismatch} +<>= +(defun initial-substring (pattern line) + (let ((ind (mismatch pattern line))) + (or (null ind) (eql ind (size pattern))))) + +@ + +\defun{atEndOfUnit}{atEndOfUnit} +<>= +(defun atEndOfUnit (x) + (null (stringp x))) + +@ + +\defun{get-a-line}{get-a-line} +\calls{get-a-line}{is-console} +\calls{get-a-line}{mkprompt} +\calls{get-a-line}{read-a-line} +\calls{get-a-line}{make-string-adjustable} +<>= +(defun get-a-line (stream) + (when (is-console stream) (princ (mkprompt))) + (let ((ll (read-a-line stream))) + (if (stringp ll) + (make-string-adjustable ll) + ll))) + +@ + +<>= +(defparameter Current-Fragment nil + "A string containing remaining chars from readline; needed because +Symbolics read-line returns embedded newlines in a c-m-Y.") + +@ + +\defun{read-a-line}{read-a-line} +\calls{read-a-line}{subseq} +\calls{read-a-line}{Line-New-Line} +\calls{read-a-line}{read-a-line} +\uses{read-a-line}{*eof*} +<>= +(defun read-a-line (&optional (stream t)) + (let (cp) + (declare (special *eof*)) + (if (and Current-Fragment (> (length Current-Fragment) 0)) + (let ((line (with-input-from-string + (s Current-Fragment :index cp :start 0) + (read-line s nil nil)))) + (setq Current-Fragment (subseq Current-Fragment cp)) + line) + (prog nil + (when (stream-eof in-stream) + (setq File-Closed t) + (setq *eof* t) + (Line-New-Line (make-string 0) Current-Line) + (return nil)) + (when (setq Current-Fragment (read-line stream)) + (return (read-a-line stream))))))) + +@ + +\defun{make-string-adjustable}{make-string-adjustable} +<>= +(defun make-string-adjustable (s) + (if (adjustable-array-p s) + s + (make-array (array-dimensions s) :element-type 'string-char + :adjustable t :initial-contents s))) + +@ + \chapter{The Compiler} \section{Compiling EQ.spad} @@ -4333,6 +4418,8 @@ if \verb|$InteractiveMode| then use a null outputstream <> <> +<> + <> <> <> @@ -4376,10 +4463,14 @@ if \verb|$InteractiveMode| then use a null outputstream <> +<> + <> <> +<> +<> <> <> @@ -4390,12 +4481,14 @@ if \verb|$InteractiveMode| then use a null outputstream <> <> +<> <> <> <> <> <> +<> <> @ diff --git a/changelog b/changelog index 2406dc5..a3b3278 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +20101002 tpd src/axiom-website/patches.html 20101002.01.tpd.patch +20101002 tpd src/interp/parsing.lisp treeshake compiler +20101002 tpd books/bookvol9 treeshake compiler 20101001 tpd src/axiom-website/patches.html 20101001.02.tpd.patch 20101001 tpd src/interp/parsing.lisp treeshake compiler 20101001 tpd books/bookvol9 treeshake compiler diff --git a/src/axiom-website/patches.html b/src/axiom-website/patches.html index 70211a3..517713b 100644 --- a/src/axiom-website/patches.html +++ b/src/axiom-website/patches.html @@ -3176,5 +3176,7 @@ books/bookvol9.pamphlet treeshake compiler
src/interp/parsing.lisp cleanup and reformat
20101001.02.tpd.patch books/bookvol9 treeshake compiler
+20101002.01.tpd.patch +books/bookvol9 treeshake compiler
diff --git a/src/interp/parsing.lisp.pamphlet b/src/interp/parsing.lisp.pamphlet index 6b1d2ff..9208fca 100644 --- a/src/interp/parsing.lisp.pamphlet +++ b/src/interp/parsing.lisp.pamphlet @@ -571,41 +571,8 @@ can be shoved back on the input stream (to the current line) with Unget-Tokens. (defun next-line (&optional (in-stream t)) (funcall Line-Handler in-stream)) -(defun make-string-adjustable (s) - (if (adjustable-array-p s) - s - (make-array (array-dimensions s) :element-type 'string-char - :adjustable t :initial-contents s))) - -(defun get-a-line (stream) - (when (is-console stream) (princ (mkprompt))) - (let ((ll (read-a-line stream))) - (if (stringp ll) - (make-string-adjustable ll) - ll))) - -(defparameter Current-Fragment nil - "A string containing remaining chars from readline; needed because -Symbolics read-line returns embedded newlines in a c-m-Y.") - (defun input-clear () (setq Current-Fragment nil)) -(defun read-a-line (&optional (stream t)) - (let (cp) - (if (and Current-Fragment (> (length Current-Fragment) 0)) - (let ((line (with-input-from-string - (s Current-Fragment :index cp :start 0) - (read-line s nil nil)))) - (setq Current-Fragment (subseq Current-Fragment cp)) - line) - (prog nil - (when (stream-eof in-stream) - (setq File-Closed t *EOF* t) - (Line-New-Line (make-string 0) Current-Line) - (return nil)) - (when (setq Current-Fragment (read-line stream)) - (return (read-a-line stream))))))) - (defparameter Printer-Line-Stack (make-stack) "Stack of output listing lines waiting to print. [local to PRINT-NEW-LINE]") @@ -3261,13 +3228,6 @@ preparse (dolist (X L) (format t "~5d. ~a~%" (car x) (cdr x))) (format t "~%")))) -(DEFUN STOREBLANKS (LINE N) - (DO ((I 0 (1+ I))) ((= I N) LINE) (SETF (CHAR LINE I) #\ ))) - -(DEFUN INITIAL-SUBSTRING (PATTERN LINE) - (let ((ind (mismatch PATTERN LINE))) - (OR (NULL IND) (EQL IND (SIZE PATTERN))))) - (DEFUN SKIP-IFBLOCK (X) (PROG (LINE IND) (DCQ (IND . LINE) (preparseReadLine1 X)) @@ -3300,52 +3260,6 @@ preparse ((INITIAL-SUBSTRING LINE ")fin") (RETURN (CONS IND NIL))) ('T (RETURN (SKIP-TO-ENDIF X)))))) -(DEFUN preparseReadLine (X) - (PROG (LINE IND) - (DCQ (IND . LINE) (preparseReadLine1 X)) - (COND ((NOT (STRINGP LINE)) (RETURN (CONS IND LINE)))) - (COND ((ZEROP (SIZE LINE)) - (RETURN (CONS IND LINE)))) - (COND ((CHAR= (ELT LINE 0) #\) ) - (COND - ((INITIAL-SUBSTRING ")if" LINE) - (COND ((EVAL (|string2BootTree| (STOREBLANKS LINE 3))) - (RETURN (preparseReadLine X))) - ('T (RETURN (SKIP-IFBLOCK X))))) - ((INITIAL-SUBSTRING ")elseif" LINE) - (RETURN (SKIP-TO-ENDIF X))) - ((INITIAL-SUBSTRING ")else" LINE) - (RETURN (SKIP-TO-ENDIF X))) - ((INITIAL-SUBSTRING ")endif" LINE) - (RETURN (preparseReadLine X))) - ((INITIAL-SUBSTRING ")fin" LINE) - (SETQ *EOF* T) - (RETURN (CONS IND NIL)) ) ))) - (RETURN (CONS IND LINE)) )) - -(DEFUN preparseReadLine1 (X) - (PROG (LINE IND) - (SETQ LINE (if $LINELIST - (pop $LINELIST) - (expand-tabs (get-a-line in-stream)))) - (setq $preparse-last-line LINE) - (and (stringp line) (incf $INDEX)) - (COND - ( (NOT (STRINGP LINE)) - (RETURN (CONS $INDEX LINE)) ) ) - (SETQ LINE (DROPTRAILINGBLANKS LINE)) - (PUSH (COPY-SEQ LINE) $EchoLineStack) - ;; next line must evaluate $INDEX before recursive call - (RETURN - (CONS - $INDEX - (COND - ( (AND (> (SETQ IND (MAXINDEX LINE)) -1) (char= (ELT LINE IND) #\_)) - (setq $preparse-last-line - (STRCONC (SUBSTRING LINE 0 IND) (CDR (preparseReadLine1 X))) )) - ( 'T - LINE ) ))) ) ) - (defun PREPARSE-ECHO (linelist) (if Echo-Meta (REPEAT (IN X (REVERSE $EchoLineStack)) (format out-stream "~&;~A~%" X))) @@ -3353,8 +3267,6 @@ preparse (defun ESCAPED (STR N) (and (> N 0) (EQ (CHAR STR (1- N)) XCAPE))) -(defun atEndOfUnit (X) (NULL (STRINGP X)) ) - (defun PARSEPILES (LOCS LINES) "Add parens and semis to lines to aid parsing." (mapl #'add-parens-and-semis-to-line (NCONC LINES '(" ")) (nconc locs '(nil)))