Browse Source

generate StringImpl as _hx_c_String

Simon Krajewski 11 năm trước cách đây
mục cha
commit
595c9f17e3

+ 6 - 6
genpy.ml

@@ -857,7 +857,7 @@ module Printer = struct
 		)
 		)
 
 
 	let is_underlying_string t = match follow t with
 	let is_underlying_string t = match follow t with
-		| TAbstract(a,tl) -> (is_type1 "" "String")(Codegen.Abstract.get_underlying_type a tl)
+		| TAbstract(a,tl) -> (is_type1 "" "_hx_c_String")(Codegen.Abstract.get_underlying_type a tl)
 		| _ -> false
 		| _ -> false
 
 
 	let handle_keywords s =
 	let handle_keywords s =
@@ -1005,7 +1005,7 @@ module Printer = struct
 				Printf.sprintf "_hx_modf(%s, %s)" (print_expr pctx e1) (print_expr pctx e1)
 				Printf.sprintf "_hx_modf(%s, %s)" (print_expr pctx e1) (print_expr pctx e1)
 			| TBinop(OpUShr,e1,e2) ->
 			| TBinop(OpUShr,e1,e2) ->
 				Printf.sprintf "_hx_rshift(%s, %s)" (print_expr pctx e1) (print_expr pctx e2)
 				Printf.sprintf "_hx_rshift(%s, %s)" (print_expr pctx e1) (print_expr pctx e2)
-			| TBinop(OpAdd,e1,e2) when (is_type1 "" "String")(e.etype) || is_underlying_string e.etype ->
+			| TBinop(OpAdd,e1,e2) when (is_type1 "" "_hx_c_String")(e.etype) || is_underlying_string e.etype ->
 				let safe_string ex =
 				let safe_string ex =
 					match ex.eexpr with
 					match ex.eexpr with
 						| TConst(TString _) -> print_expr pctx ex
 						| TConst(TString _) -> print_expr pctx ex
@@ -1109,11 +1109,11 @@ module Printer = struct
 		match fa with
 		match fa with
 			| FInstance(c,{cf_name = "length" | "get_length"}) when (is_type "" "list")(TClassDecl c) ->
 			| FInstance(c,{cf_name = "length" | "get_length"}) when (is_type "" "list")(TClassDecl c) ->
 				Printf.sprintf "_hx_builtin.len(%s)" (print_expr pctx e1)
 				Printf.sprintf "_hx_builtin.len(%s)" (print_expr pctx e1)
-			| FInstance(c,{cf_name = "toUpperCase"}) when (is_type "" "String")(TClassDecl c) ->
+			| FInstance(c,{cf_name = "toUpperCase"}) when (is_type "" "_hx_c_String")(TClassDecl c) ->
 				Printf.sprintf "%s.toUpper" (print_expr pctx e1)
 				Printf.sprintf "%s.toUpper" (print_expr pctx e1)
-			| FInstance(c,{cf_name = "toLowerCase"}) when (is_type "" "String")(TClassDecl c) ->
+			| FInstance(c,{cf_name = "toLowerCase"}) when (is_type "" "_hx_c_String")(TClassDecl c) ->
 				Printf.sprintf "%s.toLower" (print_expr pctx e1)
 				Printf.sprintf "%s.toLower" (print_expr pctx e1)
-			| FInstance(c,{cf_name = "length"}) when (is_type "" "String")(TClassDecl c) ->
+			| FInstance(c,{cf_name = "length"}) when (is_type "" "_hx_c_String")(TClassDecl c) ->
 				Printf.sprintf "_hx_builtin.len(%s)" (print_expr pctx e1)
 				Printf.sprintf "_hx_builtin.len(%s)" (print_expr pctx e1)
 			| FInstance _ | FStatic _ ->
 			| FInstance _ | FStatic _ ->
 				do_default ()
 				do_default ()
@@ -1149,7 +1149,7 @@ module Printer = struct
 			let indent = pctx.pc_indent in
 			let indent = pctx.pc_indent in
 			let handle_base_type bt =
 			let handle_base_type bt =
 				let t = print_base_type bt in
 				let t = print_base_type bt in
-				let res = if t = "String" then
+				let res = if t = "_hx_c_String" then
 					Printf.sprintf "if isinstance(_hx_e1, str):\n%s\t%s = _hx_e1\n%s\t%s" indent v.v_name indent (print_expr {pctx with pc_indent = "\t" ^ pctx.pc_indent} e)
 					Printf.sprintf "if isinstance(_hx_e1, str):\n%s\t%s = _hx_e1\n%s\t%s" indent v.v_name indent (print_expr {pctx with pc_indent = "\t" ^ pctx.pc_indent} e)
 				else
 				else
 					Printf.sprintf "if isinstance(_hx_e1, %s):\n%s\t%s = _hx_e1\n%s\t%s" t indent v.v_name indent (print_expr {pctx with pc_indent = "\t" ^ pctx.pc_indent} e)
 					Printf.sprintf "if isinstance(_hx_e1, %s):\n%s\t%s = _hx_e1\n%s\t%s" t indent v.v_name indent (print_expr {pctx with pc_indent = "\t" ^ pctx.pc_indent} e)

+ 1 - 0
std/python/_std/String.hx

@@ -36,6 +36,7 @@ import python.internal.StringImpl;
 import python.lib.Builtin;
 import python.lib.Builtin;
 #end
 #end
 @:coreApi
 @:coreApi
+@:native("_hx_c_String")
 extern class String extends StringImpl {
 extern class String extends StringImpl {
 
 
 
 

+ 2 - 0
std/python/internal/StringImpl.hx

@@ -3,6 +3,8 @@ package python.internal;
 
 
 import python.lib.Builtin;
 import python.lib.Builtin;
 
 
+@:keep
+@:native("_hx_c_String")
 class StringImpl {
 class StringImpl {
 
 
 	public static function split (s:String, d:String) {
 	public static function split (s:String, d:String) {