1 ! Copyright (C) 2006, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel generic sequences prettyprint io words arrays
4 summary effects debugger assocs accessors namespaces
5 compiler.errors stack-checker.values
6 stack-checker.recursive-state ;
7 IN: stack-checker.errors
9 TUPLE: inference-error error type word ;
11 M: inference-error compiler-error-type type>> ;
13 M: inference-error error-help error>> error-help ;
15 : (inference-error) ( ... class type -- * )
17 recursive-state get word>>
18 \ inference-error boa throw ; inline
20 : inference-error ( ... class -- * )
21 +error+ (inference-error) ; inline
23 : inference-warning ( ... class -- * )
24 +warning+ (inference-error) ; inline
26 M: inference-error error.
27 [ word>> [ "In word: " write . ] when* ] [ error>> error. ] bi ;
29 TUPLE: literal-expected ;
31 M: literal-expected summary
32 drop "Literal value expected" ;
34 M: object (literal) \ literal-expected inference-warning ;
36 TUPLE: unbalanced-branches-error branches quots ;
38 : unbalanced-branches-error ( branches quots -- * )
39 \ unbalanced-branches-error inference-error ;
41 M: unbalanced-branches-error error.
42 "Unbalanced branches:" print
43 [ quots>> ] [ branches>> [ length <effect> ] { } assoc>map ] bi zip
44 [ [ first pprint-short bl ] [ second effect>string print ] bi ] each ;
48 M: too-many->r summary
50 "Quotation pushes elements on retain stack without popping them" ;
54 M: too-many-r> summary
56 "Quotation pops retain stack elements which it did not push" ;
58 TUPLE: missing-effect word ;
60 M: missing-effect error.
63 " must declare a stack effect" print ;
65 TUPLE: effect-error word inferred declared ;
67 : effect-error ( word inferred declared -- * )
68 \ effect-error inference-error ;
70 M: effect-error error.
71 "Stack effects of the word " write
72 [ word>> pprint " do not match." print ]
73 [ "Inferred: " write inferred>> . ]
74 [ "Declared: " write declared>> . ] tri ;
76 TUPLE: recursive-quotation-error quot ;
78 M: recursive-quotation-error error.
79 "The quotation " write
81 " calls itself." print
82 "Stack effect inference is undecidable when quotation-level recursion is permitted." print ;
84 TUPLE: undeclared-recursion-error word ;
86 M: undeclared-recursion-error error.
87 "The inline recursive word " write
89 " must be declared recursive" print ;
91 TUPLE: diverging-recursion-error word ;
93 M: diverging-recursion-error error.
94 "The recursive word " write
96 " digs arbitrarily deep into the stack" print ;
98 TUPLE: unbalanced-recursion-error word height ;
100 M: unbalanced-recursion-error error.
101 "The recursive word " write
103 " leaves with the stack having the wrong height" print ;
105 TUPLE: inconsistent-recursive-call-error word ;
107 M: inconsistent-recursive-call-error error.
108 "The recursive word " write
110 " calls itself with a different set of quotation parameters than were input" print ;
112 TUPLE: unknown-primitive-error ;
114 M: unknown-primitive-error error.
116 "Cannot determine stack effect statically" print ;