1 ! Copyright (C) 2008, 2010 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: assocs arrays namespaces sequences kernel definitions
4 math effects accessors words fry classes.algebra
5 compiler.units stack-checker.values stack-checker.visitor
7 IN: stack-checker.state
9 ! Did the current control-flow path throw an error?
12 ! Number of inputs current word expects from the stack
16 DEFER: commit-literals
21 : meta-d ( -- stack ) commit-literals (meta-d) get ;
23 : meta-r ( -- stack ) (meta-r) get ;
27 : (push-literal) ( obj -- )
28 dup <literal> make-known
29 [ nip (meta-d) get push ] [ #push, ] 2bi ;
31 : commit-literals ( -- )
33 [ [ (push-literal) ] each ] [ delete-all ] bi
36 : current-stack-height ( -- n ) meta-d length input-count get - ;
38 : current-effect ( -- effect )
39 input-count get "x" <array>
40 meta-d length "x" <array>
41 terminated? get <terminated-effect> ;
43 : check-effect ( required-effect -- )
44 [ current-effect ] dip 2dup effect<= [ 2drop ] [ effect-error ] if ;
46 : init-inference ( -- )
48 V{ } clone (meta-d) set
49 V{ } clone literals set