diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ChangeLog | 13 | ||||
-rw-r--r-- | src/interp/io.boot | 11 | ||||
-rw-r--r-- | src/interp/preparse.lisp | 26 | ||||
-rw-r--r-- | src/interp/spad-parser.boot | 70 | ||||
-rw-r--r-- | src/interp/spad.lisp | 34 |
5 files changed, 82 insertions, 72 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 50e3e96f..bf2d7984 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,18 @@ 2012-06-03 Gabriel Dos Reis <gdr@cs.tamu.edu> + * interp/io.boot (%Reader): New data structure. + * interp/preparse.lisp (INITIALIZE-PREPARSE): Parameter is now a + reader. + (preparse1): Likewise. Tidy. + * interp/spad-parser.boot (preparseReadLine): Likewise. + (preparseReadLine1): Likewise. + (preparse): Likewise. + (parseSpadFile): Likewise. + * interp/spad.lisp (SPAD): Make it a unary function. Simplify. + (INITIALIZE): Remove. + +2012-06-03 Gabriel Dos Reis <gdr@cs.tamu.edu> + * interp/lexing.boot (%Line): Now a record structure. * boot/parser.boot (bpTypeName): Split out of bpTypeAliasDefinition. (bpStruct): Use it. Support parameterized structures. diff --git a/src/interp/io.boot b/src/interp/io.boot index f7a35617..a7fe1849 100644 --- a/src/interp/io.boot +++ b/src/interp/io.boot @@ -99,3 +99,14 @@ findString(s1,s2,k == 0) == n1 := #s1 or/[i for i in k..(#s2 - n1) | and/[stringChar(s1,j) = stringChar(s2,i+j) for j in 0..(n1-1)]] + +--% +--% Reader +--% +structure %Reader == + Record(ins: %InputStream, lines: %List %Line) with + readerInput == (.ins) + readerLines == (.lines) + +makeReader ist == + mk%Reader(ist,nil) diff --git a/src/interp/preparse.lisp b/src/interp/preparse.lisp index f0edee7c..175a3f7c 100644 --- a/src/interp/preparse.lisp +++ b/src/interp/preparse.lisp @@ -73,20 +73,20 @@ (DEFPARAMETER TOK NIL) (DEFPARAMETER DEFINITION_NAME NIL) -(defun Initialize-Preparse (strm) +(defun Initialize-Preparse (rd) (setq $INDEX 0 |$LineList| nil |$EchoLineStack| nil) - (setq |$preparseLastLine| (|readLine| strm))) + (setq |$preparseLastLine| (|readLine| (|readerInput| rd)))) (defvar $skipme) -(defun |preparse1| (LineList) - (PROG ((|$LineList| LineList) |$EchoLineStack| NUM A I L PSLOC +(defun |preparse1| (rd) + (PROG ((|$LineList| (|readerLines| rd)) |$EchoLineStack| NUM A I L PSLOC INSTRING PCOUNT COMSYM STRSYM OPARSYM CPARSYM N NCOMSYM (SLOC -1) (CONTINUE NIL) (PARENLEV 0) (NCOMBLOCK ()) (LINES ()) (LOCS ()) (NUMS ()) functor ) - READLOOP (DCQ (NUM . A) (|preparseReadLine| LineList)) + READLOOP (DCQ (NUM . A) (|preparseReadLine| rd)) (cond ((|atEndOfUnit?| A) - (|preparseEcho| LineList) + (|preparseEcho| (|readerLines| rd)) (COND ((NULL LINES) (RETURN NIL)) (NCOMBLOCK (|findCommentBlock| NIL NUMS LOCS NCOMBLOCK NIL))) @@ -94,7 +94,7 @@ (|parsePiles| (|reverse!| LOCS) (|reverse!| LINES)))))) (cond ((and (NULL LINES) (> (LENGTH A) 0) (EQ (CHAR A 0) #\) )) ; this is a command line, don't parse it - (|preparseEcho| LineList) + (|preparseEcho| (|readerLines| rd)) (setq |$preparseLastLine| nil) ;don't reread this line (SETQ LINE a) (CATCH 'SPAD_READER (|doSystemCommand| (subseq LINE 1))) @@ -125,7 +125,7 @@ (COND ((= SLOC N) (COND ((AND NCOMBLOCK (NOT (= N (CAR NCOMBLOCK)))) - (|findCommentBlock| NUM NUMS LOCS NCOMBLOCK linelist) + (|findCommentBlock| NUM NUMS LOCS NCOMBLOCK (|readerLines| rd)) (SETQ NCOMBLOCK NIL))) (SETQ NCOMBLOCK (CONS N (CONS A (IFCDR NCOMBLOCK)))) (SETQ A "")) @@ -157,8 +157,8 @@ (setq $skipme nil)))) (when (and LINES (EQL SLOC 0)) (IF (AND NCOMBLOCK (NOT (ZEROP (CAR NCOMBLOCK)))) - (|findCommentBlock| NUM NUMS LOCS NCOMBLOCK linelist)) - (IF (NOT (|ioTerminal?| in-stream)) + (|findCommentBlock| NUM NUMS LOCS NCOMBLOCK (|readerLines| rd))) + (IF (NOT (|ioTerminal?| (|readerInput| rd))) (setq |$preparseLastLine| (|reverse!| |$EchoLineStack|))) (RETURN (|pairList| (|reverse!| NUMS) @@ -168,14 +168,14 @@ (setq SLOC PSLOC) (GO REREAD))) (COND (NCOMBLOCK - (|findCommentBlock| NUM NUMS LOCS NCOMBLOCK linelist) + (|findCommentBlock| NUM NUMS LOCS NCOMBLOCK (|readerLines| rd)) (setq NCOMBLOCK ()))) (PUSH SLOC LOCS) - REREAD (|preparseEcho| LineList) + REREAD (|preparseEcho| (|readerLines| rd)) (PUSH A LINES) (PUSH NUM NUMS) (setq PARENLEV (+ PARENLEV PCOUNT)) - (when (and (|ioTerminal?| in-stream) (not continue)) + (when (and (|ioTerminal?| (|readerInput| rd)) (not continue)) (setq |$preparseLastLine| nil) (RETURN (|pairList| (|reverse!| NUMS) (|parsePiles| (|reverse!| LOCS) (|reverse!| LINES))))) diff --git a/src/interp/spad-parser.boot b/src/interp/spad-parser.boot index ff9051ed..56815de0 100644 --- a/src/interp/spad-parser.boot +++ b/src/interp/spad-parser.boot @@ -78,29 +78,29 @@ indentationLocation line == tabChar? line.i => loc := 8 * (loc quo 8 + 1) return loc -skipIfBlock x == - [n,:line] := z := preparseReadLine1 x +skipIfBlock rs == + [n,:line] := z := preparseReadLine1 rs not string? line => z - #line = 0 => skipIfBlock x + #line = 0 => skipIfBlock rs line.0 = char ")" => stringPrefix?('")if",line) => - EVAL string2BootTree storeBlanks!(line,2) => preparseReadLine x - skipIfBlock x + EVAL string2BootTree storeBlanks!(line,2) => preparseReadLine rs + skipIfBlock rs stringPrefix?('")elseif",line) => - EVAL string2BootTree storeBlanks!(line,7) => preparseReadLine x - skipIfBlock x + EVAL string2BootTree storeBlanks!(line,7) => preparseReadLine rs + skipIfBlock rs stringPrefix?('")else",line) or stringPrefix?('")endif",line) => - preparseReadLine x + preparseReadLine rs stringPrefix?('")fin",line) => [n,:%nothing] - skipIfBlock x - skipIfBlock x + skipIfBlock rs + skipIfBlock rs -skipToEndif x == - [n,:line] := z := preparseReadLine1 x +skipToEndif rs == + [n,:line] := z := preparseReadLine1 rs not string? line => z - stringPrefix?(line,'")endif") => preparseReadLine x + stringPrefix?(line,'")endif") => preparseReadLine rs stringPrefix?(line,'")fin") => [n,:%nothing] - skipToEndif x + skipToEndif rs ++ `n' is the line number of the current line ++ `oldnums' is the list of line numbers of previous lines @@ -118,25 +118,25 @@ findCommentBlock(n,oldnums,oldlocs,ncblock,lines) == :reverse block] $COMBLOCKLIST := [x,:$COMBLOCKLIST] -preparseReadLine x == - [n,:line] := z := preparseReadLine1 x +preparseReadLine rs == + [n,:line] := z := preparseReadLine1 rs not string? line or #line = 0 => z line.0 = char ")" => stringPrefix?('")if",line) => - EVAL string2BootTree storeBlanks!(line,3) => preparseReadLine x - skipIfBlock x + EVAL string2BootTree storeBlanks!(line,3) => preparseReadLine rs + skipIfBlock rs stringPrefix?('")elseif",line) or stringPrefix?('")else",line) => - skipToEndif x - stringPrefix?('")endif",line) => preparseReadLine x + skipToEndif rs + stringPrefix?('")endif",line) => preparseReadLine rs stringPrefix?('")fin",line) => [n,:%nothing] z z -preparseReadLine1 x == +preparseReadLine1 rs == if $LineList then [line,:$LineList] := $LineList else - line := expandLeadingTabs readLine IN_-STREAM + line := expandLeadingTabs readLine readerInput rs $preparseLastLine := line not string? line => [$INDEX] $INDEX := $INDEX + 1 @@ -144,7 +144,7 @@ preparseReadLine1 x == $EchoLineStack := [copyString line,:$EchoLineStack] n := $INDEX if #line > 0 and line.maxIndex(line) = char "__" then - line := strconc(subString(line,0,maxIndex line),rest preparseReadLine1 x) + line := strconc(subString(line,0,maxIndex line),rest preparseReadLine1 rs) $preparseLastLine := line [n,:line] @@ -200,17 +200,17 @@ parsePrint l == formatToStdout '"~%" nil -preparse st == +preparse rd == $COMBLOCKLIST := nil $SKIPME := false - stack := + readerLines(rd) := $preparseLastLine => $preparseLastLine is [.,:.] => $preparseLastLine [$preparseLastLine] nil - $INDEX := $INDEX - #stack - u := preparse1 stack - $SKIPME => preparse st + $INDEX := $INDEX - #readerLines rd + u := preparse1 rd + $SKIPME => preparse rd parsePrint u $headerDocumentation := nil $docList := nil @@ -981,26 +981,26 @@ parseSpadFile sourceFile == -- we need to restore the global input stream state after we -- finished messing with it. IN_-STREAM: local := MAKE_-INSTREAM sourceFile + rd := makeReader IN_-STREAM -- If soureFile cannot be processed for whatever reasons -- get out of here instead of being stuck later. - IN_-STREAM = nil => - systemError '"cannot open input source file" - INITIALIZE_-PREPARSE IN_-STREAM + readerInput rd = nil => systemError '"cannot open input source file" + INITIALIZE_-PREPARSE rd -- gather parse trees for all toplevel expressions in sourceFile. asts := [] - while not eof? IN_-STREAM repeat - $lineStack: local := preparse IN_-STREAM + while not eof? readerInput rd repeat + $lineStack: local := preparse rd $lineStack = nil => leave nil -- explicit end of input LINE: local := CDAR $lineStack - CATCH('SPAD__READER,parseNewExpr()) + CATCH($SpadReaderTag,parseNewExpr()) asts := [parseTransform postTransform popStack1(), :asts] -- we accumulated the parse trees in reverse order reverse! asts finally -- clean up the mess, and get out of here ioClear!() - SHUT IN_-STREAM + SHUT readerInput rd --% diff --git a/src/interp/spad.lisp b/src/interp/spad.lisp index 7776a6e6..e0ccf4be 100644 --- a/src/interp/spad.lisp +++ b/src/interp/spad.lisp @@ -64,17 +64,15 @@ (|nextLinesClear!|) (|ioClear!|)) -(defun spad (&optional - (*spad-input-file* nil) - (*spad-output-file* nil) +(defun spad (ifile &aux (*comp370-apply* (function |printBackendDecl|)) (*fileactq-apply* (function |printBackendDecl|)) ($SPAD T) (OPTIONLIST nil) (*EOF* NIL) - (|$editFile| *spad-input-file*) - in-stream out-stream) + (|$editFile| ifile) + rd in-stream out-stream) (declare (special |$Echo| |$editFile| *comp370-apply* *EOF*)) (setq |$InteractiveMode| nil) ;; only rebind |$InteractiveFrame| if compiling @@ -88,22 +86,15 @@ (init-boot/spad-reader) (unwind-protect (progn - (setq in-stream (if *spad-input-file* - (open *spad-input-file* :direction :input) - |$InputStream|)) - (initialize-preparse in-stream) - (setq out-stream (if *spad-output-file* - (open *spad-output-file* :direction :output) - |$OutputStream|)) - (when *spad-output-file* - (format out-stream "~&;;; -*- Mode:Lisp; Package:Boot -*-~%~%") - (print-package "BOOT")) - (setq |$OutputStream| out-stream) + (setq in-stream (open ifile :direction :input)) + (setq rd (|makeReader| in-stream)) + (initialize-preparse rd) + (setq out-stream |$OutputStream|) (loop (if (|eof?| in-stream) (return nil)) - (catch 'SPAD_READER + (catch |$SpadReaderTag| (progn - (setq |$lineStack| (|preparse| in-stream)) + (setq |$lineStack| (|preparse| rd)) (when (null |$lineStack|) (return nil)) (when |$lineStack| @@ -117,8 +108,7 @@ (format out-stream "~&"))) )))) (|ioClear!|))) - (if *spad-input-file* (shut in-stream)) - (if *spad-output-file* (shut out-stream))) + (shut in-stream)) T)) (DEFUN INTEGER-BIT (N I) (LOGBITP I N)) @@ -170,10 +160,6 @@ (if |$InteractiveMode| (|spadThrow|)) (|translateSpad| x)))) -(defun INITIALIZE () - (init-boot/spad-reader) - (initialize-preparse |$InputStream|)) - (defmacro try (X) `(LET ((|$autoLine|)) (declare (special |$autoLine|)) |