aboutsummaryrefslogtreecommitdiff
path: root/src/interp
diff options
context:
space:
mode:
Diffstat (limited to 'src/interp')
-rw-r--r--src/interp/io.boot54
-rw-r--r--src/interp/spad-parser.boot15
-rw-r--r--src/interp/spad.lisp66
3 files changed, 83 insertions, 52 deletions
diff --git a/src/interp/io.boot b/src/interp/io.boot
index d8b638dd..9f9debbc 100644
--- a/src/interp/io.boot
+++ b/src/interp/io.boot
@@ -101,6 +101,37 @@ findString(s1,s2,k == 0) ==
and/[stringChar(s1,j) = stringChar(s2,i+j) for j in 0..(n1-1)]]
--%
+--% Source line
+--% string and line number
+--%
+structure %SourceLine ==
+ Record(str: %String,no: %Short) with
+ sourceLineString == (.str)
+ sourceLineNumber == (.no)
+
+makeSourceLine(s,n) ==
+ mk%SourceLine(s,n)
+
+--%
+--% Load Unit
+--%
+structure %LoadUnit ==
+ Record(path: %Path,lines: %List %SourceLine) with
+ loadUnitPath == (.path)
+ loadUnitLines == (.lines)
+
+readLoadUnitSource path ==
+ lines :=
+ istream := inputTextFile path
+ or systemError ['"could not open file: ",:bright path]
+ try
+ [makeSourceLine(s,n) for n in 1.. while not eof? istream
+ | (s := readLine istream) and s ~= %nothing]
+ finally
+ closeStream istream
+ mk%LoadUnit(path,lines)
+
+--%
--% Line abstract datatype
--%
structure %Line ==
@@ -157,16 +188,27 @@ lineAdvanceChar! l ==
--% Reader
--%
structure %Reader ==
- Record(ins: %InputStream,est: %OutputStream,
- lines: %List %String,sline: %Line,idx: %Short) with
- readerInput == (.ins)
- readerError == (.est) -- error output stream
+ Record(lu: %LoadUnit,est: %OutputStream,
+ lines: %List %String,sline: %Line,idx: %Short,nxt: %SourceLine) with
+ readerUnitSource == (.lu) -- current load unit source
+ readerError == (.est) -- error output stream
readerPendingLines == (.lines)
readerSourceLine == (.sline) -- current input line
readerLineNumber == (.idx) -- current line number
+ readerNextLines == (.nxt) -- next source line to process
+
+makeReader(path,est) ==
+ lu := readLoadUnitSource path
+ mk%Reader(lu,est,nil,makeLine(),0,loadUnitLines lu)
+
+readerEoi? rd ==
+ readerNextLines rd = nil
-makeReader(ist,ost == 'T) ==
- mk%Reader(ist,ost,nil,makeLine(),0)
+readerReadLine rd ==
+ readerNextLines rd is [x,:xs] =>
+ readerNextLines(rd) := xs
+ sourceLineString x
+ %nothing
++ Add line `l' to the stack of pending lines.
readerDeferLine(rd,l) ==
diff --git a/src/interp/spad-parser.boot b/src/interp/spad-parser.boot
index 71f2d60a..92fe77f7 100644
--- a/src/interp/spad-parser.boot
+++ b/src/interp/spad-parser.boot
@@ -61,7 +61,7 @@ $preparseReportIfTrue := false
INITIALIZE_-PREPARSE rd ==
readerLineNumber(rd) := 0
- $preparseLastLine := readLine readerInput rd
+ $preparseLastLine := readerReadLine rd
--%
@@ -147,7 +147,7 @@ preparseReadLine1 rs ==
line := first lines
readerPendingLines(rs) := rest lines
else
- line := expandLeadingTabs readLine readerInput rs
+ line := expandLeadingTabs readerReadLine rs
$preparseLastLine := line
not string? line => [readerLineNumber rs]
readerLineNumber(rs) := readerLineNumber rs + 1
@@ -1063,7 +1063,6 @@ translateSpad x ==
++ ??? finally use the new parser everwhere.
parseSpadFile sourceFile ==
$SPAD: local := true -- we are parsing Spad,
- _*EOF_*: local := false -- end of current input?
FILE_-CLOSED : local := false -- current stream closed?
try
-- noise to standard output
@@ -1074,18 +1073,13 @@ parseSpadFile sourceFile ==
$InteractiveMode: local := false
-- 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,$OutputStream)
+ rd := makeReader(sourceFile,$OutputStream)
INIT_-BOOT_/SPAD_-READER rd
-
- -- If soureFile cannot be processed for whatever reasons
- -- get out of here instead of being stuck later.
- 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? readerInput rd repeat
+ while not readerEoi? rd repeat
$lineStack: local := preparse rd
$lineStack = nil => leave nil -- explicit end of input
LINE: local := CDAR $lineStack
@@ -1095,7 +1089,6 @@ parseSpadFile sourceFile ==
reverse! asts
finally -- clean up the mess, and get out of here
ioClear! rd
- SHUT readerInput rd
--%
diff --git a/src/interp/spad.lisp b/src/interp/spad.lisp
index 804a6f3f..d8dd240c 100644
--- a/src/interp/spad.lisp
+++ b/src/interp/spad.lisp
@@ -66,14 +66,13 @@
(defun spad (ifile
&aux
- (*comp370-apply* (function |printBackendDecl|))
- (*fileactq-apply* (function |printBackendDecl|))
- ($SPAD T)
- (OPTIONLIST nil)
- (*EOF* NIL)
- (|$editFile| ifile)
- rd in-stream out-stream)
- (declare (special |$Echo| |$editFile| *comp370-apply* *EOF*))
+ (*comp370-apply* (function |printBackendDecl|))
+ (*fileactq-apply* (function |printBackendDecl|))
+ ($SPAD T)
+ (OPTIONLIST nil)
+ (|$editFile| ifile)
+ rd out-stream)
+ (declare (special |$Echo| |$editFile| *comp370-apply*))
(setq |$InteractiveMode| nil)
;; only rebind |$InteractiveFrame| if compiling
(progv (if (not |$InteractiveMode|) '(|$InteractiveFrame|))
@@ -83,33 +82,30 @@
`((FLUID . |true|)
(|special| . ,(COPY-TREE |$InitialDomainsInScope|)))
(|addBinding| '|$Information| NIL (|makeInitialModemapFrame|)))))
- (unwind-protect
- (progn
- (setq in-stream (open ifile :direction :input))
- (setq rd (|makeReader| in-stream |$OutputStream|))
- (init-boot/spad-reader rd)
- (initialize-preparse rd)
- (setq out-stream |$OutputStream|)
- (loop
- (if (|eof?| in-stream) (return nil))
- (catch |$SpadReaderTag|
- (progn
- (setq |$lineStack| (|preparse| rd))
- (when (null |$lineStack|)
- (return nil))
- (when |$lineStack|
- (let ((LINE (cdar |$lineStack|)))
- (declare (special LINE))
- (|parseNewExpr| rd)
- (let ((parseout (|popStack1|)) )
- (when parseout
- (let ((|$OutputStream| out-stream))
- (|translateSpad| parseout))
- (format out-stream "~&")))
- ))))
- (|ioClear!| rd)))
- (shut in-stream))
- T))
+ (progn
+ (setq rd (|makeReader| ifile |$OutputStream|))
+ (init-boot/spad-reader rd)
+ (initialize-preparse rd)
+ (setq out-stream |$OutputStream|)
+ (loop
+ (if (|readerEoi?| rd) (return nil))
+ (catch |$SpadReaderTag|
+ (progn
+ (setq |$lineStack| (|preparse| rd))
+ (when (null |$lineStack|)
+ (return nil))
+ (when |$lineStack|
+ (let ((LINE (cdar |$lineStack|)))
+ (declare (special LINE))
+ (|parseNewExpr| rd)
+ (let ((parseout (|popStack1|)) )
+ (when parseout
+ (let ((|$OutputStream| out-stream))
+ (|translateSpad| parseout))
+ (format out-stream "~&")))
+ ))))
+ (|ioClear!| rd)))
+ T))
(DEFUN INTEGER-BIT (N I) (LOGBITP I N))