Browse Source

[cpp] Add hxcpp_api_level to allow backwards compatibility in both haxe and c++ code. Add additional memory usage statistics

Hugh 11 years ago
parent
commit
e8c5b5abb5
4 changed files with 23 additions and 2 deletions
  1. 2 0
      common.ml
  2. 2 1
      gencpp.ml
  3. 1 0
      main.ml
  4. 18 1
      std/cpp/vm/Gc.hx

+ 2 - 0
common.ml

@@ -183,6 +183,7 @@ module Define = struct
 		| GencommonDebug
 		| HaxeBoot
 		| HaxeVer
+		| HxcppApiLevel
 		| IncludePrefix
 		| Interp
 		| JavaVer
@@ -252,6 +253,7 @@ module Define = struct
 		| GencommonDebug -> ("gencommon_debug","GenCommon internal")
 		| HaxeBoot -> ("haxe_boot","Given the name 'haxe' to the flash boot class instead of a generated name")
 		| HaxeVer -> ("haxe_ver","The current Haxe version value")
+		| HxcppApiLevel -> ("hxcpp_api_level","Provided to allow compatibility between hxcpp versions")
 		| IncludePrefix -> ("include_prefix","prepend path to generated include files")
 		| Interp -> ("interp","The code is compiled to be run with --interp")
 		| JavaVer -> ("java_ver", "<version:5-7> Sets the Java version to be targeted")

+ 2 - 1
gencpp.ml

@@ -3591,7 +3591,8 @@ let write_build_data common_ctx filename classes main_deps build_extra exe_name
 	in
 
 	output_string buildfile "<xml>\n";
-	output_string buildfile "<set name=\"HXCPP_API_LEVEL\" value=\"1\" />\n";
+	output_string buildfile ("<set name=\"HXCPP_API_LEVEL\" value=\"" ^
+            (Common.defined_value common_ctx Define.HxcppApiLevel) ^ "\" />\n");
 	output_string buildfile "<files id=\"haxe\">\n";
 	output_string buildfile "<compilerflag value=\"-Iinclude\"/>\n";
 	List.iter add_class_to_buildfile classes;

+ 1 - 0
main.ml

@@ -929,6 +929,7 @@ try
 	let interp = ref false in
 	let swf_version = ref false in
 	Common.define_value com Define.HaxeVer (float_repres (float_of_int version /. 10000.));
+	Common.define_value com Define.HxcppApiLevel "310";
 	Common.raw_define com "haxe3";
 	Common.define_value com Define.Dce "std";
 	com.warning <- (fun msg p -> message ctx ("Warning : " ^ msg) p);

+ 18 - 1
std/cpp/vm/Gc.hx

@@ -23,6 +23,11 @@ package cpp.vm;
 
 class Gc
 {
+   public static inline var MEM_INFO_USAGE = 0;
+   public static inline var MEM_INFO_RESERVED = 1;
+   public static inline var MEM_INFO_CURRENT = 2;
+   public static inline var MEM_INFO_LARGE = 3;
+
    static public function enable(inEnable:Bool) : Void
    {
       untyped __global__.__hxcpp_enable(inEnable);
@@ -38,9 +43,21 @@ class Gc
       untyped __global__.__hxcpp_gc_compact();
    }
 
+   // Introduced hxcpp_api_level 310
+   // Returns stats on memory usage:
+   //   MEM_INFO_USAGE - estimate of how much is needed by program (at last collect)
+   //   MEM_INFO_RESERVED - memory allocated for possible use
+   //   MEM_INFO_CURRENT - memory in use, includes uncollected garbage.
+   //     This will generally saw-tooth between USAGE and RESERVED
+   //   MEM_INFO_LARGE - Size of separate pool used for large allocs.  Included in all the above.
+   static public function memInfo(inWhatInfo:Int) : Int
+   {
+      return untyped __global__.__hxcpp_gc_mem_info(inWhatInfo);
+   }
+
    static public function memUsage() : Int
    {
-      return untyped __global__.__hxcpp_gc_used_bytes();
+      return untyped __global__.__hxcpp_gc_mem_info(MEM_INFO_USAGE);
    }
 
    static public function trace(sought:Class<Dynamic>,printInstances:Bool=true) : Int