Commits

camlspotter committed 2da6424

testing!

Comments (0)

Files changed (11)

   module Iter = Iter
 
   module Sequence = Sequence
-  module Eval = Eval
   module Run = Run
   
   module Tuple = struct
     let errExceptionMatches = Err.exceptionMatches
   
   end
-  
+
+  module Eval = struct
+    include Eval
+
+    module X : sig
+      val callObject : [> _Callable ] t -> [> _Object ] t list -> _Object t
+	(** Function call *)
+    end = struct
+      let callObject callable = function
+	| [] -> _internal_callObject callable None
+	| list -> _internal_callObject callable (Some (Tuple.from_list list))
+    end
+
+    include X
+  end
+
   module Callable = struct
     include Callable
 
     let _internal_callObject = Object._internal_callObject
     let call = Object.call
     let callObject = Object.callObject
+    let evalCallObject = Eval.callObject
   end
 
   module Err = struct
     if( Is_block(v) ){
         return PyObject_val(Field(v, 0));
     } else {
-        printf("PyObject_opt_avl: NULL\n");
+        printf("PyObject_opt_val: NULL\n");
         return NULL;
     }
 }

js_of_ocaml/matplotlib/OMakefile

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

js_of_ocaml/matplotlib/OMakefile.omc

Binary file added.

js_of_ocaml/matplotlib/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 finance_demo, ../opy_of_ocaml finance_demo)
+
+.PHONY: clean
+clean:
+  rm -f $(filter-proper-targets $(ls R, .))

js_of_ocaml/matplotlib/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_ocaml/matplotlib/OMakeroot.omc

Binary file added.

js_of_ocaml/matplotlib/finance_demo.ml

+open Opycaml.OOApi
+open Opy_of_ocaml
+
+class o_Date t = object
+  inherit OPy.o_Object t
+end
+
+class o_Weekday t = object
+  inherit OPy.o_Object t
+end
+
+class o_Ticks t = object
+  inherit OPy.o_Object t
+end
+
+class o_Formatter t = object
+  inherit OPy.o_Object t
+end
+
+class o_Quotes t = object
+  inherit OPy.o_Object t
+end
+
+class type dates = object
+  method _WeekDayLocator : o_Weekday -> o_Ticks Js.meth
+  method _DayLocator : o_Ticks Js.meth
+  method _MONDAY : o_Weekday Js.readonly_prop
+  method _DateFormatter : o_String -> o_Formatter Js.meth
+end
+
+class type datetime = object
+  method date : o_Int -> o_Int -> o_Int -> o_Date Js.meth
+end
+
+class type finance = object
+  method quote_historical_yahoo : o_String -> o_Date -> o_Date -> o_Quotes Js.meth
+end
+ 
+let _ =
+  (* from pylab import * *)
+  let pylab = import_module "pylab" in
+
+  (* from matplotlib.dates import  DateFormatter, WeekdayLocator, HourLocator, \
+     DayLocator, MONDAY, timezone *)
+  let dates : dates Js.t = import_module "matplotlib.dates" in
+
+  (* from matplotlib.finance import quotes_historical_yahoo, candlestick,\
+     plot_day_summary, candlestick2 *)
+  let finance = import_module "matplotlib.finance" in
+
+  (* import datetime *)
+  let datetime : datetime Js.t = import_module "datetime" in
+
+  (* date1 = datetime.date( 2004, 2, 1) *)
+  let date1 = datetime##date( Int.fromLong 2004, Int.fromLong 2, Int.fromLong 1 ) in
+  date1#debug "date1";
+
+  let date2 = datetime##date( Int.fromLong 2004, Int.fromLong 4, Int.fromLong 12 ) in
+  date2#debug "date2";
+
+  let monday = dates##_MONDAY in
+  monday#debug "monday";
+
+  let mondays = dates##_WeekDayLocator( dates##_MONDAY ) in
+  mondays#debug "mondays";
+
+  let alldays = dates##_DayLocator() in
+  alldays#debug "alldays";
+
+  let weekFormatter = dates##_DateFormatter( OPy.String.fromString "%b %d" ) in  (* Eg, Jan 12 *)
+  weekFormatter#debug "weekFormatter";
+
+  let dayFormatter = dates##_DateFormatter( OPy.String.fromString "%d" ) in     (* # Eg, 12 *)
+  dayFormatter#debug "dayFormatter";
+
+  (* quotes = quotes_historical_yahoo('INTC', date1, date2) *)
+  let quotes = finance##quotes_historical_yahoo( OPy.String.fromString "INTC",
+                                                 date1,
+                                                 date2 ) 
+  in
+  quotes#debug "quotes";
+
+  ()
+
+(*
+
+quotes = quotes_historical_yahoo(
+    'INTC', date1, date2)
+if not quotes:
+    raise SystemExit
+
+fig = figure()
+fig.subplots_adjust(bottom=0.2)
+ax = fig.add_subplot(111)
+ax.xaxis.set_major_locator(mondays)
+ax.xaxis.set_minor_locator(alldays)
+ax.xaxis.set_major_formatter(weekFormatter)
+#ax.xaxis.set_minor_formatter(dayFormatter)
+
+#plot_day_summary(ax, quotes, ticksize=3)
+candlestick(ax, quotes, width=0.6)
+
+ax.xaxis_date()
+ax.autoscale_view()
+setp( gca().get_xticklabels(), rotation=45, horizontalalignment='right')
+
+show()
+
+*)

js_of_ocaml/matplotlib/finance_demo.py

+#!/usr/bin/env python
+from pylab import *
+from matplotlib.dates import  DateFormatter, WeekdayLocator, HourLocator, \
+     DayLocator, MONDAY, timezone
+from matplotlib.finance import quotes_historical_yahoo, candlestick,\
+     plot_day_summary, candlestick2
+
+import datetime
+
+date1 = datetime.date( 2004, 2, 1)
+date2 = datetime.date( 2004, 4, 12 )
+
+
+mondays = WeekdayLocator(MONDAY)        # major ticks on the mondays
+alldays    = DayLocator()              # minor ticks on the days
+weekFormatter = DateFormatter('%b %d')  # Eg, Jan 12
+dayFormatter = DateFormatter('%d')      # Eg, 12
+
+quotes = quotes_historical_yahoo(
+    'INTC', date1, date2)
+if not quotes:
+    raise SystemExit
+
+fig = figure()
+fig.subplots_adjust(bottom=0.2)
+ax = fig.add_subplot(111)
+ax.xaxis.set_major_locator(mondays)
+ax.xaxis.set_minor_locator(alldays)
+ax.xaxis.set_major_formatter(weekFormatter)
+#ax.xaxis.set_minor_formatter(dayFormatter)
+
+#plot_day_summary(ax, quotes, ticksize=3)
+candlestick(ax, quotes, width=0.6)
+
+ax.xaxis_date()
+ax.autoscale_view()
+setp( gca().get_xticklabels(), rotation=45, horizontalalignment='right')
+
+show()
+

js_of_ocaml/opy_of_ocaml.ml

   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.callObject (Callable.coerce (o#getItemString name)) (Array.to_list args ))
+      Obj.magic (Eval.callObject (Callable.coerce (o#getItemString name)) (Array.to_list args ))
     let inject = Obj.magic
   end
 

tests/set_closure_string_oo.ml

+open Opycaml.Api
+
+let _ = Base.initialize ()
+
+let m = Module.new_ "x"
+let _ = Module.setToSys m "x" 
+
+let _ = Format.eprintf "test start@."
+
+let freed = ref 0
+let finalize = fun _ -> incr freed
+
+let f n = 
+  let f = fun args -> 
+    Format.eprintf "f(%d)@." n;
+    Object.obj (Base.none ())
+  in
+  Gc.finalise finalize f; 
+  Module.setClosureString m "f" f;
+  if n mod 1000 = 0 then begin
+    Format.eprintf "*** %d@." n;
+    Opycaml.Utils.Gc.report ();
+    Format.eprintf "freed %d@." !freed
+  end
+;;
+
+let _ = 
+  for i = 0 to 100000 do
+    f i
+  done