aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ChangeLog16
-rw-r--r--src/interp/parsing.lisp34
-rw-r--r--src/interp/preparse.lisp6
-rw-r--r--src/interp/spad-parser.boot51
-rw-r--r--src/interp/spad.lisp19
5 files changed, 56 insertions, 70 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index ba620358..9124b020 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,21 @@
2012-05-07 Gabriel Dos Reis <gdr@cs.tamu.edu>
+ * interp/spad.lisp (INIT-BOOT/SPAD-READER): Don't set FILE-CLOSED.
+ (SPAD): Tidy.
+ * interp/spad-parser.boot (parseSpadFile): Do not test for *EOF*
+ or FILE-CLOSED.
+ * interp/preparse.lisp (INITIALIZED-PREPARSE): Use readLine.
+ (preparseReadLine1): Likewise.
+ * interp/parsing.lisp (FILE-CLOSED): Remove.
+ (GET-A-LINE): Likewise.
+ (CURRENT-FRAGMENT): Likewise.
+ (INPUT-CLEAR): Likewise.
+ (READ-A-LINE): Likewise.
+ (IOSTREAMS-CLEAR): Don't set FILE-CLOSED.
+ (IOCLEAR): Don't call INPUT-CLEAR.
+
+2012-05-07 Gabriel Dos Reis <gdr@cs.tamu.edu>
+
* interp/vmlisp.lisp (ioTerminal?): Rename form IS-CONSOLE.
* interp/bootlex.lisp: Adjust.
* interp/diagnostics.boot: Likewise.
diff --git a/src/interp/parsing.lisp b/src/interp/parsing.lisp
index 66b4598e..6e30ab91 100644
--- a/src/interp/parsing.lisp
+++ b/src/interp/parsing.lisp
@@ -74,7 +74,6 @@
(MAKEPROP 'END_UNIT 'KEY 'T)
(defparameter out-stream t "Current output stream.")
-(defparameter File-Closed nil "Way to stop EOF tests for console input.")
(defun Line-Print (line)
(format out-stream "~&~5D> ~A~%" (|lineNumber| line) (|lineBuffer| Line))
@@ -85,18 +84,6 @@
(t (make-array (array-dimensions s) :element-type 'character
:adjustable t :initial-contents s))))
-(defun get-a-line (stream)
- (if (and (|ioTerminal?| stream) (not |$leanMode|))
- (|printPrompt|))
- (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 Next-Lines-Clear () (setq |$lineStack| nil))
(defun Next-Lines-Show ()
@@ -124,22 +111,6 @@ Symbolics read-line returns embedded newlines in a c-m-Y.")
(defmacro current-line-clear () `(|lineClear!| |$spadLine|))
-(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
- (if (stream-eof in-stream)
- (progn (setq File-Closed t *EOF* t)
- (|lineNewLine!| (make-string 0) |$spadLine|)
- (return nil)))
- (if (setq Current-Fragment (read-line stream))
- (return (read-a-line stream)))))))
-
; *** Print New Line
(defparameter Printer-Line-Stack (|makeStack|)
@@ -199,14 +170,14 @@ Symbolics read-line returns embedded newlines in a c-m-Y.")
(format t "~&Input is coming from ~A, and output is going to ~A.~%"
(or (streamp in-stream) "the keyboard")
(or (streamp out-stream) "the screen"))
- (format t "~:[~;The current input stream is logically closed.~%~]~%" File-Closed))
+ (format t "~:[~;The current input stream is logically closed.~%~]~%"
+ (|eof?| in-stream)))
(defmacro IOStreams-Set (input output) `(setq in-stream ,input out-stream ,output))
(defmacro IOStreams-Clear (&optional (in t) (out t))
`(progn (and (streamp in-stream) (close in-stream))
(and (streamp out-stream) (close out-stream))
- (setq File-Closed nil)
(IOStreams-Set ,in ,out)))
; 2B. Routines for applying certain metagrammatical elements
@@ -580,7 +551,6 @@ the stack, then stack a NIL. Return the value of prod."
(defun IOClear (&optional (in t) (out t))
;(IOStreams-clear in out)
- (input-clear)
(current-line-clear)
(|tokenStackClear!|)
(|reduceStackClear|)
diff --git a/src/interp/preparse.lisp b/src/interp/preparse.lisp
index d3585cea..bab9621c 100644
--- a/src/interp/preparse.lisp
+++ b/src/interp/preparse.lisp
@@ -76,7 +76,7 @@
(defun Initialize-Preparse (strm)
(setq $INDEX 0 $LineList nil $EchoLineStack nil)
- (setq $preparse-last-line (get-a-line strm)))
+ (setq $preparse-last-line (|readLine| strm)))
(defvar $skipme)
@@ -223,12 +223,12 @@
(PROG (LINE IND)
(SETQ LINE (if $LINELIST
(pop $LINELIST)
- (expand-tabs (get-a-line in-stream))))
+ (expand-tabs (|readLine| in-stream))))
(setq $preparse-last-line LINE)
(and (stringp line) (incf $INDEX))
(COND
( (NOT (STRINGP LINE))
- (RETURN (CONS $INDEX LINE)) ) )
+ (RETURN (LIST $INDEX)) ) )
(SETQ LINE (DROPTRAILINGBLANKS LINE))
(PUSH (COPY-SEQ LINE) $EchoLineStack)
;; next line must evaluate $INDEX before recursive call
diff --git a/src/interp/spad-parser.boot b/src/interp/spad-parser.boot
index 454b7a25..d0ace700 100644
--- a/src/interp/spad-parser.boot
+++ b/src/interp/spad-parser.boot
@@ -85,44 +85,42 @@ stringPrefix?(s1,s2) ==
n1 > #s2 => false
and/[s1.i = s2.i for i in 0..(n1-1)]
-skipIfBlock st ==
- [n,:line] := z := preparseReadLine1 st
+skipIfBlock x ==
+ [n,:line] := z := preparseReadLine1 x
not string? line => z
- #line = 0 => skipIfBlock st
+ #line = 0 => skipIfBlock x
line.0 = char ")" =>
stringPrefix?('")if",line) =>
- EVAL string2BootTree storeBlanks!(line,2) => preparseReadLine st
- skipIfBlock st
+ EVAL string2BootTree storeBlanks!(line,2) => preparseReadLine x
+ skipIfBlock x
stringPrefix?('")elseif",line) =>
- EVAL string2BootTree storeBlanks!(line,7) => preparseReadLine st
- skipIfBlock st
+ EVAL string2BootTree storeBlanks!(line,7) => preparseReadLine x
+ skipIfBlock x
stringPrefix?('")else",line) or stringPrefix?('")endif",line) =>
- preparseReadLine st
- stringPrefix?('")fin",line) => [n]
- skipIfBlock st
- skipIfBlock st
+ preparseReadLine x
+ stringPrefix?('")fin",line) => [n,:%nothing]
+ skipIfBlock x
+ skipIfBlock x
-skipToEndif st ==
- [n,:line] := z := preparseReadLine1 st
+skipToEndif x ==
+ [n,:line] := z := preparseReadLine1 x
not string? line => z
- stringPrefix?(line,'")endif") => preparseReadLine st
- stringPrefix?(line,'")fin") => [n]
- skipToEndif st
+ stringPrefix?(line,'")endif") => preparseReadLine x
+ stringPrefix?(line,'")fin") => [n,:%nothing]
+ skipToEndif x
-preparseReadLine st ==
- [n,:line] := z := preparseReadLine1 st
+preparseReadLine x ==
+ [n,:line] := z := preparseReadLine1 x
not string? line or #line = 0 => z
line.0 = char ")" =>
stringPrefix?('")if",line) =>
- EVAL string2BootTree storeBlanks!(line,3) => preparseReadLine st
- skipIfBlock st
+ EVAL string2BootTree storeBlanks!(line,3) => preparseReadLine x
+ skipIfBlock x
stringPrefix?('")elseif",line) or stringPrefix?('")else",line) =>
- skipToEndif st
- stringPrefix?('")endif",line) => preparseReadLine st
- stringPrefix?('")fin",line) =>
- SETQ(_*EOF_*,true)
- [n]
+ skipToEndif x
+ stringPrefix?('")endif",line) => preparseReadLine x
+ stringPrefix?('")fin",line) => [n,:%nothing]
z
z
@@ -867,8 +865,9 @@ parseSpadFile sourceFile ==
-- gather parse trees for all toplevel expressions in sourceFile.
asts := []
- while not (_*EOF_* or FILE_-CLOSED) repeat
+ while not eof? IN_-STREAM repeat
$lineStack: local := PREPARSE IN_-STREAM
+ $lineStack = nil => leave nil -- explicit end of input
LINE: local := CDAR $lineStack
CATCH('SPAD__READER,parseNewExpr())
asts := [parseTransform postTransform popStack1(), :asts]
diff --git a/src/interp/spad.lisp b/src/interp/spad.lisp
index 14f264e5..5aec187c 100644
--- a/src/interp/spad.lisp
+++ b/src/interp/spad.lisp
@@ -77,7 +77,6 @@
(defun init-boot/spad-reader ()
(setq $SPAD_ERRORS (VECTOR 0 0 0))
(setq SPADERRORSTREAM |$OutputStream|)
- (setq File-Closed nil)
(Next-Lines-Clear)
(setq |$lineStack| nil)
(ioclear))
@@ -92,11 +91,9 @@
($SPAD T)
(OPTIONLIST nil)
(*EOF* NIL)
- (File-Closed NIL)
(/editfile *spad-input-file*)
in-stream out-stream)
- (declare (special |$Echo| /editfile *comp370-apply* *EOF*
- File-Closed Xcape))
+ (declare (special |$Echo| /editfile *comp370-apply* *EOF* Xcape))
(setq |$InteractiveMode| nil)
;; only rebind |$InteractiveFrame| if compiling
(progv (if (not |$InteractiveMode|) '(|$InteractiveFrame|))
@@ -121,11 +118,15 @@
(print-package "BOOT"))
(setq |$OutputStream| out-stream)
(loop
- (if (or *eof* file-closed) (return nil))
+ (if (|eof?| in-stream) (return nil))
(catch 'SPAD_READER
- (if (setq |$lineStack| (PREPARSE in-stream))
- (let ((LINE (cdar |$lineStack|)))
- (declare (special LINE))
+ (progn
+ (setq |$lineStack| (PREPARSE in-stream))
+ (when (null |$lineStack|)
+ (return nil))
+ (when |$lineStack|
+ (let ((LINE (cdar |$lineStack|)))
+ (declare (special LINE))
(|parseNewExpr|)
(let ((parseout (|popStack1|)) )
(when parseout
@@ -133,7 +134,7 @@
(S-PROCESS parseout))
(format out-stream "~&")))
;(IOClear in-stream out-stream)
- )))
+ ))))
(IOClear in-stream out-stream)))
(if *spad-input-file* (shut in-stream))
(if *spad-output-file* (shut out-stream)))