! (c)Joe Groff bsd license
-USING: alien.syntax arrays assocs biassocs combinators continuations
-generalizations kernel literals locals math math.bitwise
-sequences sets system vocabs.loader ;
+USING: alien.syntax arrays assocs biassocs combinators
+combinators.short-circuit continuations generalizations kernel
+literals locals math math.bitwise sequences sets system
+vocabs ;
IN: math.floats.env
SINGLETONS:
} spread
] 4 ncurry change-fp-env-registers ;
+CONSTANT: vm-error-exception-flag>bit
+ H{
+ { +fp-invalid-operation+ 0x01 }
+ { +fp-overflow+ 0x02 }
+ { +fp-underflow+ 0x04 }
+ { +fp-zero-divide+ 0x08 }
+ { +fp-inexact+ 0x10 }
+ }
+
PRIVATE>
: fp-exception-flags ( -- exceptions )
: collect-fp-exceptions ( quot -- exceptions )
[ clear-fp-exception-flags ] dip call fp-exception-flags ; inline
+: vm-error>exception-flags ( error -- exceptions )
+ third vm-error-exception-flag>bit mask> ;
+: vm-error-exception-flag? ( error flag -- ? )
+ vm-error>exception-flags member? ;
+
: denormal-mode ( -- mode ) fp-env-register (get-denormal-mode) ;
:: with-denormal-mode ( mode quot -- )
(fp-env-registers) [ (get-fp-traps) ] [ union ] map-reduce >array ; inline
:: with-fp-traps ( exceptions quot -- )
+ clear-fp-exception-flags
fp-traps :> orig
exceptions set-fp-traps
quot [ orig set-fp-traps ] [ ] cleanup ; inline