forked from ppedemon/hava
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVMErr.hs
119 lines (96 loc) · 3.98 KB
/
VMErr.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
module VMErr
-- Functions for putting the VM in a specific error state
-- The internal def of VMErr and Error is used only in the RefSolver module
(VMErr(..)
,Error(..)
,clsFormatErr
,noClsDefFoundErr
,clsCircularityErr
,incompClsChangeErr
,unsupportedClsVersionErr
,illegalAccessErr
,noSuchFieldErr
,noSuchMethodErr
,abstractMethodErr
,clsCastException
,nullPointerException
,arrayIndexOutOfBoundsException
,instantiationErr
,negativeArraySizeException
,arithmeticException
,getErrorRef
) where
import ClassRep(ClassRef(U))
-----------------------------------------------------------------
-- A compendium of the errors and exceptions a JVM
-- can throw during its lifetime
-----------------------------------------------------------------
data VMErr = VMErr Error String deriving Show
data Error = ClsFormatErr
| NoClsDefFoundErr
| ClsCircularityErr
| IncompClsChangeErr
| UnsupportedClsVersionErr
| IllegalAccessErr
| NoSuchFieldErr
| NoSuchMethodErr
| AbstractMethodErr
| ClsCastException
| NullPointerException
| ArrayIndexOutOfBoundsException
| InstantiationError
| NegativeArraySizeException
| ArithmeticException
deriving (Eq,Show)
clsFormatErr :: String -> VMErr
clsFormatErr = VMErr ClsFormatErr
noClsDefFoundErr :: String -> VMErr
noClsDefFoundErr = VMErr NoClsDefFoundErr
clsCircularityErr :: String -> VMErr
clsCircularityErr = VMErr ClsCircularityErr
incompClsChangeErr :: String -> VMErr
incompClsChangeErr = VMErr IncompClsChangeErr
unsupportedClsVersionErr :: String -> VMErr
unsupportedClsVersionErr = VMErr UnsupportedClsVersionErr
illegalAccessErr :: String -> VMErr
illegalAccessErr = VMErr IllegalAccessErr
noSuchFieldErr :: String -> VMErr
noSuchFieldErr = VMErr NoSuchFieldErr
noSuchMethodErr :: String -> VMErr
noSuchMethodErr = VMErr NoSuchMethodErr
abstractMethodErr :: String -> VMErr
abstractMethodErr = VMErr AbstractMethodErr
clsCastException :: String -> VMErr
clsCastException = VMErr ClsCastException
nullPointerException :: String -> VMErr
nullPointerException = VMErr NullPointerException
arrayIndexOutOfBoundsException :: String -> VMErr
arrayIndexOutOfBoundsException = VMErr ArrayIndexOutOfBoundsException
instantiationErr :: String -> VMErr
instantiationErr = VMErr InstantiationError
negativeArraySizeException :: String -> VMErr
negativeArraySizeException= VMErr NegativeArraySizeException
arithmeticException :: String -> VMErr
arithmeticException = VMErr ArithmeticException
getErrorRef :: VMErr -> ClassRef
getErrorRef (VMErr e _) =
case lookup e vmErrAssoc of
Nothing -> error $ "getErrorRef: not a VM error " ++ show e
Just ref -> ref
vmErrAssoc :: [(Error,ClassRef)]
vmErrAssoc = [
(ClsFormatErr, U "java/lang/ClassFormatError"),
(NoClsDefFoundErr, U "java/lang/NoClassDefFoundError"),
(ClsCircularityErr, U "java/lang/ClassCircularityError"),
(IncompClsChangeErr, U "java/lang/IncompatibleClassChangeError"),
(UnsupportedClsVersionErr, U "java/lang/UnsupportedClassVersionError"),
(IllegalAccessErr, U "java/lang/IllegalAccessError"),
(NoSuchFieldErr, U "java/lang/NoSuchFieldError"),
(NoSuchMethodErr, U "java/lang/NoSuchMethodError"),
(AbstractMethodErr, U "java/lang/AbstractMethodError"),
(ClsCastException, U "java/lang/ClassCastException"),
(NullPointerException, U "java/lang/NullPointerException"),
(ArrayIndexOutOfBoundsException, U "java/lang/ArrayIndexOutOfBoundsException"),
(InstantiationError, U "java/lang/InstantiationError"),
(NegativeArraySizeException, U "java/lang/NegativeArraySizeException"),
(ArithmeticException, U "java/lang/ArithmeticException")]