瀏覽代碼

[python] Remove extern for python object for now, get __dict__ using Internal.

Dan Korostelev 11 年之前
父節點
當前提交
e74d8003c7
共有 4 個文件被更改,包括 15 次插入20 次删除
  1. 0 9
      std/python/Boot.hx
  2. 9 3
      std/python/internal/AnonObject.hx
  3. 6 0
      std/python/internal/Internal.hx
  4. 0 8
      std/python/lib/Object.hx

+ 0 - 9
std/python/Boot.hx

@@ -92,15 +92,6 @@ private class ClassRegistry extends python.lib.Dict<String, HxClassBase> {
     }
 }
 
-@:keep
-@:nativeGen
-@:native("_hx_AnonObject")
-class AnonObject extends python.lib.Object {
-	public function new(fields) {
-		this.__dict__ = fields;
-	}
-}
-
 @:preCode("
 _hx_classes = _hx_ClassRegistry()
 ")

+ 9 - 3
std/python/internal/AnonObject.hx

@@ -1,7 +1,13 @@
 
 package python.internal;
 
-@:native("_hx_AnonObject")
-extern class AnonObject {
+import python.Syntax;
 
-}
+@:keep
+@:nativeGen
+@:native("_hx_AnonObject")
+class AnonObject {
+    public function new(fields) {
+        Syntax.assign(Internal.fieldDict(this), fields);
+    }
+}

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

@@ -24,6 +24,8 @@ class Internal {
 
 	static var _classes = _prefix + "classes";
 
+	static var _dict = "__dict__";
+
 	static function _getPrefixed (x:Expr):Expr {
 		return switch (x.expr) {
 			case EConst(CString(x)): macro @:pos(Context.currentPos()) $v{_prefix + x};
@@ -191,6 +193,10 @@ class Internal {
 		return fieldWithPos(o, _constructs);
 	}
 
+	macro public static function fieldDict (o:Expr):Expr {
+		return fieldWithPos(o, _dict);
+	}
+
 	macro public static function fieldEmptyInit (o:Expr):Expr {
 		return fieldWithPos(o, _emptyInit);
 	}

+ 0 - 8
std/python/lib/Object.hx

@@ -1,8 +0,0 @@
-package python.lib;
-
-import python.lib.Dict;
-
-@:native("object")
-extern class Object {
-	public var __dict__:Dict<String, Dynamic>;
-}