117 lines
3.2 KiB
Factor
117 lines
3.2 KiB
Factor
! Copyright (C) 2006, 2008 Slava Pestov.
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
USING: kernel generic sequences prettyprint io words arrays
|
|
summary effects debugger assocs accessors namespaces
|
|
compiler.errors stack-checker.values
|
|
stack-checker.recursive-state ;
|
|
IN: stack-checker.errors
|
|
|
|
TUPLE: inference-error error type word ;
|
|
|
|
M: inference-error compiler-error-type type>> ;
|
|
|
|
M: inference-error error-help error>> error-help ;
|
|
|
|
: (inference-error) ( ... class type -- * )
|
|
>r boa r>
|
|
recursive-state get word>>
|
|
\ inference-error boa throw ; inline
|
|
|
|
: inference-error ( ... class -- * )
|
|
+error+ (inference-error) ; inline
|
|
|
|
: inference-warning ( ... class -- * )
|
|
+warning+ (inference-error) ; inline
|
|
|
|
M: inference-error error.
|
|
[ word>> [ "In word: " write . ] when* ] [ error>> error. ] bi ;
|
|
|
|
TUPLE: literal-expected ;
|
|
|
|
M: literal-expected summary
|
|
drop "Literal value expected" ;
|
|
|
|
M: object (literal) \ literal-expected inference-warning ;
|
|
|
|
TUPLE: unbalanced-branches-error branches quots ;
|
|
|
|
: unbalanced-branches-error ( branches quots -- * )
|
|
\ unbalanced-branches-error inference-error ;
|
|
|
|
M: unbalanced-branches-error error.
|
|
"Unbalanced branches:" print
|
|
[ quots>> ] [ branches>> [ length <effect> ] { } assoc>map ] bi zip
|
|
[ [ first pprint-short bl ] [ second effect>string print ] bi ] each ;
|
|
|
|
TUPLE: too-many->r ;
|
|
|
|
M: too-many->r summary
|
|
drop
|
|
"Quotation pushes elements on retain stack without popping them" ;
|
|
|
|
TUPLE: too-many-r> ;
|
|
|
|
M: too-many-r> summary
|
|
drop
|
|
"Quotation pops retain stack elements which it did not push" ;
|
|
|
|
TUPLE: missing-effect word ;
|
|
|
|
M: missing-effect error.
|
|
"The word " write
|
|
word>> pprint
|
|
" must declare a stack effect" print ;
|
|
|
|
TUPLE: effect-error word inferred declared ;
|
|
|
|
: effect-error ( word inferred declared -- * )
|
|
\ effect-error inference-error ;
|
|
|
|
M: effect-error error.
|
|
"Stack effects of the word " write
|
|
[ word>> pprint " do not match." print ]
|
|
[ "Inferred: " write inferred>> . ]
|
|
[ "Declared: " write declared>> . ] tri ;
|
|
|
|
TUPLE: recursive-quotation-error quot ;
|
|
|
|
M: recursive-quotation-error error.
|
|
"The quotation " write
|
|
quot>> pprint
|
|
" calls itself." print
|
|
"Stack effect inference is undecidable when quotation-level recursion is permitted." print ;
|
|
|
|
TUPLE: undeclared-recursion-error word ;
|
|
|
|
M: undeclared-recursion-error error.
|
|
"The inline recursive word " write
|
|
word>> pprint
|
|
" must be declared recursive" print ;
|
|
|
|
TUPLE: diverging-recursion-error word ;
|
|
|
|
M: diverging-recursion-error error.
|
|
"The recursive word " write
|
|
word>> pprint
|
|
" digs arbitrarily deep into the stack" print ;
|
|
|
|
TUPLE: unbalanced-recursion-error word height ;
|
|
|
|
M: unbalanced-recursion-error error.
|
|
"The recursive word " write
|
|
word>> pprint
|
|
" leaves with the stack having the wrong height" print ;
|
|
|
|
TUPLE: inconsistent-recursive-call-error word ;
|
|
|
|
M: inconsistent-recursive-call-error error.
|
|
"The recursive word " write
|
|
word>> pprint
|
|
" calls itself with a different set of quotation parameters than were input" print ;
|
|
|
|
TUPLE: unknown-primitive-error ;
|
|
|
|
M: unknown-primitive-error error.
|
|
drop
|
|
"Cannot determine stack effect statically" print ;
|