소스 검색

remove more precode, cleanup _hx_builtin occurrences

frabbit 11 년 전
부모
커밋
8257a5327f

+ 9 - 9
genpy.ml

@@ -1049,9 +1049,9 @@ module Printer = struct
 				begin match e2.eexpr with
 					| TConst(TString s) ->
 						begin match s with
-							| "string" -> Printf.sprintf "Std._hx_is(%s, _hx_builtin.str)" (print_expr pctx e1)
-							| "boolean" -> Printf.sprintf "Std._hx_is(%s, _hx_builtin.bool)" (print_expr pctx e1)
-							| "number" -> Printf.sprintf "Std._hx_is(%s, _hx_builtin.float)" (print_expr pctx e1)
+							| "string" -> Printf.sprintf "Std._hx_is(%s, python_lib_Builtin.str)" (print_expr pctx e1)
+							| "boolean" -> Printf.sprintf "Std._hx_is(%s, python_lib_Builtin.bool)" (print_expr pctx e1)
+							| "number" -> Printf.sprintf "Std._hx_is(%s, python_lib_Builtin.float)" (print_expr pctx e1)
 							| _ -> assert false
 						end
 					| _ ->
@@ -1193,9 +1193,9 @@ module Printer = struct
 		match fa with
 			(* we need to get rid of these cases in the transformer, how is this handled in js *)
 			| 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 "python_lib_Builtin.len(%s)" (print_expr pctx e1)
 			| FInstance(c,{cf_name = "length"}) when (is_type "" "String")(TClassDecl c) ->
-				Printf.sprintf "_hx_builtin.len(%s)" (print_expr pctx e1)
+				Printf.sprintf "python_lib_Builtin.len(%s)" (print_expr pctx e1)
 			| FStatic(c,{cf_name = "fromCharCode"}) when (is_type "" "String")(TClassDecl c) ->
 				Printf.sprintf "HxString.fromCharCode"
 			| FInstance _ | FStatic _ ->
@@ -1203,14 +1203,14 @@ module Printer = struct
 			| FAnon cf when name = "iterator" && not is_assign ->
 				begin match follow cf.cf_type with
 					| TFun([],_) ->
-						Printf.sprintf "_hx_functools.partial(HxOverrides.iterator, %s)" obj
+						Printf.sprintf "python_lib_FuncTools.partial(HxOverrides.iterator, %s)" obj
 					| _ ->
 						do_default()
 				end
 			| FAnon cf when name = "shift" && not is_assign ->
 				begin match follow cf.cf_type with
 					| TFun([],_) ->
-						Printf.sprintf "_hx_functools.partial(HxOverrides.shift, %s)" obj
+						Printf.sprintf "python_lib_FuncTools.partial(HxOverrides.shift, %s)" obj
 					| _ ->
 						do_default()
 				end
@@ -1223,9 +1223,9 @@ module Printer = struct
 			let handle_base_type bt =
 				let t = print_base_type bt in
 				let res = if t = "String" then
-					Printf.sprintf "if _hx_builtin.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 python_lib_Builtin.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
-					Printf.sprintf "if _hx_builtin.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 python_lib_Builtin.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)
 				in
 				if i > 0 then
 					indent ^ "el" ^ res

+ 7 - 8
std/python/Boot.hx

@@ -7,6 +7,7 @@ import python.internal.EnumImpl;
 import python.internal.HxOverrides;
 import python.internal.HxException;
 import python.internal.AnonObject;
+import python.internal.HxBuiltin;
 
 import python.Syntax;
 
@@ -16,12 +17,10 @@ private extern class Set<T> {
 	}
 }
 
+@:import("math") private extern class Math {}
+@:import("inspect") private extern class Inspect {}
 
 @:preCode("
-import builtins as _hx_builtin
-import functools as _hx_functools
-import math as _hx_math
-
 _hx_classes = dict()
 
 class _hx_AnonObject(object):
@@ -31,10 +30,10 @@ class _hx_AnonObject(object):
 @:keep class Boot {
 
 	static function __init__ () {
-		Internal.importAsPrefixed("inspect", "boot_inspect");
-		Boot.inspect = Internal.pythonCodePrefixed("boot_inspect");
-		Boot.math = Internal.pythonCodePrefixed("math");
-		Boot.builtin = Internal.pythonCodePrefixed("builtin");
+
+		Boot.inspect = Inspect;
+		Boot.math = Math;
+		Boot.builtin = HxBuiltin.instance();
 	}
 
 	static inline function mathRound (v:Float) {

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

@@ -27,7 +27,6 @@ import python.lib.Builtin;
 /**
 	This class defines mathematical functions and constants.
 **/
-@:native("_hx_math")
 @:import("math")
 @:coreApi
 extern class Math

+ 2 - 4
std/python/internal/ArrayImpl.hx

@@ -23,15 +23,13 @@
 package python.internal;
 
 import python.lib.FuncTools;
-//import python.lib.Builtin;
-
-private abstract Builtin(Dynamic) {}
+import python.internal.HxBuiltin;
 
 @:allow(Array)
 @:keep
 class ArrayImpl {
 
-	static inline function builtin():Builtin return Internal.builtin();
+	static inline function builtin():Dynamic return HxBuiltin.instance();
 
 	public static inline function get_length <T>(x:Array<T>):Int return Syntax.callField(builtin(), "len", x);
 

+ 6 - 0
std/python/internal/HxBuiltin.hx

@@ -0,0 +1,6 @@
+
+package python.internal;
+
+@:import("builtins") extern class HxBuiltin {
+	public static inline function instance ():Dynamic return HxBuiltin;
+}

+ 1 - 6
std/python/internal/Internal.hx

@@ -10,7 +10,6 @@ class Internal {
 
 	static var _prefix = "_hx_";
 
-	static var _builtin = _prefix + "builtin";
 
 	static var _className = _prefix + "class_name";
 	static var _class = _prefix + "class";
@@ -41,15 +40,11 @@ class Internal {
 	}
 
 	static function has (o:Expr, field:String):Expr {
-		return macro python.Syntax.pythonCode($v{_builtin}).hasattr($o, $v{field});
+		return macro python.internal.HxBuiltin.instance().hasattr($o, $v{field});
 	}
 
 	#end
 
-	macro public static function builtin ():Expr {
-		return macro (python.Syntax.pythonCode($v{_builtin}):Dynamic);
-	}
-
 	macro public static function classRegistry ():Expr {
 		return macro (python.Syntax.pythonCode($v{_classes}) : python.lib.Dict<String, Class<Dynamic>>);
 	}

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

@@ -1,13 +1,13 @@
 package python.internal;
 
 import python.internal.Internal;
-
+import python.internal.HxBuiltin;
 
 @:keep
 @:native("HxString")
 class StringImpl {
 
-	static inline function builtin ():Dynamic return Internal.builtin();
+	static inline function builtin():Dynamic return HxBuiltin.instance();
 
 	public static function split (s:String, d:String) {
 		return if (d == "") Syntax.field(builtin(), "list")(s) else Syntax.callField(s, "split", d);

+ 1 - 1
std/python/lib/Builtin.hx

@@ -7,7 +7,7 @@ import python.lib.Dict;
 import python.NativeIterable;
 import python.NativeIterator;
 
-@:native("_hx_builtin")
+@:import("builtins")
 extern class Builtin {
 
 

+ 1 - 1
std/python/lib/FuncTools.hx

@@ -2,7 +2,7 @@
 package python.lib;
 
 
-@:native("_hx_functools")
+@:import("functools")
 extern class FuncTools {
 
 	public static function cmp_to_key<A>(f:A->A->Int):Dynamic;