Making more code infer
parent
c0874e64cc
commit
df18c0b6e7
|
@ -1,18 +1,23 @@
|
||||||
IN: eval
|
IN: eval
|
||||||
USING: help.markup help.syntax strings io ;
|
USING: help.markup help.syntax strings io effects ;
|
||||||
|
|
||||||
HELP: eval
|
HELP: eval
|
||||||
{ $values { "str" string } }
|
{ $values { "str" string } { "effect" effect } }
|
||||||
{ $description "Parses Factor source code from a string, and calls the resulting quotation." }
|
{ $description "Parses Factor source code from a string, and calls the resulting quotation, which must have the given stack effect." }
|
||||||
|
{ $errors "Throws an error if the input is malformed, or if the evaluation itself throws an error." } ;
|
||||||
|
|
||||||
|
HELP: eval(
|
||||||
|
{ $syntax "eval( inputs -- outputs )" }
|
||||||
|
{ $description "Parses Factor source code from the string at the top of the stack, and calls the resulting quotation, which must have the given stack effect." }
|
||||||
{ $errors "Throws an error if the input is malformed, or if the evaluation itself throws an error." } ;
|
{ $errors "Throws an error if the input is malformed, or if the evaluation itself throws an error." } ;
|
||||||
|
|
||||||
HELP: eval>string
|
HELP: eval>string
|
||||||
{ $values { "str" string } { "output" string } }
|
{ $values { "str" string } { "output" string } }
|
||||||
{ $description "Evaluates the Factor code in " { $snippet "str" } " with " { $link output-stream } " rebound to a string output stream, then outputs the resulting string." } ;
|
{ $description "Evaluates the Factor code in " { $snippet "str" } " with " { $link output-stream } " rebound to a string output stream, then outputs the resulting string. The code in the string must not take or leave any values on the stack." } ;
|
||||||
|
|
||||||
ARTICLE: "eval" "Evaluating strings at runtime"
|
ARTICLE: "eval" "Evaluating strings at runtime"
|
||||||
"The " { $vocab-link "eval" } " vocabulary implements support for evaluating strings at runtime."
|
"The " { $vocab-link "eval" } " vocabulary implements support for evaluating strings at runtime."
|
||||||
{ $subsection eval }
|
{ $subsection POSTPONE: eval( }
|
||||||
{ $subsection eval>string } ;
|
{ $subsection eval>string } ;
|
||||||
|
|
||||||
ABOUT: "eval"
|
ABOUT: "eval"
|
||||||
|
|
|
@ -1,23 +1,25 @@
|
||||||
! Copyright (C) 2008, 2009 Slava Pestov.
|
! Copyright (C) 2008, 2009 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: splitting parser compiler.units kernel namespaces
|
USING: splitting parser compiler.units kernel namespaces
|
||||||
debugger io.streams.string fry ;
|
debugger io.streams.string fry combinators effects.parser ;
|
||||||
IN: eval
|
IN: eval
|
||||||
|
|
||||||
: parse-string ( str -- quot )
|
: parse-string ( str -- quot )
|
||||||
[ string-lines parse-lines ] with-compilation-unit ;
|
[ string-lines parse-lines ] with-compilation-unit ;
|
||||||
|
|
||||||
: (eval) ( str -- )
|
: (eval) ( str effect -- )
|
||||||
parse-string call ;
|
[ parse-string ] dip call-effect ; inline
|
||||||
|
|
||||||
: eval ( str -- )
|
: eval ( str effect -- )
|
||||||
[ (eval) ] with-file-vocabs ;
|
[ (eval) ] with-file-vocabs ; inline
|
||||||
|
|
||||||
|
SYNTAX: eval( \ eval parse-call( ;
|
||||||
|
|
||||||
: (eval>string) ( str -- output )
|
: (eval>string) ( str -- output )
|
||||||
[
|
[
|
||||||
"quiet" on
|
"quiet" on
|
||||||
parser-notes off
|
parser-notes off
|
||||||
'[ _ (eval) ] try
|
'[ _ (( -- )) (eval) ] try
|
||||||
] with-string-writer ;
|
] with-string-writer ;
|
||||||
|
|
||||||
: eval>string ( str -- output )
|
: eval>string ( str -- output )
|
||||||
|
|
|
@ -21,7 +21,7 @@ TUPLE: deque { front read-only } { back read-only } ;
|
||||||
[ back>> ] [ front>> ] bi deque boa ;
|
[ back>> ] [ front>> ] bi deque boa ;
|
||||||
|
|
||||||
: flipped ( deque quot -- newdeque )
|
: flipped ( deque quot -- newdeque )
|
||||||
[ flip ] dip call flip ;
|
[ flip ] dip call flip ; inline
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
: deque-empty? ( deque -- ? )
|
: deque-empty? ( deque -- ? )
|
||||||
|
|
|
@ -354,8 +354,6 @@ IN: tools.deploy.shaker
|
||||||
|
|
||||||
: finish-deploy ( final-image -- )
|
: finish-deploy ( final-image -- )
|
||||||
"Finishing up" show
|
"Finishing up" show
|
||||||
[ { } set-datastack ] dip
|
|
||||||
{ } set-retainstack
|
|
||||||
V{ } set-namestack
|
V{ } set-namestack
|
||||||
V{ } set-catchstack
|
V{ } set-catchstack
|
||||||
"Saving final image" show
|
"Saving final image" show
|
||||||
|
|
|
@ -3,6 +3,6 @@
|
||||||
USING: eval ;
|
USING: eval ;
|
||||||
IN: tools.deploy.test.11
|
IN: tools.deploy.test.11
|
||||||
|
|
||||||
: foo ( -- ) "USING: math prettyprint ; 2 2 + ." eval ;
|
: foo ( -- ) "USING: math prettyprint ; 2 2 + ." eval( -- ) ;
|
||||||
|
|
||||||
MAIN: foo
|
MAIN: foo
|
|
@ -9,7 +9,7 @@ GENERIC: my-generic ( x -- b )
|
||||||
|
|
||||||
M: integer my-generic sq ;
|
M: integer my-generic sq ;
|
||||||
|
|
||||||
M: fixnum my-generic call-next-method my-var get call ;
|
M: fixnum my-generic call-next-method my-var get call( a -- b ) ;
|
||||||
|
|
||||||
: test-7 ( -- )
|
: test-7 ( -- )
|
||||||
[ 1 + ] my-var set-global
|
[ 1 + ] my-var set-global
|
||||||
|
|
|
@ -44,11 +44,8 @@ TUPLE: slot-editor < track ref close-hook update-hook text ;
|
||||||
{ +description+ "Parse the object being edited, and store the result back into the edited slot." }
|
{ +description+ "Parse the object being edited, and store the result back into the edited slot." }
|
||||||
} define-command
|
} define-command
|
||||||
|
|
||||||
: eval-1 ( string -- object )
|
|
||||||
1array [ eval ] with-datastack first ;
|
|
||||||
|
|
||||||
: com-eval ( slot-editor -- )
|
: com-eval ( slot-editor -- )
|
||||||
[ [ text>> editor-string eval-1 ] [ ref>> ] bi set-ref ]
|
[ [ text>> editor-string eval( -- result ) ] [ ref>> ] bi set-ref ]
|
||||||
[ close-and-update ]
|
[ close-and-update ]
|
||||||
bi ;
|
bi ;
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ SYMBOL: xim
|
||||||
xim get-global XCloseIM drop f xim set-global ;
|
xim get-global XCloseIM drop f xim set-global ;
|
||||||
|
|
||||||
: with-xim ( quot -- )
|
: with-xim ( quot -- )
|
||||||
[ "Factor" init-xim ] dip [ close-xim ] [ ] cleanup ;
|
[ "Factor" init-xim ] dip [ close-xim ] [ ] cleanup ; inline
|
||||||
|
|
||||||
: create-xic ( window classname -- xic )
|
: create-xic ( window classname -- xic )
|
||||||
[
|
[
|
||||||
|
|
|
@ -1440,4 +1440,4 @@ SYMBOL: root
|
||||||
: close-x ( -- ) dpy get XCloseDisplay drop ;
|
: close-x ( -- ) dpy get XCloseDisplay drop ;
|
||||||
|
|
||||||
: with-x ( display-string quot -- )
|
: with-x ( display-string quot -- )
|
||||||
[ initialize-x ] dip [ close-x ] [ ] cleanup ;
|
[ initialize-x ] dip [ close-x ] [ ] cleanup ; inline
|
||||||
|
|
|
@ -76,8 +76,6 @@ VAR: present-space
|
||||||
|
|
||||||
! namespace utilities
|
! namespace utilities
|
||||||
|
|
||||||
: make* ( seq -- seq ) [ dup quotation? [ call ] [ ] if ] map ;
|
|
||||||
|
|
||||||
: closed-quot ( quot -- quot )
|
: closed-quot ( quot -- quot )
|
||||||
namestack swap '[ namestack [ _ set-namestack @ ] dip set-namestack ] ;
|
namestack swap '[ namestack [ _ set-namestack @ ] dip set-namestack ] ;
|
||||||
|
|
||||||
|
@ -156,9 +154,9 @@ VAR: present-space
|
||||||
3 model-projection <model> view4> (>>model) ;
|
3 model-projection <model> view4> (>>model) ;
|
||||||
|
|
||||||
: camera-action ( quot -- quot )
|
: camera-action ( quot -- quot )
|
||||||
[ drop [ ] observer3d>
|
'[ drop _ observer3d>
|
||||||
with-self update-observer-projections ]
|
with-self update-observer-projections ]
|
||||||
make* closed-quot ;
|
closed-quot ;
|
||||||
|
|
||||||
: win3D ( text gadget -- )
|
: win3D ( text gadget -- )
|
||||||
"navigateur 4D : " rot append open-window ;
|
"navigateur 4D : " rot append open-window ;
|
||||||
|
@ -400,7 +398,7 @@ M: handler handle-gesture ( gesture gadget -- ? )
|
||||||
|
|
||||||
: add-keyboard-delegate ( obj -- obj )
|
: add-keyboard-delegate ( obj -- obj )
|
||||||
<handler>
|
<handler>
|
||||||
{
|
H{
|
||||||
{ T{ key-down f f "LEFT" }
|
{ T{ key-down f f "LEFT" }
|
||||||
[ [ rotation-step turn-left ] camera-action ] }
|
[ [ rotation-step turn-left ] camera-action ] }
|
||||||
{ T{ key-down f f "RIGHT" }
|
{ T{ key-down f f "RIGHT" }
|
||||||
|
@ -435,7 +433,7 @@ M: handler handle-gesture ( gesture gadget -- ? )
|
||||||
{ T{ key-down f f "3" } [ mvt-3D-3 camera-action ] }
|
{ T{ key-down f f "3" } [ mvt-3D-3 camera-action ] }
|
||||||
{ T{ key-down f f "4" } [ mvt-3D-4 camera-action ] }
|
{ T{ key-down f f "4" } [ mvt-3D-4 camera-action ] }
|
||||||
|
|
||||||
} [ make* ] map >hashtable >>table
|
} >>table
|
||||||
;
|
;
|
||||||
|
|
||||||
! --------------------------------------------
|
! --------------------------------------------
|
||||||
|
|
|
@ -72,17 +72,17 @@ file-chooser H{
|
||||||
: init-filelist-model ( file-chooser -- file-chooser )
|
: init-filelist-model ( file-chooser -- file-chooser )
|
||||||
dup list-of-files <model> >>model ;
|
dup list-of-files <model> >>model ;
|
||||||
|
|
||||||
: (fc-go) ( file-chooser quot -- )
|
: (fc-go) ( file-chooser button quot -- )
|
||||||
[ [ file-chooser? ] find-parent dup path>> ] dip
|
[ [ file-chooser? ] find-parent dup path>> ] dip
|
||||||
call
|
call
|
||||||
normalize-path swap set-model
|
normalize-path swap set-model
|
||||||
update-filelist-model
|
update-filelist-model
|
||||||
drop ;
|
drop ; inline
|
||||||
|
|
||||||
: fc-go-parent ( file-chooser -- )
|
: fc-go-parent ( file-chooser button -- )
|
||||||
[ dup value>> parent-directory ] (fc-go) ;
|
[ dup value>> parent-directory ] (fc-go) ;
|
||||||
|
|
||||||
: fc-go-home ( file-chooser -- )
|
: fc-go-home ( file-chooser button -- )
|
||||||
[ home ] (fc-go) ;
|
[ home ] (fc-go) ;
|
||||||
|
|
||||||
: fc-change-directory ( file-chooser file -- )
|
: fc-change-directory ( file-chooser file -- )
|
||||||
|
|
|
@ -40,7 +40,7 @@ M: ast-array infix-codegen
|
||||||
M: ast-op infix-codegen
|
M: ast-op infix-codegen
|
||||||
[ left>> infix-codegen ] [ right>> infix-codegen ]
|
[ left>> infix-codegen ] [ right>> infix-codegen ]
|
||||||
[ op>> select-op ] tri
|
[ op>> select-op ] tri
|
||||||
2over [ number? ] both? [ call ] [
|
2over [ number? ] both? [ call( a b -- c ) ] [
|
||||||
[ [ prepare-operand ] bi@ ] dip '[ @ @ @ ]
|
[ [ prepare-operand ] bi@ ] dip '[ @ @ @ ]
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
|
|
|
@ -141,7 +141,7 @@ TUPLE: key-caps-gadget < gadget keys alarm ;
|
||||||
swap [
|
swap [
|
||||||
" " [ drop ] <border-button>
|
" " [ drop ] <border-button>
|
||||||
swap [ first >>loc ] [ second >>dim ] bi
|
swap [ first >>loc ] [ second >>dim ] bi
|
||||||
] [ execute ] bi*
|
] [ execute( -- value ) ] bi*
|
||||||
] dip set-nth ;
|
] dip set-nth ;
|
||||||
|
|
||||||
: add-keys-gadgets ( gadget -- gadget )
|
: add-keys-gadgets ( gadget -- gadget )
|
||||||
|
|
|
@ -165,7 +165,7 @@ DEFER: (d)
|
||||||
swap call [ at 0 or ] curry map ; inline
|
swap call [ at 0 or ] curry map ; inline
|
||||||
|
|
||||||
: op-matrix ( domain range quot -- matrix )
|
: op-matrix ( domain range quot -- matrix )
|
||||||
rot [ [ 2dup ] dip (op-matrix) ] map 2nip ; inline
|
rot [ (op-matrix) ] with with map ; inline
|
||||||
|
|
||||||
: d-matrix ( domain range -- matrix )
|
: d-matrix ( domain range -- matrix )
|
||||||
[ (d) ] op-matrix ;
|
[ (d) ] op-matrix ;
|
||||||
|
|
|
@ -18,5 +18,5 @@ IN: math.binpack
|
||||||
[ dup zip ] dip binpack [ keys ] map ;
|
[ dup zip ] dip binpack [ keys ] map ;
|
||||||
|
|
||||||
: binpack! ( items quot n -- bins )
|
: binpack! ( items quot n -- bins )
|
||||||
[ dupd map zip ] dip binpack [ keys ] map ;
|
[ dupd map zip ] dip binpack [ keys ] map ; inline
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ M: satisfy-parser parse ( input parser -- list )
|
||||||
over empty? [
|
over empty? [
|
||||||
2drop nil
|
2drop nil
|
||||||
] [
|
] [
|
||||||
quot>> [ unclip-slice dup ] dip call
|
quot>> [ unclip-slice dup ] dip call( char -- ? )
|
||||||
[ swap <parse-results> ] [ 2drop nil ] if
|
[ swap <parse-results> ] [ 2drop nil ] if
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ IN: partial-continuations
|
||||||
USING: kernel continuations arrays sequences quotations ;
|
USING: kernel continuations arrays sequences quotations ;
|
||||||
|
|
||||||
: breset ( quot -- )
|
: breset ( quot -- )
|
||||||
[ 1array swap keep first continue-with ] callcc1 nip ;
|
[ 1array swap keep first continue-with ] callcc1 nip ; inline
|
||||||
|
|
||||||
: (bshift) ( v r k -- obj )
|
: (bshift) ( v r k -- obj )
|
||||||
[ dup first -rot ] dip
|
[ dup first -rot ] dip
|
||||||
|
|
|
@ -43,7 +43,7 @@ M: lex-hash at*
|
||||||
|
|
||||||
: parse* ( parser -- ast )
|
: parse* ( parser -- ast )
|
||||||
compile
|
compile
|
||||||
[ execute [ error-stack get first throw ] unless* ] with-global-lexer
|
[ execute( -- result ) [ error-stack get first throw ] unless* ] with-global-lexer
|
||||||
ast>> ;
|
ast>> ;
|
||||||
|
|
||||||
: create-bnf ( name parser -- )
|
: create-bnf ( name parser -- )
|
||||||
|
|
|
@ -95,7 +95,7 @@ PRIVATE>
|
||||||
: euler011 ( -- answer )
|
: euler011 ( -- answer )
|
||||||
[
|
[
|
||||||
{ [ horizontal ] [ vertical ] [ diagonal/ ] [ diagonal\ ] }
|
{ [ horizontal ] [ vertical ] [ diagonal/ ] [ diagonal\ ] }
|
||||||
[ call 4 max-product , ] each
|
[ call( -- matrix ) 4 max-product , ] each
|
||||||
] { } make supremum ;
|
] { } make supremum ;
|
||||||
|
|
||||||
! [ euler011 ] 100 ave-time
|
! [ euler011 ] 100 ave-time
|
||||||
|
|
|
@ -41,7 +41,7 @@ METHOD: expand { glob-expr }
|
||||||
[ ]
|
[ ]
|
||||||
if ;
|
if ;
|
||||||
|
|
||||||
METHOD: expand { factor-expr } expr>> eval unparse ;
|
METHOD: expand { factor-expr } expr>> eval>string ;
|
||||||
|
|
||||||
DEFER: expansion
|
DEFER: expansion
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ METHOD: expand { object } ;
|
||||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
: run-sword ( basic-expr -- )
|
: run-sword ( basic-expr -- )
|
||||||
command>> expansion unclip "shell" lookup execute ;
|
command>> expansion unclip "shell" lookup execute( arguments -- ) ;
|
||||||
|
|
||||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
|
|
|
@ -90,7 +90,7 @@ M: list focusable-child* drop t ;
|
||||||
|
|
||||||
: invoke-value-action ( list -- )
|
: invoke-value-action ( list -- )
|
||||||
dup list-empty? [
|
dup list-empty? [
|
||||||
dup hook>> call
|
dup hook>> call( list -- )
|
||||||
] [
|
] [
|
||||||
[ index>> ] keep nth-gadget invoke-secondary
|
[ index>> ] keep nth-gadget invoke-secondary
|
||||||
] if ;
|
] if ;
|
||||||
|
|
|
@ -20,8 +20,8 @@ DEFER: to-strings
|
||||||
dup class
|
dup class
|
||||||
{
|
{
|
||||||
{ \ string [ ] }
|
{ \ string [ ] }
|
||||||
{ \ quotation [ call ] }
|
{ \ quotation [ call( -- string ) ] }
|
||||||
{ \ word [ execute ] }
|
{ \ word [ execute( -- string ) ] }
|
||||||
{ \ fixnum [ number>string ] }
|
{ \ fixnum [ number>string ] }
|
||||||
{ \ array [ to-strings concat ] }
|
{ \ array [ to-strings concat ] }
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,8 +79,7 @@ site-watcher-db <alloy>
|
||||||
main-responder set-global
|
main-responder set-global
|
||||||
|
|
||||||
M: site-watcher-app init-user-profile
|
M: site-watcher-app init-user-profile
|
||||||
drop B
|
drop "username" value "email" value <account> insert-tuple ;
|
||||||
"username" value "email" value <account> insert-tuple ;
|
|
||||||
|
|
||||||
: init-db ( -- )
|
: init-db ( -- )
|
||||||
site-watcher-db [
|
site-watcher-db [
|
||||||
|
|
|
@ -12,7 +12,7 @@ CONSTANT: site-list-url URL" $site-watcher-app/spider-list"
|
||||||
{ site-watcher-app "spider-list" } >>template
|
{ site-watcher-app "spider-list" } >>template
|
||||||
[
|
[
|
||||||
! Silly query
|
! Silly query
|
||||||
username B spidering-sites [ site>> ] map
|
username spidering-sites [ site>> ] map
|
||||||
"sites" set-value
|
"sites" set-value
|
||||||
] >>init
|
] >>init
|
||||||
<protected>
|
<protected>
|
||||||
|
|
|
@ -58,7 +58,7 @@ SYMBOL: *calling*
|
||||||
swap [ * - ] keep 2array ;
|
swap [ * - ] keep 2array ;
|
||||||
|
|
||||||
: change-global ( variable quot -- )
|
: change-global ( variable quot -- )
|
||||||
global swap change-at ;
|
global swap change-at ; inline
|
||||||
|
|
||||||
: (correct-for-timing-overhead) ( timingshash -- timingshash )
|
: (correct-for-timing-overhead) ( timingshash -- timingshash )
|
||||||
time-dummy-word [ subtract-overhead ] curry assoc-map ;
|
time-dummy-word [ subtract-overhead ] curry assoc-map ;
|
||||||
|
@ -75,7 +75,7 @@ SYMBOL: *calling*
|
||||||
correct-for-timing-overhead
|
correct-for-timing-overhead
|
||||||
"total time:" write
|
"total time:" write
|
||||||
] dip pprint nl
|
] dip pprint nl
|
||||||
print-word-timings nl ;
|
print-word-timings nl ; inline
|
||||||
|
|
||||||
: profile-vocab ( vocab quot -- )
|
: profile-vocab ( vocab quot -- )
|
||||||
"annotating vocab..." print flush
|
"annotating vocab..." print flush
|
||||||
|
@ -88,4 +88,4 @@ SYMBOL: *calling*
|
||||||
correct-for-timing-overhead
|
correct-for-timing-overhead
|
||||||
"total time:" write
|
"total time:" write
|
||||||
] dip pprint
|
] dip pprint
|
||||||
print-word-timings ;
|
print-word-timings ; inline
|
||||||
|
|
Loading…
Reference in New Issue