]> gitweb.factorcode.org Git - factor.git/blob - basis/stack-checker/errors/errors.factor
Removing more >r/r> usages
[factor.git] / basis / stack-checker / errors / errors.factor
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
8
9 TUPLE: inference-error error type word ;
10
11 M: inference-error compiler-error-type type>> ;
12
13 M: inference-error error-help error>> error-help ;
14
15 : (inference-error) ( ... class type -- * )
16     [ boa ] dip
17     recursive-state get word>>
18     \ inference-error boa throw ; inline
19
20 : inference-error ( ... class -- * )
21     +error+ (inference-error) ; inline
22
23 : inference-warning ( ... class -- * )
24     +warning+ (inference-error) ; inline
25
26 M: inference-error error.
27     [ word>> [ "In word: " write . ] when* ] [ error>> error. ] bi ;
28
29 TUPLE: literal-expected ;
30
31 M: literal-expected summary
32     drop "Literal value expected" ;
33
34 M: object (literal) \ literal-expected inference-warning ;
35
36 TUPLE: unbalanced-branches-error branches quots ;
37
38 : unbalanced-branches-error ( branches quots -- * )
39     \ unbalanced-branches-error inference-error ;
40
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 ;
45
46 TUPLE: too-many->r ;
47
48 M: too-many->r summary
49     drop
50     "Quotation pushes elements on retain stack without popping them" ;
51
52 TUPLE: too-many-r> ;
53
54 M: too-many-r> summary
55     drop
56     "Quotation pops retain stack elements which it did not push" ;
57
58 TUPLE: missing-effect word ;
59
60 M: missing-effect error.
61     "The word " write
62     word>> pprint
63     " must declare a stack effect" print ;
64
65 TUPLE: effect-error word inferred declared ;
66
67 : effect-error ( word inferred declared -- * )
68     \ effect-error inference-error ;
69
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 ;
75
76 TUPLE: recursive-quotation-error quot ;
77
78 M: recursive-quotation-error error.
79     "The quotation " write
80     quot>> pprint
81     " calls itself." print
82     "Stack effect inference is undecidable when quotation-level recursion is permitted." print ;
83
84 TUPLE: undeclared-recursion-error word ;
85
86 M: undeclared-recursion-error error.
87     "The inline recursive word " write
88     word>> pprint
89     " must be declared recursive" print ;
90
91 TUPLE: diverging-recursion-error word ;
92
93 M: diverging-recursion-error error.
94     "The recursive word " write
95     word>> pprint
96     " digs arbitrarily deep into the stack" print ;
97
98 TUPLE: unbalanced-recursion-error word height ;
99
100 M: unbalanced-recursion-error error.
101     "The recursive word " write
102     word>> pprint
103     " leaves with the stack having the wrong height" print ;
104
105 TUPLE: inconsistent-recursive-call-error word ;
106
107 M: inconsistent-recursive-call-error error.
108     "The recursive word " write
109     word>> pprint
110     " calls itself with a different set of quotation parameters than were input" print ;
111
112 TUPLE: unknown-primitive-error ;
113
114 M: unknown-primitive-error error.
115     drop
116     "Cannot determine stack effect statically" print ;