Commits

camlspotter committed ca4544e

hmmm. we need something more than js_of_ocaml

Comments (0)

Files changed (7)

js_of_ocaml/py_of_ocaml.ml

   type 'a readonly_prop = < get : 'a> gen_prop
   type 'a meth
 end
+
+include Js

js_of_ocaml/test.ml

-(* open Opycaml.Api is recommended. *)
-open Opycaml.Api
-open Py_of_ocaml
+open Py_of_ocaml (* It must go first *)
+open Opycaml.Api (* open Opycaml.Api is recommended. *)
 
 class type module_string = object
-  method lowercase  : _String t Js.readonly_prop
-  method capitalize : [>_String] t -> _String t Js.meth
+  method lowercase  : _String t readonly_prop
+  method capitalize : [>_String] t -> _String t meth
 end
 
-let import_module_dict name = Js.dict (Module.getDict (Import.importModule name))
+let import_module_dict name = dict (Module.getDict (Import.importModule name))
 
 let _ =
   let module_string : module_string Js.t = import_module_dict "string" in (* from string import * *)

js_of_ocaml/testoox.ml

 open Opycaml.OOApi
 open Opy_of_ocaml
   
-class type module_string =
-  object
-    method lowercase : o_String Js.readonly_prop
-    method capitalize : #o_String -> o_String Js.meth
-  end
-  
+class type module_string = object
+  method lowercase : o_String Js.readonly_prop
+  method capitalize : #o_String -> o_String Js.meth
+end
+
+let module_string_wrap = object
+  method lowercase = OPy.String.coerce
+  method capitalize = OPy.String.coerce
+end
+
 let _ =
   let module_string : module_string Js.t = import_module "string" in
   (* from string import * *)
       (arg1#lowercase : < get : 'x2; .. > Js.gen_prop)
     in 
     (* (Js.Unsafe.get module_string_1 "lowercase" : 'x2)  *)
-    (Obj.magic module_string_1 : o_Dict)#getItemString "lowercase"
+    module_string_wrap#lowercase
+    ((Obj.magic module_string_1 : o_Dict)#getItemString "lowercase")
   in
 
-  prerr_endline "lowercase";
-
   let res =
     let module_string_2 : (< .. > as 'x3) Js.t = module_string in
     let _ (arg2 : 'x3) =
       (arg2#capitalize : 'x4 -> 'x5 Js.meth)
     in
-    OPy.String.coerce 
+    module_string_wrap#capitalize
       (Js.Unsafe.meth_call module_string_2 "capitalize" [| Js.Unsafe.inject ((Obj.magic lowercase) : 'x4) |] : 'x5)
   in prerr_endline res#asString
   

js_of_ocaml2/OMakefile

+USE_OCAMLFIND=true
+
+OCAMLPACKS = opycaml
+
+OCAMLDEPFLAGS += -syntax camlp4o -package js_of_ocaml.syntax
+OCAMLPPFLAGS += -syntax camlp4o -package js_of_ocaml.syntax
+OCAMLFLAGS += -annot
+
+.DEFAULT: $(OCamlProgram testoox, opy_of_ocaml testoox)
+
+.PHONY: clean
+clean:
+  rm -f $(filter-proper-targets $(ls R, .))

js_of_ocaml2/OMakeroot

+########################################################################
+# Permission is hereby granted, free of charge, to any person
+# obtaining a copy of this file, to deal in the File without
+# restriction, including without limitation the rights to use,
+# copy, modify, merge, publish, distribute, sublicense, and/or
+# sell copies of the File, and to permit persons to whom the
+# File is furnished to do so, subject to the following condition:
+#
+# THE FILE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE FILE OR
+# THE USE OR OTHER DEALINGS IN THE FILE.
+
+########################################################################
+# The standard OMakeroot file.
+# You will not normally need to modify this file.
+# By default, your changes should be placed in the
+# OMakefile in this directory.
+#
+# If you decide to modify this file, note that it uses exactly
+# the same syntax as the OMakefile.
+#
+
+#
+# Include the standard installed configuration files.
+# Any of these can be deleted if you are not using them,
+# but you probably want to keep the Common file.
+#
+open build/C
+open build/OCaml
+open build/LaTeX
+
+#
+# The command-line variables are defined *after* the
+# standard configuration has been loaded.
+#
+DefineCommandVars()
+
+#
+# Include the OMakefile in this directory.
+#
+.SUBDIRS: .

js_of_ocaml2/opy_of_ocaml.ml

+open Opycaml.OOApi
+open OPy
+
+module Js : sig
+  type 'a t
+  type 'a gen_prop
+  type 'a readonly_prop = < get : 'a> gen_prop
+  type 'a meth
+  val dict : #o_Dict -> 'a t
+  module Unsafe : sig
+    val get : 'a t -> string -> 'b
+    val meth_call : 'a t -> string -> #o_Object array -> 'b
+    val inject : #o_Object -> o_Object
+  end
+end = struct
+  type 'a t = o_Dict
+  type 'a gen_prop
+  let dict o = (o :> o_Dict)
+  module Unsafe = struct
+    let get (o : 'a t) name = Obj.magic (o#getItemString name)
+    let meth_call (o : o_Dict) name args = 
+      Obj.magic (Object.call (Callable.coerce (o#getItemString name)) (Array.to_list args ))
+    let inject o = (o :> o_Object)
+  end
+
+  type 'a readonly_prop = < get : 'a> gen_prop
+  type 'a meth
+end
+
+include Js
+
+let import_module name = Js.dict (Import.importModule name)#getDict

js_of_ocaml2/testoox.ml

+open Opycaml.OOApi
+open Opy_of_ocaml
+
+class type module_string = object
+  method lowercase : o_String readonly_prop
+  method capitalize : #o_String -> o_String meth
+end
+
+(* Somehow the following object must be created from the above *) 
+let module_string_wrap = object
+  method lowercase = OPy.String.coerce
+  method capitalize = OPy.String.coerce
+end
+
+let _ =
+  let module_string : module_string t * _ = import_module "string", module_string_wrap in
+  (* from string import * *)
+  let lowercase =
+    let ((module_string_1 : (< .. > as 'x1) Js.t), wrapper) = module_string in
+    let _ (arg1 : 'x1) =
+      (arg1#lowercase : < get : 'x2; .. > Js.gen_prop)
+    in 
+    (* (Js.Unsafe.get module_string_1 "lowercase" : 'x2)  *)
+    wrapper#lowercase
+    ((Obj.magic module_string_1 : o_Dict)#getItemString "lowercase")
+  in
+
+  let res =
+    let (module_string_2 : (< .. > as 'x3) Js.t), wrapper = module_string in
+    let _ (arg2 : 'x3) =
+      (arg2#capitalize : 'x4 -> 'x5 Js.meth)
+    in
+    wrapper#capitalize
+      (Js.Unsafe.meth_call module_string_2 "capitalize" [| Js.Unsafe.inject ((Obj.magic lowercase) : 'x4) |] : 'x5)
+  in prerr_endline res#asString
+