2008-12-05 22:34:25 -05:00
|
|
|
! Copyright (C) 2008 Jose Antonio Ortega Ruiz.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
|
|
|
2008-12-15 17:44:13 -05:00
|
|
|
USING: accessors arrays assocs classes classes.tuple
|
|
|
|
combinators compiler.units continuations debugger definitions
|
|
|
|
eval help io io.files io.pathnames io.streams.string kernel
|
2008-12-20 19:43:28 -05:00
|
|
|
lexer listener listener.private make math math.order memoize
|
|
|
|
namespaces parser prettyprint prettyprint.config quotations
|
|
|
|
sequences sets sorting source-files strings summary tools.vocabs
|
|
|
|
vectors vocabs vocabs.loader vocabs.parser words ;
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
|
|
IN: fuel
|
|
|
|
|
2008-12-08 20:36:55 -05:00
|
|
|
! Evaluation status:
|
2008-12-05 22:34:25 -05:00
|
|
|
|
2008-12-18 18:20:56 -05:00
|
|
|
TUPLE: fuel-status in use restarts ;
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
|
|
SYMBOL: fuel-status-stack
|
|
|
|
V{ } clone fuel-status-stack set-global
|
|
|
|
|
2008-12-08 20:36:55 -05:00
|
|
|
SYMBOL: fuel-eval-result
|
|
|
|
f clone fuel-eval-result set-global
|
|
|
|
|
|
|
|
SYMBOL: fuel-eval-output
|
|
|
|
f clone fuel-eval-result set-global
|
|
|
|
|
|
|
|
SYMBOL: fuel-eval-res-flag
|
|
|
|
t clone fuel-eval-res-flag set-global
|
|
|
|
|
|
|
|
: fuel-eval-restartable? ( -- ? )
|
|
|
|
fuel-eval-res-flag get-global ; inline
|
|
|
|
|
|
|
|
: fuel-eval-restartable ( -- )
|
|
|
|
t fuel-eval-res-flag set-global ; inline
|
|
|
|
|
|
|
|
: fuel-eval-non-restartable ( -- )
|
|
|
|
f fuel-eval-res-flag set-global ; inline
|
|
|
|
|
2008-12-05 22:34:25 -05:00
|
|
|
: push-fuel-status ( -- )
|
2008-12-18 18:20:56 -05:00
|
|
|
in get use get clone restarts get-global clone
|
2008-12-05 22:34:25 -05:00
|
|
|
fuel-status boa
|
|
|
|
fuel-status-stack get push ;
|
|
|
|
|
|
|
|
: pop-fuel-status ( -- )
|
|
|
|
fuel-status-stack get empty? [
|
2008-12-20 10:51:05 -05:00
|
|
|
fuel-status-stack get pop
|
|
|
|
[ in>> in set ]
|
|
|
|
[ use>> clone use set ]
|
|
|
|
[
|
|
|
|
restarts>> fuel-eval-restartable? [ drop ] [
|
|
|
|
clone restarts set-global
|
|
|
|
] if
|
|
|
|
] tri
|
2008-12-05 22:34:25 -05:00
|
|
|
] unless ;
|
|
|
|
|
|
|
|
|
2008-12-08 20:36:55 -05:00
|
|
|
! Lispy pretty printing
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
|
|
GENERIC: fuel-pprint ( obj -- )
|
|
|
|
|
2008-12-08 20:36:55 -05:00
|
|
|
M: object fuel-pprint pprint ; inline
|
2008-12-05 22:34:25 -05:00
|
|
|
|
2008-12-08 20:36:55 -05:00
|
|
|
M: f fuel-pprint drop "nil" write ; inline
|
2008-12-05 22:34:25 -05:00
|
|
|
|
2008-12-08 20:36:55 -05:00
|
|
|
M: integer fuel-pprint pprint ; inline
|
2008-12-05 22:34:25 -05:00
|
|
|
|
2008-12-08 20:36:55 -05:00
|
|
|
M: string fuel-pprint pprint ; inline
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
|
|
M: sequence fuel-pprint
|
|
|
|
dup empty? [ drop f fuel-pprint ] [
|
|
|
|
"(" write
|
|
|
|
[ " " write ] [ fuel-pprint ] interleave
|
|
|
|
")" write
|
|
|
|
] if ;
|
|
|
|
|
2008-12-08 20:36:55 -05:00
|
|
|
M: tuple fuel-pprint tuple>array fuel-pprint ; inline
|
|
|
|
|
|
|
|
M: continuation fuel-pprint drop ":continuation" write ; inline
|
|
|
|
|
|
|
|
M: restart fuel-pprint name>> fuel-pprint ; inline
|
|
|
|
|
|
|
|
SYMBOL: :restarts
|
2008-12-05 22:34:25 -05:00
|
|
|
|
2008-12-08 20:36:55 -05:00
|
|
|
: fuel-restarts ( obj -- seq )
|
|
|
|
compute-restarts :restarts prefix ; inline
|
|
|
|
|
|
|
|
M: condition fuel-pprint
|
|
|
|
[ error>> ] [ fuel-restarts ] bi 2array condition prefix fuel-pprint ;
|
|
|
|
|
2008-12-15 17:44:13 -05:00
|
|
|
M: lexer-error fuel-pprint
|
|
|
|
{
|
|
|
|
[ line>> ]
|
|
|
|
[ column>> ]
|
|
|
|
[ line-text>> ]
|
|
|
|
[ fuel-restarts ]
|
|
|
|
} cleave 4array lexer-error prefix fuel-pprint ;
|
|
|
|
|
2008-12-08 20:36:55 -05:00
|
|
|
M: source-file-error fuel-pprint
|
|
|
|
[ file>> ] [ error>> ] bi 2array source-file-error prefix
|
|
|
|
fuel-pprint ;
|
|
|
|
|
|
|
|
M: source-file fuel-pprint path>> fuel-pprint ;
|
|
|
|
|
|
|
|
! Evaluation vocabulary
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
|
|
: fuel-eval-set-result ( obj -- )
|
2008-12-08 20:36:55 -05:00
|
|
|
clone fuel-eval-result set-global ; inline
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
|
|
: fuel-retort ( -- )
|
|
|
|
error get
|
|
|
|
fuel-eval-result get-global
|
|
|
|
fuel-eval-output get-global
|
2008-12-18 18:20:56 -05:00
|
|
|
3array fuel-pprint flush nl "<~FUEL~>" write nl flush ;
|
2008-12-05 22:34:25 -05:00
|
|
|
|
2008-12-09 17:37:27 -05:00
|
|
|
: fuel-forget-error ( -- ) f error set-global ; inline
|
|
|
|
: fuel-forget-result ( -- ) f fuel-eval-result set-global ; inline
|
|
|
|
: fuel-forget-output ( -- ) f fuel-eval-output set-global ; inline
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
|
|
: (fuel-begin-eval) ( -- )
|
|
|
|
push-fuel-status
|
|
|
|
fuel-forget-error
|
2008-12-09 17:37:27 -05:00
|
|
|
fuel-forget-result
|
|
|
|
fuel-forget-output ;
|
2008-12-08 20:36:55 -05:00
|
|
|
|
2008-12-21 16:12:46 -05:00
|
|
|
: (fuel-end-eval) ( result -- )
|
|
|
|
fuel-eval-output set-global fuel-retort
|
2008-12-18 18:20:56 -05:00
|
|
|
pop-fuel-status ; inline
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
|
|
: (fuel-eval) ( lines -- )
|
2008-12-08 20:36:55 -05:00
|
|
|
[ [ parse-lines ] with-compilation-unit call ] curry
|
|
|
|
[ print-error ] recover ; inline
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
|
|
: (fuel-eval-each) ( lines -- )
|
2008-12-08 20:36:55 -05:00
|
|
|
[ 1vector (fuel-eval) ] each ; inline
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
|
|
: (fuel-eval-usings) ( usings -- )
|
|
|
|
[ "USING: " prepend " ;" append ] map
|
2008-12-09 17:37:27 -05:00
|
|
|
(fuel-eval-each) fuel-forget-error fuel-forget-output ;
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
|
|
: (fuel-eval-in) ( in -- )
|
2008-12-08 20:36:55 -05:00
|
|
|
[ dup "IN: " prepend 1vector (fuel-eval) in set ] when* ; inline
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
|
|
: fuel-eval-in-context ( lines in usings -- )
|
2008-12-21 16:12:46 -05:00
|
|
|
(fuel-begin-eval)
|
|
|
|
[ (fuel-eval-usings) (fuel-eval-in) (fuel-eval) ] with-string-writer
|
|
|
|
(fuel-end-eval) ;
|
2008-12-05 22:34:25 -05:00
|
|
|
|
2008-12-18 09:38:40 -05:00
|
|
|
: fuel-run-file ( path -- ) run-file ; inline
|
|
|
|
|
2008-12-17 18:49:01 -05:00
|
|
|
! Edit locations
|
|
|
|
|
2008-12-06 01:01:12 -05:00
|
|
|
: fuel-get-edit-location ( defspec -- )
|
2008-12-13 18:41:35 -05:00
|
|
|
where [
|
|
|
|
first2 [ (normalize-path) ] dip 2array fuel-eval-set-result
|
2008-12-15 20:09:18 -05:00
|
|
|
] when* ; inline
|
2008-12-13 18:41:35 -05:00
|
|
|
|
2008-12-20 19:43:28 -05:00
|
|
|
: fuel-format-xrefs ( seq -- seq )
|
|
|
|
[ word? ] filter [
|
2008-12-21 11:33:53 -05:00
|
|
|
[ name>> ]
|
|
|
|
[ vocabulary>> ]
|
|
|
|
[ where [ first2 [ (normalize-path) ] dip ] [ f f ] if* ] tri 4array
|
2008-12-20 19:43:28 -05:00
|
|
|
] map [ [ first ] dip first <=> ] sort ; inline
|
|
|
|
|
|
|
|
: fuel-callers-xref ( word -- )
|
|
|
|
usage fuel-format-xrefs fuel-eval-set-result ; inline
|
|
|
|
|
|
|
|
: fuel-callees-xref ( word -- )
|
|
|
|
uses fuel-format-xrefs fuel-eval-set-result ; inline
|
|
|
|
|
2008-12-13 18:41:35 -05:00
|
|
|
: fuel-get-vocab-location ( vocab -- )
|
2008-12-15 20:09:18 -05:00
|
|
|
>vocab-link fuel-get-edit-location ; inline
|
2008-12-13 18:41:35 -05:00
|
|
|
|
2008-12-17 17:50:48 -05:00
|
|
|
! Completion support
|
|
|
|
|
|
|
|
: fuel-filter-prefix ( seq prefix -- seq )
|
2008-12-18 09:38:40 -05:00
|
|
|
[ drop-prefix nip length 0 = ] curry filter prune ; inline
|
2008-12-17 17:50:48 -05:00
|
|
|
|
2008-12-15 17:44:13 -05:00
|
|
|
: (fuel-get-vocabs) ( -- seq )
|
|
|
|
all-vocabs-seq [ vocab-name ] map ; inline
|
|
|
|
|
2008-12-13 18:41:35 -05:00
|
|
|
: fuel-get-vocabs ( -- )
|
2008-12-15 20:09:18 -05:00
|
|
|
(fuel-get-vocabs) fuel-eval-set-result ; inline
|
2008-12-15 17:44:13 -05:00
|
|
|
|
2008-12-17 17:50:48 -05:00
|
|
|
: fuel-get-vocabs/prefix ( prefix -- )
|
|
|
|
(fuel-get-vocabs) swap fuel-filter-prefix fuel-eval-set-result ; inline
|
|
|
|
|
2008-12-18 09:38:40 -05:00
|
|
|
: fuel-vocab-summary ( name -- )
|
|
|
|
>vocab-link summary fuel-eval-set-result ; inline
|
|
|
|
|
2008-12-15 17:44:13 -05:00
|
|
|
MEMO: (fuel-vocab-words) ( name -- seq )
|
|
|
|
>vocab-link words [ name>> ] map ;
|
|
|
|
|
2008-12-15 20:09:18 -05:00
|
|
|
: fuel-current-words ( -- seq )
|
|
|
|
use get [ keys ] map concat ; inline
|
|
|
|
|
|
|
|
: fuel-vocabs-words ( names -- seq )
|
|
|
|
prune [ (fuel-vocab-words) ] map concat ; inline
|
2008-12-15 17:44:13 -05:00
|
|
|
|
|
|
|
: (fuel-get-words) ( prefix names/f -- seq )
|
2008-12-15 20:09:18 -05:00
|
|
|
[ fuel-vocabs-words ] [ fuel-current-words ] if* natural-sort
|
2008-12-17 18:49:01 -05:00
|
|
|
swap fuel-filter-prefix ;
|
2008-12-15 17:44:13 -05:00
|
|
|
|
|
|
|
: fuel-get-words ( prefix names -- )
|
|
|
|
(fuel-get-words) fuel-eval-set-result ; inline
|
2008-12-05 22:34:25 -05:00
|
|
|
|
2008-12-18 09:38:40 -05:00
|
|
|
|
|
|
|
! -run=fuel support
|
2008-12-08 20:36:55 -05:00
|
|
|
|
2008-12-15 20:09:18 -05:00
|
|
|
: fuel-startup ( -- ) "listener" run-file ; inline
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
|
|
MAIN: fuel-startup
|