2009-03-16 21:11:36 -04:00
|
|
|
! Copyright (C) 2007, 2009 Slava Pestov, Daniel Ehrenberg.
|
2008-07-20 05:24:37 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2009-03-16 21:11:36 -04:00
|
|
|
USING: fry accessors arrays kernel kernel.private combinators.private
|
2009-04-22 22:26:55 -04:00
|
|
|
words sequences generic math math.order namespaces quotations
|
2009-04-11 21:30:51 -04:00
|
|
|
assocs combinators combinators.short-circuit classes.tuple
|
2009-05-14 17:54:16 -04:00
|
|
|
classes.tuple.private effects summary hashtables classes sets
|
2009-03-21 04:10:21 -04:00
|
|
|
definitions generic.standard slots.private continuations locals
|
2009-04-11 21:30:51 -04:00
|
|
|
sequences.private generalizations stack-checker.backend
|
|
|
|
stack-checker.state stack-checker.visitor stack-checker.errors
|
2009-11-08 21:34:46 -05:00
|
|
|
stack-checker.values stack-checker.recursive-state
|
|
|
|
stack-checker.dependencies ;
|
2010-02-26 16:01:01 -05:00
|
|
|
FROM: namespaces => set ;
|
2008-07-20 05:24:37 -04:00
|
|
|
IN: stack-checker.transforms
|
|
|
|
|
2009-11-09 01:17:24 -05:00
|
|
|
: call-transformer ( stack quot -- newquot )
|
|
|
|
'[ _ _ with-datastack [ length 1 assert= ] [ first ] bi ]
|
|
|
|
[ error-continuation get current-word get transform-expansion-error ]
|
2009-04-10 08:08:16 -04:00
|
|
|
recover ;
|
|
|
|
|
2009-11-09 01:17:24 -05:00
|
|
|
:: ((apply-transform)) ( quot values stack rstate -- )
|
|
|
|
rstate recursive-state [ stack quot call-transformer ] with-variable
|
2010-03-07 23:44:50 -05:00
|
|
|
values [ length shorten-d ] [ #drop, ] bi
|
2009-11-09 01:17:24 -05:00
|
|
|
rstate infer-quot ;
|
2008-08-10 23:22:26 -04:00
|
|
|
|
2009-11-09 01:17:24 -05:00
|
|
|
: literal-values? ( values -- ? ) [ literal-value? ] all? ;
|
2009-02-06 11:21:55 -05:00
|
|
|
|
2009-11-09 01:17:24 -05:00
|
|
|
: input-values? ( values -- ? )
|
|
|
|
[ { [ literal-value? ] [ input-value? ] } 1|| ] all? ;
|
|
|
|
|
|
|
|
: (apply-transform) ( quot n -- )
|
|
|
|
ensure-d {
|
|
|
|
{ [ dup literal-values? ] [
|
|
|
|
dup empty? [ dup recursive-state get ] [
|
|
|
|
[ ]
|
|
|
|
[ [ literal value>> ] map ]
|
|
|
|
[ first literal recursion>> ] tri
|
|
|
|
] if
|
|
|
|
((apply-transform))
|
|
|
|
] }
|
|
|
|
{ [ dup input-values? ] [ drop current-word get unknown-macro-input ] }
|
|
|
|
[ drop current-word get bad-macro-input ]
|
|
|
|
} cond ;
|
2008-07-23 01:17:08 -04:00
|
|
|
|
|
|
|
: apply-transform ( word -- )
|
2009-11-09 01:17:24 -05:00
|
|
|
[ current-word set ]
|
|
|
|
[ "transform-quot" word-prop ]
|
|
|
|
[ "transform-n" word-prop ] tri
|
2009-02-06 05:38:54 -05:00
|
|
|
(apply-transform) ;
|
2008-07-23 01:17:08 -04:00
|
|
|
|
|
|
|
: apply-macro ( word -- )
|
2009-11-09 01:17:24 -05:00
|
|
|
[ current-word set ]
|
|
|
|
[ "macro" word-prop ]
|
|
|
|
[ "declared-effect" word-prop in>> length ] tri
|
2009-02-06 05:38:54 -05:00
|
|
|
(apply-transform) ;
|
2008-07-20 05:24:37 -04:00
|
|
|
|
|
|
|
: define-transform ( word quot n -- )
|
2008-08-31 20:17:04 -04:00
|
|
|
[ drop "transform-quot" set-word-prop ]
|
|
|
|
[ nip "transform-n" set-word-prop ]
|
2008-07-23 01:17:08 -04:00
|
|
|
3bi ;
|
2008-07-20 05:24:37 -04:00
|
|
|
|
|
|
|
! Combinators
|
|
|
|
\ cond [ cond>quot ] 1 define-transform
|
|
|
|
|
2009-04-20 19:44:45 -04:00
|
|
|
\ cond t "no-compile" set-word-prop
|
|
|
|
|
2008-07-20 05:24:37 -04:00
|
|
|
\ case [
|
2008-09-06 20:13:59 -04:00
|
|
|
[
|
|
|
|
[ no-case ]
|
2008-07-20 05:24:37 -04:00
|
|
|
] [
|
2010-07-30 14:09:56 -04:00
|
|
|
dup [ callable? ] find dup
|
|
|
|
[ [ head ] dip ] [ 2drop [ no-case ] ] if
|
|
|
|
swap case>quot
|
2008-09-06 20:13:59 -04:00
|
|
|
] if-empty
|
2008-07-20 05:24:37 -04:00
|
|
|
] 1 define-transform
|
|
|
|
|
2009-04-20 19:44:45 -04:00
|
|
|
\ case t "no-compile" set-word-prop
|
|
|
|
|
2008-07-20 05:24:37 -04:00
|
|
|
\ cleave [ cleave>quot ] 1 define-transform
|
|
|
|
|
2009-04-20 19:44:45 -04:00
|
|
|
\ cleave t "no-compile" set-word-prop
|
|
|
|
|
2008-07-20 05:24:37 -04:00
|
|
|
\ 2cleave [ 2cleave>quot ] 1 define-transform
|
|
|
|
|
2009-04-20 19:44:45 -04:00
|
|
|
\ 2cleave t "no-compile" set-word-prop
|
|
|
|
|
2008-07-20 05:24:37 -04:00
|
|
|
\ 3cleave [ 3cleave>quot ] 1 define-transform
|
|
|
|
|
2009-04-20 19:44:45 -04:00
|
|
|
\ 3cleave t "no-compile" set-word-prop
|
|
|
|
|
2012-09-28 12:16:08 -04:00
|
|
|
\ 4cleave [ 4cleave>quot ] 1 define-transform
|
|
|
|
|
|
|
|
\ 4cleave t "no-compile" set-word-prop
|
|
|
|
|
2011-10-02 23:25:39 -04:00
|
|
|
\ spread [ deep-spread>quot ] 1 define-transform
|
2008-07-20 05:24:37 -04:00
|
|
|
|
2009-04-20 19:44:45 -04:00
|
|
|
\ spread t "no-compile" set-word-prop
|
|
|
|
|
2009-07-18 04:33:45 -04:00
|
|
|
\ 0&& [ '[ _ 0 n&& ] ] 1 define-transform
|
|
|
|
|
|
|
|
\ 0&& t "no-compile" set-word-prop
|
|
|
|
|
|
|
|
\ 1&& [ '[ _ 1 n&& ] ] 1 define-transform
|
|
|
|
|
|
|
|
\ 1&& t "no-compile" set-word-prop
|
|
|
|
|
|
|
|
\ 2&& [ '[ _ 2 n&& ] ] 1 define-transform
|
|
|
|
|
|
|
|
\ 2&& t "no-compile" set-word-prop
|
|
|
|
|
|
|
|
\ 3&& [ '[ _ 3 n&& ] ] 1 define-transform
|
|
|
|
|
|
|
|
\ 3&& t "no-compile" set-word-prop
|
|
|
|
|
|
|
|
\ 0|| [ '[ _ 0 n|| ] ] 1 define-transform
|
|
|
|
|
|
|
|
\ 0|| t "no-compile" set-word-prop
|
|
|
|
|
|
|
|
\ 1|| [ '[ _ 1 n|| ] ] 1 define-transform
|
|
|
|
|
|
|
|
\ 1|| t "no-compile" set-word-prop
|
|
|
|
|
|
|
|
\ 2|| [ '[ _ 2 n|| ] ] 1 define-transform
|
|
|
|
|
|
|
|
\ 2|| t "no-compile" set-word-prop
|
|
|
|
|
|
|
|
\ 3|| [ '[ _ 3 n|| ] ] 1 define-transform
|
|
|
|
|
|
|
|
\ 3|| t "no-compile" set-word-prop
|
|
|
|
|
2010-01-29 10:12:09 -05:00
|
|
|
: add-next-method-dependency ( method -- )
|
|
|
|
[ "method-class" word-prop ]
|
|
|
|
[ "method-generic" word-prop ] bi
|
|
|
|
2dup next-method
|
2012-06-21 02:55:24 -04:00
|
|
|
add-depends-on-next-method ;
|
2010-01-29 10:12:09 -05:00
|
|
|
|
2008-08-10 23:22:26 -04:00
|
|
|
\ (call-next-method) [
|
2010-01-29 10:12:09 -05:00
|
|
|
[ add-next-method-dependency ]
|
|
|
|
[ [ next-method-quot ] [ '[ _ no-next-method ] ] bi or ] bi
|
2008-11-22 20:57:25 -05:00
|
|
|
] 1 define-transform
|
2008-08-10 23:22:26 -04:00
|
|
|
|
2009-04-20 19:44:45 -04:00
|
|
|
\ (call-next-method) t "no-compile" set-word-prop
|
|
|
|
|
2008-08-10 23:22:26 -04:00
|
|
|
! Constructors
|
2008-07-20 05:24:37 -04:00
|
|
|
\ boa [
|
|
|
|
dup tuple-class? [
|
2010-01-29 09:04:51 -05:00
|
|
|
dup tuple-layout
|
2012-06-21 02:55:24 -04:00
|
|
|
[ add-depends-on-tuple-layout ]
|
2010-01-29 09:04:51 -05:00
|
|
|
[ [ "boa-check" word-prop [ ] or ] dip ] 2bi
|
|
|
|
'[ @ _ <tuple-boa> ]
|
2010-07-17 15:57:44 -04:00
|
|
|
] [
|
|
|
|
\ boa time-bomb
|
|
|
|
] if
|
2008-08-10 23:22:26 -04:00
|
|
|
] 1 define-transform
|
|
|
|
|
2009-04-20 19:44:45 -04:00
|
|
|
\ boa t "no-compile" set-word-prop
|