瀏覽代碼

move String.length implementation to compiler

Simon Krajewski 11 年之前
父節點
當前提交
0566f733a8
共有 2 個文件被更改,包括 5 次插入2 次删除
  1. 2 0
      genpy.ml
  2. 3 2
      std/python/_std/String.hx

+ 2 - 0
genpy.ml

@@ -1113,6 +1113,8 @@ module Printer = struct
 				Printf.sprintf "%s.toUpper" (print_expr pctx e1)
 			| FInstance(c,{cf_name = "toLowerCase"}) when (is_type "" "String")(TClassDecl c) ->
 				Printf.sprintf "%s.toLower" (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)
 			| FInstance _ | FStatic _ ->
 				do_default ()
 			| FAnon cf when name = "iterator" && not is_assign ->

+ 3 - 2
std/python/_std/String.hx

@@ -35,13 +35,14 @@ package;
 import python.internal.StringImpl;
 import python.lib.Builtin;
 #end
+@:coreApi
 extern class String extends StringImpl {
 
 
 	/**
 		The number of characters in [this] String.
 	**/
-	var length(get,null) : Int;
+	var length(default,null) : Int;
 
 	private inline function get_length ():Int {
 		return python.lib.Builtin.len(this);
@@ -205,5 +206,5 @@ extern class String extends StringImpl {
 		//untyped __python__("String = __builtin__.str");
 	}
 
-    
+
 }