Commits

camlspotter committed d850e3b

dependency + call/callObject type improvement

Comments (0)

Files changed (5)

 auto.ml auto.mli auto_stubs.c: $(addsuffix .idl, $(IDLS)) $(Installed camlidl) autoclasses.idl autoclasses.h
 	camlidl auto.idl
 
-autoapi.ml : auto.ml module.pl
+autoapi.ml : auto.ml module.pl $(addsuffix .idl.in, $(IDLS))
     ./module.pl *.idl.in > $@
 
 auto_stubs.o: auto_stubs.c auto.h api_ml.h autoclasses.h
 module Callable = Callable
 module Sequence = Sequence
 module Eval = Eval
-module Object = Object
 module Run = Run
 
 module Base : sig
 
 end
 
+module Object = struct
+  include Object
+
+  let call callable ?kwd list =
+    _internal_call callable (Tuple.from_list list) kwd
+
+  let callObject callable = function
+    | [] -> _internal_callObject callable None
+    | list -> _internal_callObject callable (Some (Tuple.from_list list))
+end
+
 module Err : sig
   include module type of Err
 
 open Opycaml.Api
 
-let _ = 
-  prerr_endline "start";
-  Base.initialize ()
+let _ =
+  Base.initialize ();
+
+  let string = Import.importModule "string" in (* from string import * *)
+  let dict = Module.getDict string in
+  let lowercase = Dict.getItemString dict "lowercase" in
+  let capitalize = Dict.getItemString dict "capitalize" in
+
+  let res = Object.callObject (Callable.coerce capitalize) [lowercase] in
+
+  prerr_endline (String.asString (String.coerce res));
+
+  Base.finalize ()
 ;;
-
-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 ()
 // Determine if the object o is callable. Return 1 if the object is callable and 0 otherwise. This function always succeeds.
 
 // Need to think about NULL
-[new] PyObject* PyObject_Call(PyCallableObject *callable_object, PyTupleObject *args, [option] PyDictObject *kw);
+[new] PyObject* [internal] PyObject_Call(PyCallableObject *callable_object, PyTupleObject *args, [option] PyDictObject *kw);
 // Return value: New reference.
 // Call a callable Python object callable_object, with arguments given by the tuple args, and named arguments given by the dictionary kw. If no named arguments are needed, kw may be NULL. args must not be NULL, use an empty tuple if no arguments are needed. Returns the result of the call on success, or NULL on failure. This is the equivalent of the Python expression apply(callable_object, args, kw) or callable_object(*args, **kw).
 
-[new] PyObject* PyObject_CallObject(PyCallableObject *callable_object, [option] PyTupleObject *args);
+[new] PyObject* [internal] PyObject_CallObject(PyCallableObject *callable_object, [option] PyTupleObject *args);
 // Return value: New reference.
 // Call a callable Python object callable_object, with arguments given by the tuple args. If no arguments are needed, then args may be NULL. Returns the result of the call on success, or NULL on failure. This is the equivalent of the Python expression apply(callable_object, args) or callable_object(*args).
 
-[new] PyObject* PyEval_CallObject(PyCallableObject *callable_object, [option] PyTupleObject *args);
+[new] PyObject* [internal] PyEval_CallObject(PyCallableObject *callable_object, [option] PyTupleObject *args);
 // Return value: New reference.
 // Call a callable Python object callable_object, with arguments given by the tuple args. If no arguments are needed, then args may be NULL. Returns the result of the call on success, or NULL on failure. This is the equivalent of the Python expression apply(callable_object, args) or callable_object(*args).
 // Same as PyObject_CallObject but with sanity checks
     Base.debug "o" o;
 
     prerr_endline "calling function";
-    let res = Object.callObject (Callable.coerce capitalize) (Some tpl) in
+    let res = Object.callObject (Callable.coerce capitalize) [o] in
     Printf.eprintf "res : refcnt = %d\n%!" (Base.refcnt res);
     prerr_endline "function called!";
     prerr_endline (String.asString (String.coerce res));