| @@ -0,0 +1,690 @@ |
| 1 | +# |
| 2 | +# jni -- java native interface |
| 3 | +# |
| 4 | +# this module defines the limbo helper |
| 5 | +# functions for java class library |
| 6 | +# native methods (limbo). |
| 7 | +# |
| 8 | +# This module is based on the JNI |
| 9 | +# specification from JavaSoft for |
| 10 | +# VM implementations supporting a C/C++ |
| 11 | +# interface. |
| 12 | +# |
| 13 | + |
| 14 | +include "sys.m"; |
| 15 | +include "math.m"; |
| 16 | +include "string.m"; |
| 17 | +include "loader.m"; |
| 18 | +include "classloader.m"; |
| 19 | +include "cast.m"; |
| 20 | + |
| 21 | +JNI : module |
| 22 | +{ |
| 23 | + # where to find jni.dis |
| 24 | + PATH : con "/dis/java/jni.dis"; |
| 25 | + |
| 26 | + # |
| 27 | + # exported read-only vars |
| 28 | + # upon JNI initialization the following |
| 29 | + # variables are assigned. Native method modules |
| 30 | + # can use the following instances rather than |
| 31 | + # loading their own copies. These variables |
| 32 | + # should never be assigned. |
| 33 | + sys : Sys; # std inferno sys module |
| 34 | + math : Math; # std inferno math module |
| 35 | + str : String; # std inferno string module |
| 36 | + jldr : JavaClassLoader; # primary java class loader |
| 37 | + jassist : JavaAssist; # java assist module |
| 38 | + |
| 39 | + # boolean constants |
| 40 | + FALSE : con 0; |
| 41 | + TRUE : con 1; |
| 42 | + BFALSE : con byte 0; |
| 43 | + BTRUE : con byte 1; |
| 44 | + |
| 45 | + # return error flags for JNI functions |
| 46 | + OK : con 0; |
| 47 | + ERR : con -1; |
| 48 | + |
| 49 | + # JVM Type Constants: used for identifying Java primitive types. |
| 50 | + T_JVMSTART : con 4; |
| 51 | + T_BOOLEAN, T_CHAR, T_FLOAT, T_DOUBLE, T_BYTE, T_SHORT, |
| 52 | + T_INT, T_LONG, T_OBJECT, T_ARRAY, T_VOID, |
| 53 | + T_JVMLAST |
| 54 | + : con (iota + T_JVMSTART); |
| 55 | + |
| 56 | + # JVM class flags constants |
| 57 | + ACC_PUBLIC: con 16r0001; |
| 58 | + ACC_PRIVATE: con 16r0002; |
| 59 | + ACC_PROTECTED: con 16r0004; |
| 60 | + ACC_STATIC: con 16r0008; |
| 61 | + ACC_FINAL: con 16r0010; |
| 62 | + ACC_SUPER: con 16r0020; |
| 63 | + ACC_SYNCHRONIZED: con 16r0020; |
| 64 | + ACC_VOLATILE: con 16r0040; |
| 65 | + ACC_TRANSIENT: con 16r0080; |
| 66 | + ACC_NATIVE: con 16r0100; |
| 67 | + ACC_INTERFACE: con 16r0200; |
| 68 | + ACC_ABSTRACT: con 16r0400; |
| 69 | + |
| 70 | + ACC_WRITTEN_FLAGS: con 16r0fff; |
| 71 | + |
| 72 | + |
| 73 | + # common java types |
| 74 | + |
| 75 | + # |
| 76 | + # The following two types are used to represent |
| 77 | + # Java classes. The 'ClassData' type contains all |
| 78 | + # of the information pertaining to a class and is |
| 79 | + # used to obtain class information and instantiate |
| 80 | + # objects. Although there is information in the |
| 81 | + # structure it should normally be treated as an |
| 82 | + # opaque type by client native method modules. |
| 83 | + # |
| 84 | + ClassModule : type ref Loader->Niladt; |
| 85 | + ClassData : type ref JavaClassLoader->Class; |
| 86 | + |
| 87 | + # |
| 88 | + # This is the "generic" type of any Java instance. |
| 89 | + # Operations on the object can be performed via this |
| 90 | + # generic handle. |
| 91 | + # |
| 92 | + JObject : type ref JavaClassLoader->Object; |
| 93 | + |
| 94 | + # |
| 95 | + # This represents an instance of java.lang.Class |
| 96 | + # It is an object which contains a ptr to the |
| 97 | + # actual class data it represents. |
| 98 | + # |
| 99 | + JClass : type ref JavaClassLoader->ClassObject; |
| 100 | + |
| 101 | + # |
| 102 | + # This is an instance of java.lang.String. |
| 103 | + # This class is a wrapper of a Dis string. |
| 104 | + # |
| 105 | + JString : type ref JavaClassLoader->JavaString; |
| 106 | + |
| 107 | + JBoolean : type int; |
| 108 | + |
| 109 | + # Java arrays are actually classes |
| 110 | + # which wrap a Dis array. The array |
| 111 | + # class matches the adt 'Array' defined |
| 112 | + # in JavaClassLoader. The following arrays |
| 113 | + # should mirror that adt and are used by |
| 114 | + # limbo modules to access the array contents |
| 115 | + # directly. Java Arrays should only be created |
| 116 | + # in Java code or via the Array functions |
| 117 | + # below. A simple limbo instance of the |
| 118 | + # array adt's is not good enough. |
| 119 | + |
| 120 | + # JArray is used as a "generic" array and to represent |
| 121 | + # multi-dimensional arrays. |
| 122 | + JArray : type ref JavaClassLoader->Array; # x[][].. |
| 123 | + |
| 124 | + IntArray : adt |
| 125 | + { |
| 126 | + cl_mod: ref Loader->Niladt; # object's class data |
| 127 | + ary: array of int; # actual dis array |
| 128 | + dims: int; # number of dimensions |
| 129 | + class: ClassData; # class data of base type |
| 130 | + primitive: int; # set if base type is primitive |
| 131 | + }; |
| 132 | + |
| 133 | + ByteArray : adt |
| 134 | + { |
| 135 | + cl_mod: ref Loader->Niladt; # object's class data |
| 136 | + ary: array of byte; # actual dis array |
| 137 | + dims: int; # number of dimensions |
| 138 | + class: ClassData; # class data of base type |
| 139 | + primitive: int; # set if base type is primitive |
| 140 | + }; |
| 141 | + |
| 142 | + BigArray : adt |
| 143 | + { |
| 144 | + cl_mod: ref Loader->Niladt; # object's class data |
| 145 | + ary: array of big; # actual dis array |
| 146 | + dims: int; # number of dimensions |
| 147 | + class: ClassData; # class data of base type |
| 148 | + primitive: int; # set if base type is primitive |
| 149 | + }; |
| 150 | + |
| 151 | + RealArray : adt |
| 152 | + { |
| 153 | + cl_mod: ref Loader->Niladt; # object's class data |
| 154 | + ary: array of real; # actual dis array |
| 155 | + dims: int; # number of dimensions |
| 156 | + class: ClassData; # class data of base type |
| 157 | + primitive: int; # set if base type is primitive |
| 158 | + }; |
| 159 | + |
| 160 | + StringArray : adt |
| 161 | + { |
| 162 | + cl_mod: ref Loader->Niladt; # object's class data |
| 163 | + ary: array of JString; # actual dis array |
| 164 | + dims: int; # number of dimensions |
| 165 | + class: ClassData; # class data of base type |
| 166 | + primitive: int; # set if base type is primitive |
| 167 | + }; |
| 168 | + |
| 169 | + ClassArray : adt |
| 170 | + { |
| 171 | + cl_mod: ref Loader->Niladt; # object's class data |
| 172 | + ary: array of JClass; # actual dis array |
| 173 | + dims: int; # number of dimensions |
| 174 | + class: ClassData; # class data of base type |
| 175 | + primitive: int; # set if base type is primitive |
| 176 | + }; |
| 177 | + |
| 178 | + ObjectArray : adt |
| 179 | + { |
| 180 | + cl_mod: ref Loader->Niladt; # object's class data |
| 181 | + ary: array of JObject; # actual dis array |
| 182 | + dims: int; # number of dimensions |
| 183 | + class: ClassData; # class data of base type |
| 184 | + primitive: int; # set if base type is primitive |
| 185 | + }; |
| 186 | + |
| 187 | + ArrayArray : adt |
| 188 | + { |
| 189 | + cl_mod: ref Loader->Niladt; # object's class data |
| 190 | + ary: array of JArray; # actual dis array |
| 191 | + dims: int; # number of dimensions |
| 192 | + class: ClassData; # class data of base type |
| 193 | + primitive: int; # set if base type is primitive |
| 194 | + }; |
| 195 | + |
| 196 | + # |
| 197 | + # Common type names emitted by 'javal'. |
| 198 | + # |
| 199 | + JArrayI : type ref IntArray; # int[] |
| 200 | + JArrayC : type ref IntArray; # char[] |
| 201 | + JArrayB : type ref ByteArray; # byte[] |
| 202 | + JArrayS : type ref IntArray; # short[] |
| 203 | + JArrayJ : type ref BigArray; # long[] |
| 204 | + JArrayF : type ref RealArray; # float[] |
| 205 | + JArrayD : type ref RealArray; # double[] |
| 206 | + JArrayZ : type ref ByteArray; # boolean[] |
| 207 | + |
| 208 | + JArrayJClass : type ref ClassArray; # Class[] |
| 209 | + JArrayJString : type ref StringArray; # String[] |
| 210 | + JArrayJObject : type ref ObjectArray; # Object[] |
| 211 | + |
| 212 | + ThreadObject : adt |
| 213 | + { |
| 214 | + cl_mod : ClassModule; |
| 215 | + name : JArrayC; |
| 216 | + priority : int; |
| 217 | + #threadQ : cyclic ref ThreadObject; |
| 218 | + PrivateInfo : ref JavaClassLoader->ThreadData; |
| 219 | + was_interrupted : byte; #boolean |
| 220 | + #eetop : int; |
| 221 | + #single_step : byte; #boolean |
| 222 | + daemon : byte; #boolean |
| 223 | + stillborn : byte; #boolean |
| 224 | + target : JObject; |
| 225 | + group : JObject; |
| 226 | + #initial_stack_memory : int; |
| 227 | + }; |
| 228 | + JThread : type ref ThreadObject; |
| 229 | + |
| 230 | + |
| 231 | + # |
| 232 | + # This union type is used for setting/getting fields |
| 233 | + # of an arbitrary Java object/class, and also for |
| 234 | + # calling arbitrary object/class methods. |
| 235 | + # To set Java reference types (i.e. objects, arrays) |
| 236 | + # they must be converted to a JObject (i.e. use TObject). |
| 237 | + # |
| 238 | + # One way to create an instance of this type is: |
| 239 | + # val := ref Value.TObject(obj); |
| 240 | + # |
| 241 | + # To retrieve a value use a 'pick' statement or one |
| 242 | + # of the "getter" functions below. |
| 243 | + # |
| 244 | + # NOTE: the Low module is aware of the order of the "pick" tags |
| 245 | + # |
| 246 | + Value :adt |
| 247 | + { |
| 248 | + pick |
| 249 | + { |
| 250 | + TObject => jobj : JObject; |
| 251 | + TByte => jbyte : int; |
| 252 | + TBoolean => jboolean: int; |
| 253 | + TChar => jchar : int; |
| 254 | + TShort => jshort : int; |
| 255 | + TInt => jint : int; |
| 256 | + TLong => jlong : big; |
| 257 | + TFloat => jfloat : real; |
| 258 | + TDouble => jdouble : real; |
| 259 | + } |
| 260 | + |
| 261 | + # |
| 262 | + # Get a value of the expected type. If the |
| 263 | + # actual type is not the expected type then |
| 264 | + # a FatalError() is called. |
| 265 | + # |
| 266 | + Boolean : fn( this : self ref Value ) : JBoolean; |
| 267 | + Byte : fn( this : self ref Value ) : int; |
| 268 | + Short : fn( this : self ref Value ) : int; |
| 269 | + Int : fn( this : self ref Value ) : int; |
| 270 | + Long : fn( this : self ref Value ) : big; |
| 271 | + Float : fn( this : self ref Value ) : real; |
| 272 | + Double : fn( this : self ref Value ) : real; |
| 273 | + Char : fn( this : self ref Value ) : int; |
| 274 | + Object : fn( this : self ref Value ) : JObject; |
| 275 | + |
| 276 | + |
| 277 | + }; |
| 278 | + |
| 279 | + # |
| 280 | + # This structure is used to "describe" a Java type. A Java signature |
| 281 | + # stored as a string is converted into this ADT for better comparisons. |
| 282 | + # Depending on the actual type vairous parts of the ADT will be filled |
| 283 | + # in. The 'sig' field will contain the appropriate java signagure string |
| 284 | + # associated with the type. The following details how to distinguish the |
| 285 | + # type: |
| 286 | + # non-array ref: |
| 287 | + # 'class' represents the class info; other fields are 0/nil |
| 288 | + # array ref: |
| 289 | + # "class" is nil for primitive array and 'prim' contains one of |
| 290 | + # the "Java Type Constants" representing the array's base type. |
| 291 | + # for non-primitive arrays 'class' is the ClassData for the base |
| 292 | + # type; 'prim' is 0; 'dims' contains the number of dimensions |
| 293 | + # primitive: |
| 294 | + # 'class' is nil; 'dims' is 0; 'prim' is one of Java Type Consts |
| 295 | + # method: |
| 296 | + # 'params' is a list of Descriptor's for each param -- nil if the |
| 297 | + # method has no parameters. The method return value is represented |
| 298 | + # by the other fields as described above; a method w/ no return |
| 299 | + # value will have (nil,T_VOID,0,"V",nil) descriptor. NOTE: the param |
| 300 | + # list is in (Right-to-Left order -- i.e right most param is the |
| 301 | + # list-head). |
| 302 | + # |
| 303 | + Descriptor : adt |
| 304 | + { |
| 305 | + class : ClassData; |
| 306 | + prim : int; |
| 307 | + dims : int; |
| 308 | + sig : string; #type's java signature |
| 309 | + params : cyclic list of ref Descriptor; |
| 310 | + }; |
| 311 | + |
| 312 | + |
| 313 | + # |
| 314 | + # argument passed to AttachCurrentThread |
| 315 | + # |
| 316 | + ThreadAttachArgs : adt |
| 317 | + { |
| 318 | + name : string; #can be nil |
| 319 | + daemon : byte; #1=true |
| 320 | + group : JObject; #nil ==> main group |
| 321 | + }; |
| 322 | + |
| 323 | + |
| 324 | + # |
| 325 | + # JNI Functions |
| 326 | + # |
| 327 | + |
| 328 | + # |
| 329 | + # Return JNI version number in the form |
| 330 | + # of 0xVVVVIIII where VVVV=major version |
| 331 | + # and IIII= minor version |
| 332 | + # |
| 333 | + GetVersion : fn() : int; |
| 334 | + |
| 335 | + |
| 336 | + ## |
| 337 | + ## Class/Object access |
| 338 | + ## |
| 339 | + |
| 340 | + # |
| 341 | + # Find the class data for a given class name. |
| 342 | + # Will cause a load of the class if necessary. |
| 343 | + # NOTE: this does not return a java.lang.Class |
| 344 | + # object, but rather the internal structure. |
| 345 | + # |
| 346 | + FindClass : fn( name : string ) : ClassData; |
| 347 | + |
| 348 | + # |
| 349 | + # Return the class's superclass data. |
| 350 | + # |
| 351 | + GetSuperclass : fn( cl_data : ClassData ) : ClassData; |
| 352 | + |
| 353 | + # |
| 354 | + # Return the java.lang.Class instance associated |
| 355 | + # with this instance. |
| 356 | + # |
| 357 | + GetObjectClass : fn( obj : JObject ) : JClass; |
| 358 | + |
| 359 | + # |
| 360 | + # Return the internal Class Data information |
| 361 | + # associated with this instance |
| 362 | + # |
| 363 | + GetObjectClassData : fn( obj : JObject ) : ClassData; |
| 364 | + |
| 365 | + # |
| 366 | + # return the associated java.lang.Class instance |
| 367 | + # associated with the given internal Class |
| 368 | + # Data. |
| 369 | + # |
| 370 | + GetClassObject : fn( cl_data : ClassData ) : JClass; |
| 371 | + |
| 372 | + # |
| 373 | + # return the java.lang.Class instance associated |
| 374 | + # with the array class that has signature 'sig'. |
| 375 | + # |
| 376 | + LookupArrayClass : fn( sig : string ) : JClass; |
| 377 | + |
| 378 | + # |
| 379 | + # Allocate an instance of java.lang.Class that |
| 380 | + # represents the class indicated by 'cl_data'. |
| 381 | + # The 'cl_data' can be obtained via the functions above. |
| 382 | + # |
| 383 | + NewClassObject : fn( cl_data : ClassData ) : JClass; |
| 384 | + |
| 385 | + # |
| 386 | + # Allocate a new instance of the class; no constructor called. |
| 387 | + # |
| 388 | + AllocObject : fn( cl_data : ClassData ) : JObject; |
| 389 | + |
| 390 | + # |
| 391 | + # Allocate a new instance of the class and |
| 392 | + # attempt to call the "default" constructor. |
| 393 | + # NOTE: this routine should be used with care, |
| 394 | + # because not all classes have default constructors. |
| 395 | + # |
| 396 | + NewObject : fn( cl_data : ClassData ) : JObject; |
| 397 | + |
| 398 | + # |
| 399 | + # Duplicate the object. This function will create |
| 400 | + # a new instance of the object's class and perform |
| 401 | + # a shallow copy of the the objects data contents |
| 402 | + # into the new instance. |
| 403 | + # NOTE: the constructor of the new object is not invoked |
| 404 | + # |
| 405 | + DupObject : fn( obj : JObject ) : JObject; |
| 406 | + |
| 407 | + # |
| 408 | + # Return a hash code based on the object's reference, |
| 409 | + # not its contents. This is called by |
| 410 | + # java.lang.Object.hashCode() as well as |
| 411 | + # System.identityHashCode(). |
| 412 | + # |
| 413 | + IdentityHash : fn( obj : JObject ) : int; |
| 414 | + |
| 415 | + # |
| 416 | + # Allocate a java string object and place the |
| 417 | + # dis string as its contents. |
| 418 | + # |
| 419 | + NewString : fn( val : string ) : JString; |
| 420 | + |
| 421 | + # |
| 422 | + # Just like NewString but return as a |
| 423 | + # JObject type, rather then JString |
| 424 | + # |
| 425 | + NewStringObject : fn( val : string ) : JObject; |
| 426 | + |
| 427 | + # |
| 428 | + # Set object/class data fields. |
| 429 | + # Must pass the "object instance"/"class data" along with the |
| 430 | + # field name and the value it should be set to. The contents of |
| 431 | + # the 'val' union type is used to determine the field type and if |
| 432 | + # they are not compatable the function fails. |
| 433 | + # |
| 434 | + # RETURN: JNI->OK=> success; |
| 435 | + # JNI->ERR=> failure |
| 436 | + # |
| 437 | + SetStaticField : fn( cl_data : ClassData, name : string, val : ref Value ) : int; |
| 438 | + SetObjField : fn( obj : JObject, name : string, val : ref Value ) : int; |
| 439 | + |
| 440 | + # Get object/class data fields. |
| 441 | + # Must pass the "object instance"/"class data" along with the field |
| 442 | + # name and a "type signature" (see JVM reference). The type sig must |
| 443 | + # match the actual field sig exactly. |
| 444 | + # |
| 445 | + # RETURN: nil=> failure; |
| 446 | + # non-nil=> a 'Value' union type with the field contents |
| 447 | + # |
| 448 | + GetStaticField : fn( cl_data : ClassData, name : string, typ : string ) : ref Value; |
| 449 | + GetObjField : fn( obj : JObject, name : string, typ : string ) : ref Value; |
| 450 | + |
| 451 | + |
| 452 | + # |
| 453 | + # Call a method: |
| 454 | + # cl_data/obj : the class or object being called |
| 455 | + # meth : name of method to call |
| 456 | + # sig : signature of method being called |
| 457 | + # args : array of args to pass (nil==void) 'this' is implicitly |
| 458 | + # passed for dynamic (object) method calls |
| 459 | + # return : tuple: value of method call (nil==void), error code |
| 460 | + # |
| 461 | + # example: |
| 462 | + # v := Value.Int(99); |
| 463 | + # args := array[] of {v}; |
| 464 | + # (val,err) := CallMeth( o, "foo", "(I)I", args ); |
| 465 | + # if ( err == JNI->OK ) |
| 466 | + # sys->print( "return: %d\n", val.Int() ); |
| 467 | + # |
| 468 | + CallStatic : fn( cl_data : ClassData, meth : string, sig : string, args : array of ref Value ) : (ref Value,int); |
| 469 | + CallMethod : fn( obj : JObject, meth : string, sig : string, args : array of ref Value ) : (ref Value,int); |
| 470 | + |
| 471 | + |
| 472 | + # |
| 473 | + # Method call error codes |
| 474 | + # |
| 475 | + CALLERR_NOMETHOD, # method not found |
| 476 | + CALLERR_BADSIG, # bad signature |
| 477 | + CALLERR_BADARGCNT, # arg count mismatch |
| 478 | + CALLERR_BADARG # argument mismatch: errcode-CALLERR_BADARG==argument position |
| 479 | + # 'badarg' must be last. |
| 480 | + : con (iota+1); |
| 481 | + |
| 482 | + |
| 483 | + ## |
| 484 | + ## Object/Class comparison functions |
| 485 | + ## |
| 486 | + |
| 487 | + IsInstanceOf : fn( obj : JObject, cl_data : ClassData ) : JBoolean; |
| 488 | + IsAssignable : fn( assignee, assignTo : JClass ) : JBoolean; |
| 489 | + IsSameObject : fn( obj1, obj2 : JObject ) : JBoolean; |
| 490 | + |
| 491 | + # Check if 'ary' can be assigned to an instance with matching 'desc'. |
| 492 | + # If 'ary' or 'desc' are nil then return FALSE. |
| 493 | + ArrayInstanceOf : fn( ary : JArray, desc : ref Descriptor ) : JBoolean; |
| 494 | + |
| 495 | + # Is the object an array? (nil==FALSE) |
| 496 | + IsArray : fn( obj : JObject ) : JBoolean; |
| 497 | + |
| 498 | + ## |
| 499 | + ## Support for Serializable |
| 500 | + ## |
| 501 | + |
| 502 | + # Return the modifiers for the item. |
| 503 | + # Return 0 if field or method not found in class. |
| 504 | + # Do not search for fields/methods in superclass. |
| 505 | + # string args are same format as strings returned |
| 506 | + # by GetFieldSignatures and GetMethodSignatures. |
| 507 | + # |
| 508 | + GetClassFlags : fn(jcl : JClass) : int; |
| 509 | + GetFieldFlags : fn(jcl : JClass, fieldsignature : string) : int; |
| 510 | + GetMethodFlags : fn(jcl : JClass, methodsignature : string) : int; |
| 511 | + |
| 512 | + # Return array of Fields/Methods plus signatures as strings. |
| 513 | + # Should be limited Fields/methods in this class, not superclass. |
| 514 | + # Returned value strings are "fieldormethodname signature". |
| 515 | + # |
| 516 | + GetFieldSignatures : fn(jcl: JClass, excl : int) : JArrayJString; |
| 517 | + GetMethodSignatures : fn(jcl: JClass, excl : int) : JArrayJString; |
| 518 | + |
| 519 | + ## |
| 520 | + ## Throwing Exceptions |
| 521 | + ## |
| 522 | + |
| 523 | + # |
| 524 | + # Throw the pre-created 'throwable' object. The |
| 525 | + # 'throwable' object must be an instance of |
| 526 | + # "java.lang.Throwable", else failure. |
| 527 | + # |
| 528 | + Throw : fn( throwable : JObject ); |
| 529 | + ThrowException : fn( name : string, msg : string ); |
| 530 | + |
| 531 | + # |
| 532 | + # return the current Java Exception. The object |
| 533 | + # returned can be used by "Throw" to re-throw it. |
| 534 | + # |
| 535 | + # ex is the current Inferno exception if in a rescue. |
| 536 | + # if ex is nil then the current value of culprit() is |
| 537 | + # returned (that may be nil). If ex is non nil and |
| 538 | + # culprit() is nil then ex is converted to the appropriate |
| 539 | + # Java throwable and returned. |
| 540 | + # |
| 541 | + JavaException: fn( ex : string ) : JObject; |
| 542 | + |
| 543 | + # |
| 544 | + # Clear any current Exception for the calling thread. |
| 545 | + # |
| 546 | + ExceptionClear : fn(); |
| 547 | + |
| 548 | + ## |
| 549 | + ## Array functions |
| 550 | + ## |
| 551 | + |
| 552 | + GetArrayLength : fn( ary : JArray ) : int; |
| 553 | + |
| 554 | + # |
| 555 | + # functions to make "java" arrays from limbo arrays |
| 556 | + # |
| 557 | + MkAByte : fn( ary : array of byte ) : JArrayB; |
| 558 | + MkAChar : fn( ary : array of int ) : JArrayC; |
| 559 | + MkAShort : fn( ary : array of int ) : JArrayS; |
| 560 | + MkAInt : fn( ary : array of int ) : JArrayI; |
| 561 | + MkALong : fn( ary : array of big ) : JArrayJ; |
| 562 | + MkAFloat : fn( ary : array of real ) : JArrayF; |
| 563 | + MkADouble : fn( ary : array of real ) : JArrayD; |
| 564 | + MkABoolean : fn( ary : array of byte ) : JArrayZ; |
| 565 | + MkAObject : fn( ary : array of JObject ) : JArrayJObject; |
| 566 | + MkAString : fn( ary : array of string ) : JArrayJString; |
| 567 | + |
| 568 | + MkAAByte : fn( aary : array of array of byte ) : JArray; |
| 569 | + MkAAInt : fn( aary : array of array of int ) : JArray; |
| 570 | + |
| 571 | + # This can be used to create arrays of arbitrary dimensions. |
| 572 | + MkAJArray : fn( ary : array of JArray ) : JArray; |
| 573 | + |
| 574 | + # make a JArrayC from a Dis string |
| 575 | + StringToAChar : fn( s : string ) : JArrayC; |
| 576 | + |
| 577 | + ## |
| 578 | + ## Monitor, locking, and Thread functions |
| 579 | + ## |
| 580 | + |
| 581 | + # |
| 582 | + # Lock or unlock the object's associated |
| 583 | + # lock. Block until the operation is complete. |
| 584 | + # Upon an error: FatalError() is called |
| 585 | + # |
| 586 | + MonitorEnter : fn( obj : JObject ); |
| 587 | + MonitorExit : fn( obj :JObject ); |
| 588 | + |
| 589 | + # |
| 590 | + # Notify any waiters. |
| 591 | + # all==1 => notify all |
| 592 | + # *Lock* version will do a enter/exit. |
| 593 | + # |
| 594 | + MonitorLockNotify : fn( obj : JObject, all : int ); |
| 595 | + MonitorNotify : fn( obj : JObject, all : int ); |
| 596 | + |
| 597 | + # |
| 598 | + # Attach a "Limbo thread" to the "Java vm". |
| 599 | + # This allows a Limbo "spawned" thread to |
| 600 | + # look like a "Java thread" to the Java Classes. |
| 601 | + # |
| 602 | + # return 0=>success; <0=>fail |
| 603 | + # |
| 604 | + AttachCurrentThread : fn( arg : ref ThreadAttachArgs ) : int; |
| 605 | + |
| 606 | + # |
| 607 | + # Detach a thread from the "java VM". |
| 608 | + # |
| 609 | + DetachCurrentThread : fn() : int; |
| 610 | + |
| 611 | + # |
| 612 | + # returns the Main thread group. |
| 613 | + # |
| 614 | + MainThreadGroup : fn() : JObject; |
| 615 | + |
| 616 | + ## |
| 617 | + ## Utility Functions |
| 618 | + ## |
| 619 | + |
| 620 | + # flags indicating which methods to find |
| 621 | + METH_PRIVATE, # private methods |
| 622 | + METH_VIRTUAL, # virtual methods |
| 623 | + METH_STATIC, # static methods |
| 624 | + METH_INIT # constructors |
| 625 | + : con ( 1 << iota ); |
| 626 | + |
| 627 | + # |
| 628 | + # look up a method based on its name and signature. |
| 629 | + # |
| 630 | + # class : class descritpor to look in |
| 631 | + # name : method name to look up |
| 632 | + # sig : method signature |
| 633 | + # flags : specifies what type of method to find and |
| 634 | + # can be any of the above flags or'ed togeather. |
| 635 | + # |
| 636 | + # return: the (module,index) of the method |
| 637 | + # |
| 638 | + FindMethod : fn( class : ClassData, |
| 639 | + name : string, |
| 640 | + sig : string, |
| 641 | + flags : int ) : (Nilmod,int); |
| 642 | + |
| 643 | + # |
| 644 | + # If c represents a Java primitive type, return |
| 645 | + # T_BOOLEAN..T_LONG or T_VOID; otherwise, return 0. |
| 646 | + # Also return 0 if T_VOID applies, but ignorevoid != 0. |
| 647 | + # |
| 648 | + PrimitiveIndex: fn(c : JClass, ignorevoid : int) : int; |
| 649 | + |
| 650 | + # |
| 651 | + # Convert a Java type signature string into |
| 652 | + # a type descriptor structure. The signature |
| 653 | + # passed in can represent any single type (including |
| 654 | + # a method). Extra characters on the end are ignored. |
| 655 | + # |
| 656 | + JSigToDescriptor : fn( sig : string ) : ref Descriptor; |
| 657 | + |
| 658 | + # |
| 659 | + # Throw a java.lang.InternalError |
| 660 | + # |
| 661 | + FatalError : fn( msg : string ); |
| 662 | + |
| 663 | + # |
| 664 | + # Indicate to loader a native module init() |
| 665 | + # function has failed. |
| 666 | + # |
| 667 | + InitError : fn( msg : string ); |
| 668 | + |
| 669 | + # |
| 670 | + # Return an instance of the Cast module. |
| 671 | + # |
| 672 | + CastMod : fn() : Cast; |
| 673 | + |
| 674 | + # |
| 675 | + # Return an instance of the Low module. |
| 676 | + # |
| 677 | + LowMod : fn() : Low; |
| 678 | + |
| 679 | + # return the current draw context |
| 680 | + getContext:fn(): ref Draw->Context; |
| 681 | + |
| 682 | + # |
| 683 | + # The following routines are called by the JavaClassLoader |
| 684 | + # module to initialize JNI. Native method modules must not |
| 685 | + # call thease routines. |
| 686 | + # |
| 687 | + jinit : fn( jldr : JavaClassLoader, jass : JavaAssist ); |
| 688 | + Self: fn(s: Sys, j: JNI): (Nilmod, string); |
| 689 | + init: fn(j: JNI); |
| 690 | +}; |