Commits

camlspotter  committed 8f96f44

added install, META and example

  • Participants
  • Parent commits e15d9ba

Comments (0)

Files changed (5)

+name = "OPyCaml"
+version = "1.0.0"
+description = "( ゚∀゚)o彡°O'PyCaml"
+
+requires = ""
+
+archive(byte) = "opycaml.cma"
+archive(native) = "opycaml.cmxa"
 .DEFAULT: $(OCamlProgram test, test)
 .DEFAULT: $(OCamlProgram test_bug1, test_bug1)
 
-# 
-# PROGRAM=test
-# FILOCAML_LIBS+=opycaml.cma
-# 
-# MLMODULES= test 
-# CMOS=$(addsuffix .cmo, $(MLMODULES)) 
-# CMXS=$(addsuffix .cmx, $(MLMODULES)) 
-# CMXOS=$(addsuffix .o, $(MLMODULES)) 
-# 
-# test.byt: $(CMOS) opycaml.cma libopycaml.a dllopycaml.so
-#     $(OCamlC) -verbose -o $@ opycaml.cma $(CMOS)
-# 
-# test.exe: $(CMXS) $(CMXOS) opycaml.cmxa libopycaml.a dllopycaml.so
-#     $(OCamlOpt) -verbose -o $@ opycaml.cmxa $(CMXS)
-# 
-# .DEFAULT: test.exe
+.PHONY: install
+install: opycaml.cma opycaml.cmxa
+	$(OCAMLFIND) install opycaml opycaml.cmi opycaml.cma opycaml.cmxa opycaml.a dllopycaml.so libopycaml.a autoapi.ml api.ml META

File example/OMakefile

+USE_OCAMLFIND=true
+
+OCAMLPACKS = opycaml
+
+.DEFAULT: $(OCamlProgram test, test)
+
+.PHONY: clean
+clean:
+  rm -f $(filter-proper-targets $(ls R, .))

File example/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: .

File example/test.ml

+open Opycaml.Api
+
+let _ = 
+  prerr_endline "start";
+  Base.initialize ()
+;;
+
+let _ =
+  try
+    ignore (Import.importModule "hogehoge")
+  with
+  | Error (e, detail) ->
+      Printf.eprintf "Error: %s %s\n%!" (String.asString (Object.repr e)) (String.asString (Object.repr detail))
+;;
+
+let _ =
+  let o = String.fromString "hello world" in
+  Base.debug "o" o;
+
+  assert (Base.phys_eq o o);
+  let repr = Object.repr o in
+  Base.debug "repr" repr;
+  let hash = Object.hash o in
+  Printf.eprintf "hash=%nd\n%!" hash;
+
+  try
+    let stringModule = Import.importModule "string" in (* from string import * *)
+    Base.debug "stringModule" stringModule;
+    let dict = Module.getDict stringModule in
+    (* Base.debug "dict" dict; *)
+    let lowercase = Dict.getItemString dict "lowercase" in
+    Base.debug "lowercase" lowercase;
+
+    let capitalize = Dict.getItemString dict "capitalize" in
+    Base.debug "capitalize" capitalize;
+
+    if not (Callable.check capitalize) then begin
+      prerr_endline "capitalize is not a function!";
+      failwith "capitalize is not a function!";
+    end;
+
+    let tpl = Tuple.new_ 1 in
+    Base.debug "tpl" tpl;
+
+    Base.debug "o" o;
+
+    prerr_endline "tuple setting";
+    
+    Tuple.setItem tpl 0 o;
+
+    prerr_endline "tuple set";
+    Base.debug "tuple" tpl;
+    Base.debug "o" o; (* ref by tuple and o *)
+
+    prerr_endline "getItem";
+    let x = Tuple.getItem tpl 0 in
+    Base.debug "x" x; (* ref by tuple, o and x *) 
+    Base.debug "o" o; (* ref by tuple, o and x *) 
+
+    let xx = Tuple._GET_ITEM tpl 0 in
+    Base.debug "xx" xx; (* ref by tuple, o, x and xx *)
+    Base.debug "o" o;
+
+    prerr_endline "calling function";
+    let res = Object.callObject capitalize (Some tpl) in
+    Printf.eprintf "res : refcnt = %d\n%!" (Base.refcnt res);
+    prerr_endline "function called!";
+    prerr_endline (String.asString res);
+    prerr_endline (String.asString o);
+
+    let minus_1 = Int.fromLong (-1) in
+    assert (Int.asLong minus_1 = -1); 
+
+    Run.simpleString "print 'Run.simpleString'";
+    (* Run.simpleString "print(string.lowercase)"; *) (* does not work *)
+    (* Run.simpleString "print(lowercase)"; *) (* does not work *)
+
+    ignore (Base.main []);
+    prerr_endline "exited from toploop";
+
+  with
+  | Error (e, detail) -> 
+      Printf.eprintf "Error: %s %s\n%!" (String.asString (Object.repr e)) (String.asString (Object.repr detail))
+;;
+
+let _ = Base.finalize ()