Commits

camlspotter committed d02765e Draft

branch android: explicit vm creation

Comments (0)

Files changed (3)

camljava-0.3/lib/jni.mli

 
 type obj
         (* The type of Java object references *)
-val null: obj
-        (* The [null] object reference *)
+
 exception Null_pointer
         (* Exception raised by the operations below when they
            encounter a null object reference in arguments that must
 external set_double_array_element: obj -> int -> float -> unit
         = "camljava_SetDoubleArrayElement"
 
-(* Auxiliaries for Java->OCaml callbacks *)
 
-val wrap_object: < .. > -> obj
+(** Build a VM and initialize *)
+module Make(A : sig end) : sig
 
+  val null: obj
+    (** The [null] object reference *)
+
+  (* Auxiliaries for Java->OCaml callbacks *)
+
+  val wrap_object: < .. > -> obj
+
+end

camljava-0.3/lib/jni.mlp

 external init: string -> unit = "camljava_Init"
 external shutdown: unit -> unit = "camljava_Shutdown"
 
-let _ =
-  let libpath = "%PATH%" in  
-  let sep =
-    match Sys.os_type with
-      "Unix" -> ":"
-    | "Win32" -> ";"
-    | _ -> assert false in
-  let path =
-    try
-      Sys.getenv "CLASSPATH" ^ sep ^ libpath
-    with Not_found ->
-      libpath in
-  init path;
-  at_exit shutdown
-
 type obj
 
 external get_null: unit -> obj = "camljava_GetNull"
 
-let null = get_null()
-
 exception Null_pointer
 
-let _ = Callback.register_exception "camljava_null_pointer" Null_pointer
-
 exception Exception of obj
 
-let _ = Callback.register "camljava_raise_exception"
-          (fun obj -> raise (Exception obj))
-
 external register_natives: unit -> unit = "camljava_RegisterNatives"
 
-let _ = register_natives()
-
-let _ = Callback.register "Oo.new_method" Oo.new_method
-
 (* String operations *)
 
 external string_to_java: string -> obj = "camljava_MakeJavaString"
 
 external register_null_string: string -> unit = "camljava_RegisterNullString"
 
-let _ = register_null_string null_string
-
 (* Class operations *)
 
 type clazz
 
 external wrap_caml_object : < .. > -> int64 = "camljava_WrapCamlObject"
 
-let callback_class =
-  find_class "fr/inria/caml/camljava/Callback"
-let callback_init =
-  get_methodID callback_class "<init>" "(J)V"
-let wrap_object camlobj =
-  let javaobj = alloc_object callback_class in
-  call_nonvirtual_void_method javaobj callback_class callback_init
-                              [|Long (wrap_caml_object camlobj)|];
-  javaobj
+module Make(A:sig end) = struct
+
+  let _ =
+    let libpath = "%PATH%" in  
+    let sep =
+      match Sys.os_type with
+        "Unix" -> ":"
+      | "Win32" -> ";"
+      | _ -> assert false in
+    let path =
+      try
+        Sys.getenv "CLASSPATH" ^ sep ^ libpath
+      with Not_found ->
+        libpath in
+    init path;
+    at_exit shutdown
+  
+  let null = get_null()
+  
+  let _ = Callback.register_exception "camljava_null_pointer" Null_pointer
+  
+  let _ = Callback.register "camljava_raise_exception"
+            (fun obj -> raise (Exception obj))
+  
+  let _ = register_natives()
+  
+  let _ = Callback.register "Oo.new_method" Oo.new_method
+  
+  let _ = register_null_string null_string
+  
+  let callback_class =
+    find_class "fr/inria/caml/camljava/Callback"
+  let callback_init =
+    get_methodID callback_class "<init>" "(J)V"
+
+  let wrap_object camlobj =
+    let javaobj = alloc_object callback_class in
+    call_nonvirtual_void_method javaobj callback_class callback_init
+                                [|Long (wrap_caml_object camlobj)|];
+    javaobj
+
+end

camljava-0.3/test/jnitest.ml

 open Jni
+module VM = Jni.Make(struct end)
+open VM
 
 class cls = object
   method f = print_string "cls.f called"; print_newline()