Browse Source

[cpp] Get v4 gencpp changes working on v3.4

Hugh Sanderson 6 years ago
parent
commit
136247ed1d

+ 42 - 9
src/generators/gencpp.ml

@@ -760,7 +760,7 @@ and type_string_suff suffix haxe_type remap =
    | TAbstract ({ a_path = ([],"Int") },[]) -> "int"
    | TAbstract ({ a_path = (["cpp"],"UInt8") },[]) -> "unsigned char"
    | TAbstract( { a_path = ([], "EnumValue") }, _  ) -> "Dynamic"
-   | TAbstract ({ a_path = ([],"Null") }, [t]) ->
+   | TType ({ t_path = ([],"Null") }, [t]) ->
 		(match follow t with
 		| TAbstract ({ a_path = [],"Int" },_)
 		| TAbstract ({ a_path = [],"Float" },_)
@@ -979,6 +979,18 @@ let is_extern_class_instance obj =
 ;;
 
 
+(* Check to see if we are the first object in the parent tree to implement a dynamic interface *)
+let implement_dynamic_here class_def =
+   let implements_dynamic c = match c.cl_dynamic with None -> false | _ -> true  in
+   let rec super_implements_dynamic c = match c.cl_super with
+      | None -> false
+      | Some (csup, _) -> if (implements_dynamic csup) then true else
+            super_implements_dynamic csup;
+   in
+   ( (implements_dynamic class_def) && (not (super_implements_dynamic class_def) ) );;
+
+
+
 let rec is_dynamic_accessor name acc field class_def =
  ( ( acc ^ "_" ^ field.cf_name) = name ) &&
    ( not (List.exists (fun f -> f.cf_name=name) class_def.cl_ordered_fields) )
@@ -1885,7 +1897,7 @@ let rec cpp_type_of ctx haxe_type =
         baseType
    and cpp_type_of_pointer ctx p =
      match p with
-     | TAbstract ({ a_path = ([],"Null") },[t]) -> cpp_type_of ctx t
+     | TType ({ t_path = ([],"Null") },[t]) -> cpp_type_of ctx t
      | x ->  cpp_type_of ctx x
    (* Optional types are Dynamic if they norally could not be null *)
    and cpp_fun_arg_type_of ctx tvar opt =
@@ -5237,7 +5249,7 @@ let is_writable class_def field =
 let statics_except_meta class_def = (List.filter (fun static -> static.cf_name <> "__meta__" && static.cf_name <> "__rtti") class_def.cl_ordered_statics);;
 
 let has_set_member_field class_def =
-   (
+   implement_dynamic_here class_def || (
       let reflect_fields = List.filter (reflective class_def) (class_def.cl_ordered_fields) in
       let reflect_writable = List.filter (is_writable class_def) reflect_fields in
       List.exists variable_field reflect_writable
@@ -5253,14 +5265,14 @@ let has_set_static_field class_def =
 
 
 let has_get_fields class_def =
-   (
+   implement_dynamic_here class_def ||(
       let is_data_field field = (match follow field.cf_type with | TFun _ -> false | _ -> true) in
       List.exists is_data_field class_def.cl_ordered_fields
    )
 ;;
 
 let has_get_member_field class_def =
-   (
+   implement_dynamic_here class_def || (
       let reflect_fields = List.filter (reflective class_def) (class_def.cl_ordered_fields) in
       List.exists (is_readable class_def) reflect_fields
    )
@@ -5508,6 +5520,7 @@ let generate_class_files baseCtx super_deps constructor_deps class_def inScripta
    let classIdTxt = Printf.sprintf "0x%08lx" classId in
 
    (* Config *)
+   let implement_dynamic = implement_dynamic_here class_def in
    let override_iteration = (not nativeGen) && (has_new_gc_references baseCtx class_def) in
    let dynamic_interface_closures =  (Common.defined baseCtx.ctx_common Define.DynamicInterfaceClosures) in
 
@@ -5875,6 +5888,8 @@ let generate_class_files baseCtx super_deps constructor_deps class_def inScripta
          (* MARK function - explicitly mark all child pointers *)
          output_cpp ("void " ^ class_name ^ "::__Mark(HX_MARK_PARAMS)\n{\n");
          output_cpp ("\tHX_MARK_BEGIN_CLASS(" ^ smart_class_name ^ ");\n");
+         if (implement_dynamic) then
+            output_cpp "\tHX_MARK_DYNAMIC;\n";
          List.iter (dump_field_iterator "HX_MARK_MEMBER_NAME") implemented_instance_fields;
          (match super_needs_iteration with
          | "" -> ()
@@ -5884,6 +5899,8 @@ let generate_class_files baseCtx super_deps constructor_deps class_def inScripta
 
          (* Visit function - explicitly visit all child pointers *)
          output_cpp ("void " ^ class_name ^ "::__Visit(HX_VISIT_PARAMS)\n{\n");
+         if (implement_dynamic) then
+            output_cpp "\tHX_VISIT_DYNAMIC;\n";
          List.iter (dump_field_iterator "HX_VISIT_MEMBER_NAME") implemented_instance_fields;
          (match super_needs_iteration with
          | "" -> ()
@@ -5964,6 +5981,8 @@ let generate_class_files baseCtx super_deps constructor_deps class_def inScripta
             ) )
          in
          dump_quick_field_test (get_field_dat reflect_static_readable);
+         if (implement_dynamic) then
+            output_cpp "\tHX_CHECK_DYNAMIC_GET_FIELD(inName);\n";
          output_cpp ("\treturn false;\n}\n\n");
       end;
 
@@ -5999,7 +6018,12 @@ let generate_class_files baseCtx super_deps constructor_deps class_def inScripta
          ) in
 
          dump_quick_field_test (set_field_dat reflect_write_member_variables);
-         output_cpp ("\treturn super::__SetField(inName,inValue,inCallProp);\n}\n\n");
+         if (implement_dynamic) then begin
+            output_cpp ("\ttry { return super::__SetField(inName,inValue,inCallProp); }\n");
+            output_cpp ("\tcatch(Dynamic e) { HX_DYNAMIC_SET_FIELD(inName,inValue); }\n");
+            output_cpp "\treturn inValue;\n}\n\n";
+         end else
+            output_cpp ("\treturn super::__SetField(inName,inValue,inCallProp);\n}\n\n");
       end;
 
       if (has_set_static_field class_def) then begin
@@ -6036,6 +6060,8 @@ let generate_class_files baseCtx super_deps constructor_deps class_def inScripta
 
          output_cpp ("void " ^ class_name ^ "::__GetFields(Array< ::String> &outFields)\n{\n");
          List.iter append_field (List.filter is_data_field class_def.cl_ordered_fields);
+         if (implement_dynamic) then
+            output_cpp "\tHX_APPEND_DYNAMIC_FIELDS(outFields);\n";
          output_cpp "\tsuper::__GetFields(outFields);\n";
          output_cpp "};\n\n";
       end;
@@ -6229,7 +6255,8 @@ let generate_class_files baseCtx super_deps constructor_deps class_def inScripta
             output_cpp ("   HX_DEFINE_SCRIPTABLE_INTERFACE\n")
          else begin
             output_cpp ("   HX_DEFINE_SCRIPTABLE(HX_ARR_LIST" ^ (string_of_int (List.length constructor_var_list) ) ^ ")\n");
-            output_cpp "\tHX_DEFINE_SCRIPTABLE_DYNAMIC;\n";
+            if (not implement_dynamic) then
+               output_cpp "\tHX_DEFINE_SCRIPTABLE_DYNAMIC;\n";
          end;
       end;
 
@@ -6508,6 +6535,9 @@ let generate_class_files baseCtx super_deps constructor_deps class_def inScripta
       if (has_get_fields class_def) then
          output_h ("\t\tvoid __GetFields(Array< ::String> &outFields);\n");
 
+      if (implement_dynamic) then
+         output_h ("\t\tHX_DECLARE_IMPLEMENT_DYNAMIC;\n");
+
       if (has_compare_field class_def) then
          output_h ("\t\tint __Compare(const hx::Object *inRHS) const { " ^
                            "return const_cast<" ^ class_name ^ " *>(this)->__compare(Dynamic((hx::Object *)inRHS)); }\n");
@@ -6794,7 +6824,7 @@ let is_assign_op op =
 
 let rec script_type_string haxe_type =
    match haxe_type with
-   | TAbstract ({ a_path = ([],"Null") },[t]) ->
+   | TType ({ t_path = ([],"Null") },[t]) ->
       (match follow t with
       | TAbstract ({ a_path = [],"Int" },_)
       | TAbstract ({ a_path = [],"Float" },_)
@@ -7114,7 +7144,7 @@ class script_writer ctx filename asciiOut =
    val identTable = Hashtbl.create 0
    val fileTable = Hashtbl.create 0
    val identBuffer = Buffer.create 0
-   val cppiaAst = false
+   val cppiaAst = true
 
    method stringId name =
       try ( Hashtbl.find identTable name )
@@ -8004,6 +8034,7 @@ let generate_script_class common_ctx script class_def =
    script#write ((string_of_int ( (List.length ordered_fields) +
                                  (List.length ordered_statics) +
                                  (match class_def.cl_constructor with Some _ -> 1 | _ -> 0 ) +
+                                 (if (implement_dynamic_here class_def) then 1 else 0) +
                                  (match class_def.cl_init with Some _ -> 1 | _ -> 0 ) ) )
                                  ^ "\n");
 
@@ -8044,6 +8075,8 @@ let generate_script_class common_ctx script class_def =
 
    List.iter (generate_field false) ordered_fields;
    List.iter (generate_field true) ordered_statics;
+   if (implement_dynamic_here class_def) then
+      script#implDynamic;
    script#write "\n";
 ;;
 

+ 34 - 17
std/cpp/_std/haxe/ds/IntMap.hx

@@ -1,5 +1,5 @@
 /*
- * Copyright (C)2005-2017 Haxe Foundation
+ * Copyright (C)2005-2019 Haxe Foundation
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -22,28 +22,33 @@
 package haxe.ds;
 
 @:headerClassCode("
-  inline void set(int key, ::null value) { __int_hash_set(h,key,value); }
-  inline void set(int key, bool value) { __int_hash_set(h,key,value); }
-  inline void set(int key, char value) { __int_hash_set_int(h,key,value); }
-  inline void set(int key, unsigned char value) { __int_hash_set_int(h,key,value); }
-  inline void set(int key, signed char value) { __int_hash_set_int(h,key,value); }
-  inline void set(int key, short value) { __int_hash_set_int(h,key,value); }
-  inline void set(int key, unsigned short value) { __int_hash_set_int(h,key,value); }
-  inline void set(int key, int value) { __int_hash_set_int(h,key,value); }
-  inline void set(int key, unsigned int value) { __int_hash_set_int(h,key,value); }
-  inline void set(int key, float value) { __int_hash_set_float(h,key,value); }
-  inline void set(int key, double value) { __int_hash_set_float(h,key,value); }
-  inline void set(int key, ::String value) { __int_hash_set_string(h,key,value); }
+  inline void set(int key, ::null value) { __int_hash_set(HX_MAP_THIS,key,value); }
+  inline void set(int key, bool value) { __int_hash_set(HX_MAP_THIS,key,value); }
+  inline void set(int key, char value) { __int_hash_set_int(HX_MAP_THIS,key,value); }
+  inline void set(int key, unsigned char value) { __int_hash_set_int(HX_MAP_THIS,key,value); }
+  inline void set(int key, signed char value) { __int_hash_set_int(HX_MAP_THIS,key,value); }
+  inline void set(int key, short value) { __int_hash_set_int(HX_MAP_THIS,key,value); }
+  inline void set(int key, unsigned short value) { __int_hash_set_int(HX_MAP_THIS,key,value); }
+  inline void set(int key, int value) { __int_hash_set_int(HX_MAP_THIS,key,value); }
+  inline void set(int key, unsigned int value) { __int_hash_set_int(HX_MAP_THIS,key,value); }
+  inline void set(int key, float value) { __int_hash_set_float(HX_MAP_THIS,key,value); }
+  inline void set(int key, double value) { __int_hash_set_float(HX_MAP_THIS,key,value); }
+  inline void set(int key, ::String value) { __int_hash_set_string(HX_MAP_THIS,key,value); }
 
   template<typename V, typename H>
-  inline void set(int key, const ::cpp::Struct<V,H> &value) {__int_hash_set(h,key,value); }
+  inline void set(int key, const ::cpp::Struct<V,H> &value) {__int_hash_set(HX_MAP_THIS,key,value); }
   template<typename F>
-  inline void set(int key, const ::cpp::Function<F> &value) {__int_hash_set(h,key,value); }
+  inline void set(int key, const ::cpp::Function<F> &value) {__int_hash_set(HX_MAP_THIS,key,value); }
   template<typename V>
-  inline void set(int key, const ::cpp::Pointer<V> &value) {__int_hash_set(h,key,(Dynamic)value ); }
+  inline void set(int key, const ::cpp::Pointer<V> &value) {__int_hash_set(HX_MAP_THIS,key,(Dynamic)value ); }
 
   template<typename VALUE>
   inline void set(Dynamic &key, const VALUE &value) { set( (int)key, value ); }
+
+  inline bool get_bool(int key) { return __int_hash_get_bool(h,key); }
+  inline int get_int(int key) { return __int_hash_get_int(h,key); }
+  inline Float get_float(int key) { return __int_hash_get_float(h,key); }
+  inline String get_string(int key) { return __int_hash_get_string(h,key); }
 ")
 @:coreApi class IntMap<T> implements haxe.Constraints.IMap<Int,T> {
 
@@ -53,7 +58,7 @@ package haxe.ds;
 	public function new() : Void { }
 
 	public function set( key : Int, value : T ) : Void {
-		untyped __global__.__int_hash_set(h,key,value);
+		untyped __global__.__int_hash_set(__cpp__("HX_MAP_THIS"),key,value);
 	}
 
 	public function get( key : Int ) : Null<T> {
@@ -81,4 +86,16 @@ package haxe.ds;
 	public function toString() : String {
 		return untyped __global__.__int_hash_to_string(h);
 	}
+
+   #if (scriptable)
+   private function setString(key:Int,val:String) : Void { untyped __int_hash_set_string(__cpp__("HX_MAP_THIS"),key,val); }
+   private function setInt(key:Int,val:Int) : Void { untyped __int_hash_set_int(__cpp__("HX_MAP_THIS"),key,val); }
+   private function setBool(key:Int,val:Bool) : Void { untyped __int_hash_set_int(__cpp__("HX_MAP_THIS"),key,val); }
+   private function setFloat(key:Int,val:Float) : Void { untyped __int_hash_set_float(__cpp__("HX_MAP_THIS"),key,val); }
+
+   private function getString(key:Int) : String { return untyped __int_hash_get_string(h,key); }
+   private function getInt(key:Int) : Int { return untyped __int_hash_get_int(h,key); }
+   private function getBool(key:Int) : Bool { return untyped __int_hash_get_bool(h,key); }
+   private function getFloat(key:Int) : Float { return untyped __int_hash_get_float(h,key); }
+   #end
 }

+ 34 - 17
std/cpp/_std/haxe/ds/ObjectMap.hx

@@ -1,5 +1,5 @@
 /*
- * Copyright (C)2005-2017 Haxe Foundation
+ * Copyright (C)2005-2019 Haxe Foundation
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -22,26 +22,31 @@
 package haxe.ds;
 
 @:headerClassCode("
-  inline void set(Dynamic key, ::null value) { __object_hash_set(h,key,value); }
-  inline void set(Dynamic key, bool value) { __object_hash_set(h,key,value); }
-  inline void set(Dynamic key, char value) { __object_hash_set_int(h,key,value); }
-  inline void set(Dynamic key, unsigned char value) { __object_hash_set_int(h,key,value); }
-  inline void set(Dynamic key, signed char value) { __object_hash_set_int(h,key,value); }
-  inline void set(Dynamic key, short value) { __object_hash_set_int(h,key,value); }
-  inline void set(Dynamic key, unsigned short value) { __object_hash_set_int(h,key,value); }
-  inline void set(Dynamic key, int value) { __object_hash_set_int(h,key,value); }
-  inline void set(Dynamic key, unsigned int value) { __object_hash_set_int(h,key,value); }
-  inline void set(Dynamic key, float value) { __object_hash_set_float(h,key,value); }
-  inline void set(Dynamic key, double value) { __object_hash_set_float(h,key,value); }
-  inline void set(Dynamic key, ::String value) { __object_hash_set_string(h,key,value); }
+  inline void set(Dynamic key, ::null value) { __object_hash_set(HX_MAP_THIS,key,value); }
+  inline void set(Dynamic key, bool value) { __object_hash_set(HX_MAP_THIS,key,value); }
+  inline void set(Dynamic key, char value) { __object_hash_set_int(HX_MAP_THIS,key,value); }
+  inline void set(Dynamic key, unsigned char value) { __object_hash_set_int(HX_MAP_THIS,key,value); }
+  inline void set(Dynamic key, signed char value) { __object_hash_set_int(HX_MAP_THIS,key,value); }
+  inline void set(Dynamic key, short value) { __object_hash_set_int(HX_MAP_THIS,key,value); }
+  inline void set(Dynamic key, unsigned short value) { __object_hash_set_int(HX_MAP_THIS,key,value); }
+  inline void set(Dynamic key, int value) { __object_hash_set_int(HX_MAP_THIS,key,value); }
+  inline void set(Dynamic key, unsigned int value) { __object_hash_set_int(HX_MAP_THIS,key,value); }
+  inline void set(Dynamic key, float value) { __object_hash_set_float(HX_MAP_THIS,key,value); }
+  inline void set(Dynamic key, double value) { __object_hash_set_float(HX_MAP_THIS,key,value); }
+  inline void set(Dynamic key, ::String value) { __object_hash_set_string(HX_MAP_THIS,key,value); }
 
 
   template<typename V, typename H>
-  inline void set(Dynamic key, const ::cpp::Struct<V,H> &value) {__object_hash_set(h,key,value); }
+  inline void set(Dynamic key, const ::cpp::Struct<V,H> &value) {__object_hash_set(HX_MAP_THIS,key,value); }
   template<typename V>
-  inline void set(Dynamic key, const ::cpp::Function<V> &value) {__object_hash_set(h,key,(Dynamic)value ); }
+  inline void set(Dynamic key, const ::cpp::Function<V> &value) {__object_hash_set(HX_MAP_THIS,key,(Dynamic)value ); }
   template<typename V>
-  inline void set(Dynamic key, const ::cpp::Pointer<V> &value) {__object_hash_set(h,key,(Dynamic)value ); }
+  inline void set(Dynamic key, const ::cpp::Pointer<V> &value) {__object_hash_set(HX_MAP_THIS,key,(Dynamic)value ); }
+
+  inline bool get_bool(Dynamic key) { return __object_hash_get_bool(h,key); }
+  inline int get_int(Dynamic key) { return __object_hash_get_int(h,key); }
+  inline Float get_float(Dynamic key) { return __object_hash_get_float(h,key); }
+  inline String get_string(Dynamic key) { return __object_hash_get_string(h,key); }
 
 ")
 @:coreApi
@@ -52,7 +57,7 @@ class ObjectMap<K:{},V> implements haxe.Constraints.IMap<K,V> {
 	public function new() : Void { }
 
 	public function set( key : K, value : V ) : Void {
-		untyped __global__.__object_hash_set(h,key,value);
+		untyped __global__.__object_hash_set(__cpp__("HX_MAP_THIS"),key,value);
 	}
 
 	public function get( key : K ) : Null<V> {
@@ -80,4 +85,16 @@ class ObjectMap<K:{},V> implements haxe.Constraints.IMap<K,V> {
 	public function toString() : String {
 		return untyped __global__.__object_hash_to_string(h);
 	}
+
+   #if (scriptable)
+   private function setString(key:Dynamic,val:String) : Void { untyped __object_hash_set_string(__cpp__("HX_MAP_THIS"),key,val); }
+   private function setInt(key:Dynamic,val:Int) : Void { untyped __object_hash_set_int(__cpp__("HX_MAP_THIS"),key,val); }
+   private function setBool(key:Dynamic,val:Bool) : Void { untyped __object_hash_set_int(__cpp__("HX_MAP_THIS"),key,val); }
+   private function setFloat(key:Dynamic,val:Float) : Void { untyped __object_hash_set_float(__cpp__("HX_MAP_THIS"),key,val); }
+
+   private function getString(key:Dynamic) : String { return untyped __object_hash_get_string(h,key); }
+   private function getInt(key:Dynamic) : Int { return untyped __object_hash_get_int(h,key); }
+   private function getBool(key:Dynamic) : Bool { return untyped __object_hash_get_bool(h,key); }
+   private function getFloat(key:Dynamic) : Float { return untyped __object_hash_get_float(h,key); }
+   #end
 }

+ 34 - 17
std/cpp/_std/haxe/ds/StringMap.hx

@@ -1,5 +1,5 @@
 /*
- * Copyright (C)2005-2017 Haxe Foundation
+ * Copyright (C)2005-2019 Haxe Foundation
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -22,28 +22,33 @@
 package haxe.ds;
 
 @:headerClassCode("
-  inline void set(String key, ::null value) { __string_hash_set(h,key,value); }
-  inline void set(String key, bool value) { __string_hash_set(h,key,value); }
-  inline void set(String key, char value) { __string_hash_set_int(h,key,value); }
-  inline void set(String key, unsigned char value) { __string_hash_set_int(h,key,value); }
-  inline void set(String key, signed char value) { __string_hash_set_int(h,key,value); }
-  inline void set(String key, short value) { __string_hash_set_int(h,key,value); }
-  inline void set(String key, unsigned short value) { __string_hash_set_int(h,key,value); }
-  inline void set(String key, int value) { __string_hash_set_int(h,key,value); }
-  inline void set(String key, unsigned int value) { __string_hash_set_int(h,key,value); }
-  inline void set(String key, float value) { __string_hash_set_float(h,key,value); }
-  inline void set(String key, double value) { __string_hash_set_float(h,key,value); }
-  inline void set(String key, ::String value) { __string_hash_set_string(h,key,value); }
+  inline void set(String key, ::null value) { __string_hash_set(HX_MAP_THIS,key,value); }
+  inline void set(String key, bool value) { __string_hash_set(HX_MAP_THIS,key,value); }
+  inline void set(String key, char value) { __string_hash_set_int(HX_MAP_THIS,key,value); }
+  inline void set(String key, unsigned char value) { __string_hash_set_int(HX_MAP_THIS,key,value); }
+  inline void set(String key, signed char value) { __string_hash_set_int(HX_MAP_THIS,key,value); }
+  inline void set(String key, short value) { __string_hash_set_int(HX_MAP_THIS,key,value); }
+  inline void set(String key, unsigned short value) { __string_hash_set_int(HX_MAP_THIS,key,value); }
+  inline void set(String key, int value) { __string_hash_set_int(HX_MAP_THIS,key,value); }
+  inline void set(String key, unsigned int value) { __string_hash_set_int(HX_MAP_THIS,key,value); }
+  inline void set(String key, float value) { __string_hash_set_float(HX_MAP_THIS,key,value); }
+  inline void set(String key, double value) { __string_hash_set_float(HX_MAP_THIS,key,value); }
+  inline void set(String key, ::String value) { __string_hash_set_string(HX_MAP_THIS,key,value); }
 
   template<typename V, typename H>
-  inline void set(String key, const ::cpp::Struct<V,H> &value) {__string_hash_set(h,key,value); }
+  inline void set(String key, const ::cpp::Struct<V,H> &value) {__string_hash_set(HX_MAP_THIS,key,value); }
   template<typename V>
-  inline void set(String key, const ::cpp::Function<V> &value) {__string_hash_set(h,key,(Dynamic)value ); }
+  inline void set(String key, const ::cpp::Function<V> &value) {__string_hash_set(HX_MAP_THIS,key,(Dynamic)value ); }
   template<typename V>
-  inline void set(String key, const ::cpp::Pointer<V> &value) {__string_hash_set(h,key,(Dynamic)value ); }
+  inline void set(String key, const ::cpp::Pointer<V> &value) {__string_hash_set(HX_MAP_THIS,key,(Dynamic)value ); }
 
   template<typename VALUE>
   inline void set(Dynamic &key, const VALUE &value) { set( (String)key, value ); }
+
+  inline bool get_bool(String key) { return __string_hash_get_bool(h,key); }
+  inline int get_int(String key) { return __string_hash_get_int(h,key); }
+  inline Float get_float(String key) { return __string_hash_get_float(h,key); }
+  inline String get_string(String key) { return __string_hash_get_string(h,key); }
 ")
 @:coreApi class StringMap<T> implements haxe.Constraints.IMap<String,T> {
 	@:ifFeature("haxe.ds.StringMap.*")
@@ -52,7 +57,7 @@ package haxe.ds;
 	public function new() : Void { }
 
 	public function set( key : String, value : T ) : Void {
-		untyped __global__.__string_hash_set(h,key,value);
+		untyped __global__.__string_hash_set(__cpp__("HX_MAP_THIS"),key,value);
 	}
 
 	public function get( key : String ) : Null<T> {
@@ -80,4 +85,16 @@ package haxe.ds;
 	public function toString() : String {
 		return untyped __global__.__string_hash_to_string(h);
 	}
+
+   #if (scriptable)
+   private function setString(key:String,val:String) : Void { untyped __string_hash_set_string(__cpp__("HX_MAP_THIS"),key,val); }
+   private function setInt(key:String,val:Int) : Void { untyped __string_hash_set_int(__cpp__("HX_MAP_THIS"),key,val); }
+   private function setBool(key:String,val:Bool) : Void { untyped __string_hash_set_int(__cpp__("HX_MAP_THIS"),key,val); }
+   private function setFloat(key:String,val:Float) : Void { untyped __string_hash_set_float(__cpp__("HX_MAP_THIS"),key,val); }
+
+   private function getString(key:String) : String { return untyped __string_hash_get_string(h,key); }
+   private function getInt(key:String) : Int { return untyped __string_hash_get_int(h,key); }
+   private function getBool(key:String) : Bool { return untyped __string_hash_get_bool(h,key); }
+   private function getFloat(key:String) : Float { return untyped __string_hash_get_float(h,key); }
+   #end
 }

+ 17 - 17
std/cpp/_std/haxe/ds/WeakMap.hx

@@ -1,5 +1,5 @@
 /*
- * Copyright (C)2005-2017 Haxe Foundation
+ * Copyright (C)2005-2019 Haxe Foundation
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -22,25 +22,25 @@
 package haxe.ds;
 
 @:headerClassCode("
-  inline void set(Dynamic key, ::null value) { __object_hash_set(h,key,value,true); }
-  inline void set(Dynamic key, bool value) { __object_hash_set(h,key,value,true); }
-  inline void set(Dynamic key, char value) { __object_hash_set_int(h,key,value,true); }
-  inline void set(Dynamic key, unsigned char value) { __object_hash_set_int(h,key,value,true); }
-  inline void set(Dynamic key, signed char value) { __object_hash_set_int(h,key,value,true); }
-  inline void set(Dynamic key, short value) { __object_hash_set_int(h,key,value,true); }
-  inline void set(Dynamic key, unsigned short value) { __object_hash_set_int(h,key,value,true); }
-  inline void set(Dynamic key, int value) { __object_hash_set_int(h,key,value,true); }
-  inline void set(Dynamic key, unsigned int value) { __object_hash_set_int(h,key,value,true); }
-  inline void set(Dynamic key, float value) { __object_hash_set_float(h,key,value,true); }
-  inline void set(Dynamic key, double value) { __object_hash_set_float(h,key,value,true); }
-  inline void set(Dynamic key, ::String value) { __object_hash_set_string(h,key,value,true); }
+  inline void set(Dynamic key, ::null value) { __object_hash_set(HX_MAP_THIS,key,value,true); }
+  inline void set(Dynamic key, bool value) { __object_hash_set(HX_MAP_THIS,key,value,true); }
+  inline void set(Dynamic key, char value) { __object_hash_set_int(HX_MAP_THIS,key,value,true); }
+  inline void set(Dynamic key, unsigned char value) { __object_hash_set_int(HX_MAP_THIS,key,value,true); }
+  inline void set(Dynamic key, signed char value) { __object_hash_set_int(HX_MAP_THIS,key,value,true); }
+  inline void set(Dynamic key, short value) { __object_hash_set_int(HX_MAP_THIS,key,value,true); }
+  inline void set(Dynamic key, unsigned short value) { __object_hash_set_int(HX_MAP_THIS,key,value,true); }
+  inline void set(Dynamic key, int value) { __object_hash_set_int(HX_MAP_THIS,key,value,true); }
+  inline void set(Dynamic key, unsigned int value) { __object_hash_set_int(HX_MAP_THIS,key,value,true); }
+  inline void set(Dynamic key, float value) { __object_hash_set_float(HX_MAP_THIS,key,value,true); }
+  inline void set(Dynamic key, double value) { __object_hash_set_float(HX_MAP_THIS,key,value,true); }
+  inline void set(Dynamic key, ::String value) { __object_hash_set_string(HX_MAP_THIS,key,value,true); }
 
   template<typename V, typename H>
-  inline void set(Dynamic key, const ::cpp::Struct<V,H> &value) {__object_hash_set(h,key,value,true); }
+  inline void set(Dynamic key, const ::cpp::Struct<V,H> &value) {__object_hash_set(HX_MAP_THIS,key,value,true); }
   template<typename V>
-  inline void set(Dynamic key, const ::cpp::Pointer<V> &value) {__object_hash_set(h,key,(Dynamic)value,true ); }
+  inline void set(Dynamic key, const ::cpp::Pointer<V> &value) {__object_hash_set(HX_MAP_THIS,key,(Dynamic)value,true ); }
   template<typename V>
-  inline void set(Dynamic key, const ::cpp::Function<V> &value) {__object_hash_set(h,key,(Dynamic)value,true ); }
+  inline void set(Dynamic key, const ::cpp::Function<V> &value) {__object_hash_set(HX_MAP_THIS,key,(Dynamic)value,true ); }
 ")
 @:coreApi
 class WeakMap<K:{},V> implements haxe.Constraints.IMap<K,V> {
@@ -50,7 +50,7 @@ class WeakMap<K:{},V> implements haxe.Constraints.IMap<K,V> {
 	public function new() : Void { }
 
 	public function set( key : K, value : V ) : Void {
-		untyped __global__.__object_hash_set(h,key,value,true);
+		untyped __global__.__object_hash_set(__cpp__("HX_MAP_THIS"),key,value,true);
 	}
 
 	public function get( key : K ) : Null<V> {