1. camlspotter
  2. opycaml

Commits

camlspotter  committed a8f2b4f

added an example from Nicolas

  • Participants
  • Parent commits 914e82a
  • Branches dev

Comments (0)

Files changed (8)

File OMakefile

View file
 .DEFAULT: $(OCamlProgram test_bug1, test_bug1)
 
 .PHONY: install
-install: opycaml.cma opycaml.cmxa libopycaml_python.so
-	$(OCAMLFIND) install opycaml opycaml.cmi opycaml.cma opycaml.cmxa opycaml.a dllopycaml.so libopycaml.a autoapi.ml api.ml META libopycaml_python.so
+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 auto.idl.in

View file
 typedef int Py_ssize_t; // not sure
 typedef int size_t; // not sure
 
+typedef [abstract] void FILE;
+
 #include "err.idl"
 #include "object.idl"
 #include "base.idl"

File example/OMakefile

View file
 OCAMLPACKS = opycaml
 
 .DEFAULT: $(OCamlProgram test, test)
+.DEFAULT: $(OCamlProgram module_new, module_new)
 
 .PHONY: clean
 clean:

File example/module_new.ml

View file
+open Opycaml.Api
+
+let _ =
+  Base.initialize ();
+  let mdl = Module.new_ "MyModule" in
+  let mdldic = Import.getModuleDict () in
+  Dict.setItemString mdldic "MyModule" mdl;
+  let dic = Module.getDict mdl in
+  Dict.setItemString dic "answer" (Int.fromLong 42);
+  ignore (Base.main []);
+  Base.finalize ()
+;;
+
+
+  

File high.idl.in

View file
 // int PyRun_InteractiveOneFlags(FILE *fp, const char *filename, PyCompilerFlags *flags);
 // Read and execute a single statement from a file associated with an interactive device according to the flags argument. If filename is NULL, "???" is used instead. The user will be prompted using sys.ps1 and sys.ps2. Returns 0 when the input was executed successfully, -1 if there was an exception, or an error code from the errcode.h include file distributed as part of Python if there was a parse error. (Note that errcode.h is not included by Python.h, so must be included specifically if needed.)
 
-// int PyRun_InteractiveLoop(FILE *fp, const char *filename);
+int PyRun_InteractiveLoop([in] FILE *fp, [string] const char *filename);
 // This is a simplified interface to PyRun_InteractiveLoopFlags() below, leaving flags set to NULL.
+//
+// ( ゚∀゚)o彡°O'PyCaml: FILE is not implemented. Always use [Run.interactiveLoop None "-"] in order to read from STDIN for the moment.
 
 // int PyRun_InteractiveLoopFlags(FILE *fp, const char *filename, PyCompilerFlags *flags);
 // Read and execute statements from a file associated with an interactive device until EOF is reached. If filename is NULL, "???" is used instead. The user will be prompted using sys.ps1 and sys.ps2. Returns 0 at EOF.

File memo/nicolas.txt

View file
+let mpython () = 
+let mx = pymodule_new "Mymms" in 
+
+let sd = pyimport_getmoduledict () in 
+let _ = pydict_setitemstring (sd, "Mymms", mx) in 
+
+let _ = pydict_setitemstring (pymodule_getdict mx, "pytypecheck", pytypecheck) in 
+let _ = pydict_setitemstring (pymodule_getdict mx, "mymms2python", mymms2python) in 
+let _ = pydict_setitemstring (pymodule_getdict mx, "simpl", simpl) in 
+let _ = pydict_setitemstring (pymodule_getdict mx, "interp", interp) in 
+let _ = pydict_setitemstring (pymodule_getdict mx, "simpl2", simpl2) in 
+let _ = pydict_setitemstring (pymodule_getdict mx, "interp2", interp2) in 
+let _ = pydict_setitemstring (pymodule_getdict mx, "mymmsrequire", mymmsrequire) in 
+let _ = pydict_setitemstring (pymodule_getdict mx, "mymmsload", mymmsload) in 
+let _ = pydict_setitemstring (pymodule_getdict mx, "addinload", addinload) in 
+let _ = pydict_setitemstring (pymodule_getdict mx, "getnormaloutput", getnormaloutput) in 
+let _ = pydict_setitemstring (pymodule_getdict mx, "getdebugoutput", getdebugoutput) in 
+let _ = pydict_setitemstring (pymodule_getdict mx, "geterroroutput", geterroroutput) in 
+let _ = pydict_setitemstring (pymodule_getdict mx, "mymmscommand", mymmscommand) in 
+
+try 
+
+let filename = Sys.argv.(2) in 
+let argv = Array.init ((Array.length Sys.argv) - 2) (fun i -> Sys.argv.(i+2)) in 
+set_python_argv argv; 
+let filechannel = open_in filename in 
+let fl = read_file filechannel in 
+let _ =pyrun_simplestring fl in 
+() 
+
+with 
+| Sys_error _ -> print_error "file does not exists\n"; exit 0; 
+| Invalid_argument _ -> ( 
+let _ = pyrun_interactiveloop (0,"-") in 
+exit 0; 
+) 
+| e -> raise e 
+
+;; 

File module.pl

View file
             $rem =~ s/py([A-z]+)_p_noincr/py$1/g;
             $rem =~ s/py([A-z]+)_p_incr/py$1/g;
             $rem =~ s/py([A-z]+)_p/py$1/g;
-    
+	    # FILE
+	    $rem =~ s/fILE/_FILE/g;
+
 	    # introduce polymorphism (pretty dirty)
 	    # pyAbcd ... -> ==> [>_Abcd] t ... ->
 	    while( $rem =~ s/py([A-Z][A-z]+)(.*->)/[>_$1] t$2/g ){

File type.ml

View file
 type hash_or_fail = nativeint
 type py_ssize_t = int
 type size_t = int
+type _FILE (* not implemented yet *)
 
 exception Error of _Object t (* type *) * _Object t (* detail value *)