JavaVM.st
changeset 524 c8a27ccbb61e
parent 523 4e94b5f76d80
child 526 a5c6d24f952b
--- a/JavaVM.st	Fri Jan 08 13:23:57 1999 +0000
+++ b/JavaVM.st	Fri Jan 08 14:13:48 1999 +0000
@@ -2462,6 +2462,22 @@
     "Modified: / 20.11.1998 / 13:27:14 / cg"
 !
 
+throwArrayIndexOutOfBoundsException:theArray _:badIndex
+    |exClass ex|
+
+"/    self 
+"/        throwExceptionClassName:'java.lang.ArrayIndexOutOfBoundsException' 
+"/        withMessage:'bad array index: ' , badIndex printString
+
+    exClass := Java classForName:'java.lang.ArrayIndexOutOfBoundsException'.
+    ex := exClass newWith_int:badIndex.
+
+    self throwException:ex
+
+    "Modified: / 20.11.1998 / 13:27:14 / cg"
+    "Created: / 8.1.1999 / 15:03:59 / cg"
+!
+
 throwClassNotFoundException
     self 
 	throwExceptionClassName:'java.lang.ClassNotFoundException' 
@@ -2480,6 +2496,15 @@
     "Modified: / 10.11.1998 / 13:20:31 / cg"
 !
 
+throwDivisionByZeroException
+    self halt:'division by zero'.
+    self
+        throwExceptionClassName:'java.lang.ArithmeticException'
+        withMessage:'division by zero'
+
+    "Created: / 8.1.1999 / 14:28:15 / cg"
+!
+
 throwException:aJavaException
     |con jMsg msg exClass srchCon handlerContext handlerPC method pc hPC|
 
@@ -10345,12 +10370,366 @@
 
 !JavaVM class methodsFor:'vm support'!
 
+_ARRAYLENGTH:arr
+    ^ arr size
+
+    "Created: / 8.1.1999 / 14:38:27 / cg"
+!
+
 _ATHROW:aJavaException
     self throwException:aJavaException.
 
     "Created: / 8.1.1999 / 14:15:36 / cg"
 !
 
+_CHECKCAST:anObject _:aClassOrInterface
+    "trampouline for unhandled cases ..."
+
+    aClassOrInterface isBehavior ifTrue:[
+        aClassOrInterface == ByteArray ifTrue:[
+            ^ anObject class == aClassOrInterface
+        ].
+
+        aClassOrInterface isInterface ifTrue:[
+            (anObject class hasInterface:aClassOrInterface) ifTrue:[
+                ^ true
+            ]
+        ].
+        (anObject isKindOf:aClassOrInterface) ifTrue:[
+            ^ true
+        ].
+        anObject isArray ifTrue:[
+            ^ true
+        ].
+        self halt.
+        ^ false.
+    ].
+    (aClassOrInterface isMemberOf:JavaClassPointerRef) ifTrue:[
+        "/ must be a pointer to an array of that class
+
+        anObject isArray ifTrue:[
+            ^ true
+        ].
+        self halt.
+        ^ false.
+    ].
+    (aClassOrInterface isMemberOf:JavaBuiltInClassPointerRef) ifTrue:[
+        aClassOrInterface arrayClass == anObject class ifTrue:[
+            ^ true
+        ].
+    ].
+
+    (anObject isMemberOf:Array) ifTrue:[
+        anObject size == 0 ifTrue:[
+            ^ true
+        ].
+        (self _CHECKCAST:(anObject at:1) _:(aClassOrInterface deref)) ifTrue:[
+            ^ true
+        ].
+        self halt.
+        ^ false
+    ].
+    self halt.
+    ^ false.
+
+    "Modified: / 10.11.1998 / 01:51:01 / cg"
+    "Created: / 8.1.1999 / 14:53:51 / cg"
+!
+
+_D2I:op1
+    |v|
+
+    v := op1 asInteger.
+    v > 16r7FFFFFFF ifTrue:[
+        self halt.
+        v := 16r7FFFFFFF
+    ] ifFalse:[
+        v < 16r80000000 negated ifTrue:[
+            self halt.
+            v := 16r80000000 negated
+        ]
+    ].
+    ^ v
+
+    "Modified: / 17.10.1998 / 21:55:49 / cg"
+    "Created: / 8.1.1999 / 14:47:13 / cg"
+!
+
+_D2L:op1
+    |v|
+
+    v := op1 asInteger.
+    v > 16r7FFFFFFFFFFFFFFF ifTrue:[
+        self halt.
+        v := 16r7FFFFFFFFFFFFFFF
+    ] ifFalse:[
+        v < 16r8000000000000000 negated ifTrue:[
+            self halt.
+            v := 16r8000000000000000 negated
+        ]
+    ].
+    ^ v
+
+    "Modified: / 17.10.1998 / 21:55:49 / cg"
+    "Created: / 8.1.1999 / 14:46:44 / cg"
+!
+
+_DADD:op1 _:op2
+    ^ op1 asFloat + op2 asFloat
+
+    "Created: / 8.1.1999 / 15:11:59 / cg"
+!
+
+_DDIV:op1 _:op2
+    ^ op1 asFloat / op2 asFloat.
+
+    "Created: / 8.1.1999 / 15:09:10 / cg"
+!
+
+_DMUL:op1 _:op2
+    ^ op1 asFloat * op2 asFloat
+
+    "Created: / 8.1.1999 / 14:49:52 / cg"
+!
+
+_DNEG:op
+    ^ op asFloat negated
+
+    "Created: / 8.1.1999 / 15:06:15 / cg"
+!
+
+_DSUB:op1 _:op2
+    ^ op1 asFloat - op2 asFloat
+
+    "Created: / 8.1.1999 / 15:10:59 / cg"
+!
+
+_F2I:op1
+    ^ self _D2I:op1
+
+    "Created: / 8.1.1999 / 14:47:42 / cg"
+!
+
+_F2L:op1
+    ^ self _D2L:op1
+
+    "Created: / 8.1.1999 / 14:47:53 / cg"
+!
+
+_FADD:op1 _:op2
+    ^ op1 asShortFloat + op2 asShortFloat
+
+    "Created: / 8.1.1999 / 15:11:36 / cg"
+!
+
+_FDIV:op1 _:op2
+    ^ op1 asShortFloat / op2 asShortFloat.
+
+    "Created: / 8.1.1999 / 15:09:32 / cg"
+!
+
+_FMUL:op1 _:op2
+    ^ op1 asShortFloat * op2 asShortFloat
+
+    "Created: / 8.1.1999 / 14:50:10 / cg"
+!
+
+_FNEG:op
+    ^ op asShortFloat negated
+
+    "Created: / 8.1.1999 / 15:06:33 / cg"
+!
+
+_FSUB:op1 _:op2
+    ^ op1 asShortFloat - op2 asShortFloat
+
+    "Created: / 8.1.1999 / 15:08:17 / cg"
+!
+
+_INSTANCEOF:anObject _:aClassOrInterface
+    "trampouline for unhandled cases ..."
+
+"/    aClassOrInterface isInterface ifTrue:[
+"/        (anObject class hasInterface:aClassOrInterface) ifTrue:[
+"/(aClassOrInterface name includesString:'LightweightPeer') ifTrue:[self halt].
+"/            ^ 1
+"/        ].
+"/    ].
+"/ (aClassOrInterface name includesString:'LightweightPeer') ifTrue:[self halt].
+
+    ^ 0.
+
+    "Modified: / 13.2.1998 / 18:03:03 / cg"
+    "Created: / 8.1.1999 / 14:52:54 / cg"
+!
+
+_L2D:op1
+    ^ op1 asFloat
+
+    "Created: / 8.1.1999 / 14:46:09 / cg"
+!
+
+_L2F:op1
+    ^ op1 asShortFloat
+
+    "Created: / 8.1.1999 / 14:46:18 / cg"
+    "Modified: / 8.1.1999 / 14:50:18 / cg"
+!
+
+_LADD:op1 _:op2
+    |sum|
+
+    sum := (op1 + op2) bitAnd:16rFFFFFFFFFFFFFFFF.
+    ^ sum
+
+    "Created: / 8.1.1999 / 15:07:39 / cg"
+!
+
+_LAND:op1 _:op2
+    |rslt|
+
+    (op1 < 0 or:[op2 < 0]) ifTrue:[
+        self halt.
+    ].
+    rslt := op1 bitAnd: op2.
+    ^ rslt
+
+    "Modified: / 7.1.1998 / 21:21:53 / cg"
+    "Created: / 8.1.1999 / 14:54:22 / cg"
+!
+
+_LDIV:op1 _:op2
+    |quo|
+
+    quo := op1 quo: op2.
+    ^ quo
+
+    "Created: / 8.1.1999 / 15:04:47 / cg"
+!
+
+_LMUL:op1 _:op2
+    |prod o1 o2 sign|
+
+"/ self halt.
+    "/ ST's largeIntegers compute a correct result;
+    "/ but here, we want the overflow to flow into the
+    "/ sign bit ... (sigh)
+
+    sign := 1.
+    (o1 := op1) < 0 ifTrue:[
+        sign := -1.
+        o1 := o1 negated.
+    ].
+    (o2 := op2) < 0 ifTrue:[
+        sign := sign negated.
+        o2 := o2 negated.
+    ].
+
+    prod := (o1 * o2) bitAnd:16rFFFFFFFFFFFFFFFF.
+    (prod bitAnd:16r8000000000000000) ~~ 0 ifTrue:[
+    ].
+    sign == -1 ifTrue:[
+        prod := prod negated
+    ].
+    ^ prod
+
+    "Created: / 8.1.1999 / 15:10:04 / cg"
+!
+
+_LNEG:op
+    ^ op asInteger negated
+
+    "Created: / 8.1.1999 / 15:06:59 / cg"
+!
+
+_LOR:op1 _:op2
+    |rslt|
+
+    (op1 < 0 or:[op2 < 0]) ifTrue:[
+        self halt.
+    ].
+    rslt := op1 bitOr: op2.
+    ^ rslt
+
+    "Created: / 8.1.1999 / 15:05:10 / cg"
+!
+
+_LREM:op1 _:op2
+    |rem|
+
+    rem := op1 rem: op2.
+    ^ rem
+
+    "Modified: / 7.1.1998 / 00:23:11 / cg"
+    "Created: / 8.1.1999 / 15:04:23 / cg"
+!
+
+_LSHL:op1 _:op2
+    |rslt|
+
+    (op1 < 0) ifTrue:[
+        self halt.
+    ].
+    rslt := (op1 bitShift:op2) bitAnd:16rFFFFFFFFFFFFFFFF.
+    ^ rslt
+
+    "Created: / 8.1.1999 / 14:51:08 / cg"
+!
+
+_LSHR:op1 _:op2
+    |rslt|
+
+    op1 < 0 ifTrue:[
+        self halt
+    ].
+
+    (op1 < 0) ifTrue:[
+        self halt.
+    ].
+    rslt := (op1 bitShift:op2 negated) bitAnd:16rFFFFFFFFFFFFFFFF.
+    ^ rslt
+
+    "Created: / 8.1.1999 / 14:51:57 / cg"
+!
+
+_LSUB:op1 _:op2
+    |diff|
+
+    diff := (op1 - op2) bitAnd:16rFFFFFFFFFFFFFFFF.
+    ^ diff
+
+    "Created: / 8.1.1999 / 15:10:33 / cg"
+!
+
+_LUSHR:op1 _:op2
+    |rslt|
+
+    op1 < 0 ifTrue:[
+        self halt
+    ].
+
+    (op1 < 0) ifTrue:[
+        self halt.
+    ].
+    rslt := (op1 bitShift:op2 negated) bitAnd:16rFFFFFFFFFFFFFFFF.
+    ^ rslt
+
+    "Modified: / 7.1.1998 / 21:22:17 / cg"
+    "Created: / 8.1.1999 / 14:51:32 / cg"
+!
+
+_LXOR:op1 _:op2
+    |rslt|
+
+    (op1 < 0 or:[op2 < 0]) ifTrue:[
+        self halt.
+    ].
+    rslt := op1 bitXor: op2.
+    ^ rslt
+
+    "Created: / 8.1.1999 / 15:12:28 / cg"
+!
+
 _MONITORENTER:someObject
     |mon thisProcess|
 
@@ -11006,6 +11385,6 @@
 !JavaVM class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /home/jv/Projects/SmalltalkX/repositories/cvs/stx/libjava/JavaVM.st,v 1.119 1999/01/08 13:23:57 cg Exp $'
+    ^ '$Header: /home/jv/Projects/SmalltalkX/repositories/cvs/stx/libjava/JavaVM.st,v 1.120 1999/01/08 14:13:48 cg Exp $'
 ! !
 JavaVM initialize!