From 87331addba3055765ee88a79a1f8e6835b10c7ea Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 20 Aug 2004 23:27:48 +0000 Subject: [PATCH] improved native run-resource --- TODO.FACTOR.txt | 2 +- library/jedit/jedit.factor | 4 +- library/platform/native/parse-stream.factor | 43 ++++++++++++++------- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/TODO.FACTOR.txt b/TODO.FACTOR.txt index 8bcf3f1ba6..7026b3f722 100644 --- a/TODO.FACTOR.txt +++ b/TODO.FACTOR.txt @@ -1,7 +1,6 @@ - input style after clicking link - fedit broken with listener - maple-like: press enter at old commands to evaluate there -- fix up native file/line info - standalone listener input style - add a socket timeout - drop test in http server @@ -45,6 +44,7 @@ + native: +- accept multi-line input in listener - gc call in the middle of some ops might affect callstack - multitasking - better error reporting diff --git a/library/jedit/jedit.factor b/library/jedit/jedit.factor index 3b31342e9e..9e86e7bbfc 100644 --- a/library/jedit/jedit.factor +++ b/library/jedit/jedit.factor @@ -68,10 +68,10 @@ USE: words : jedit ( word -- ) intern dup [ - word-line/file 2dup and [ + word-line/file dup [ jedit-line/file ] [ - "Unknown source" print + 3drop "Unknown source" print ] ifte ] [ "Not defined" print diff --git a/library/platform/native/parse-stream.factor b/library/platform/native/parse-stream.factor index de7889135a..cd2a1a08d5 100644 --- a/library/platform/native/parse-stream.factor +++ b/library/platform/native/parse-stream.factor @@ -66,32 +66,49 @@ USE: strings "file-in" get "in" set "file-use" get "use" set ; -: parse-stream ( name stream -- code ) +: (parse-stream) ( name stream -- quot ) #! Uses the current namespace for temporary variables. >r "file" set f r> [ (parse) ] read-lines nreverse "file" off "line-number" off ; -: parse-file ( file -- code ) - dup parse-stream ; +: parse-stream ( name stream -- quot ) + [ + 10 "base" set + file-vocabs + (parse-stream) + ] with-scope ; -: (run-file) ( file -- ) - #! Run a file. The file is read with the same IN:/USE: as - #! the current interactive interpreter. - parse-file call ; +: parse-file ( file -- quot ) + dup parse-stream ; : run-file ( file -- ) #! Run a file. The file is read with the default IN:/USE: #! for files. - [ - 10 "base" set - file-vocabs - parse-file - ] with-scope call ; + parse-file call ; + +: (parse-file) ( file -- quot ) + dup (parse-stream) ; + +: (run-file) ( file -- ) + #! Run a file. The file is read with the same IN:/USE: as + #! the current interactive interpreter. + (parse-file) call ; : resource-path ( -- path ) "resource-path" get [ "." ] unless* ; +: parse-resource ( path -- quot ) + #! Resources are loaded from the resource-path variable, or + #! the current directory if it is not set. Words defined in + #! resources have a definition source path starting with + #! resource:. This allows words that operate on source + #! files, like "jedit", to use a different resource path + #! at run time than was used at parse time. + "resource:" over cat2 + swap resource-path swap cat2 + parse-stream ; + : run-resource ( file -- ) - resource-path swap cat2 run-file ; + parse-resource call ;