Selaa lähdekoodia

removed __construct__ and class.toString, __super__ and __interfaces__ are now optional

Nicolas Cannasse 19 vuotta sitten
vanhempi
commit
72314dfccb
3 muutettua tiedostoa jossa 25 lisäystä ja 40 poistoa
  1. 9 19
      genjs.ml
  2. 13 9
      genneko.ml
  3. 3 12
      genswf8.ml

+ 9 - 19
genjs.ml

@@ -195,7 +195,7 @@ and gen_expr ctx e =
 		spr ctx (field s);
 		print ctx " %s " (Ast.s_binop op);
 		gen_value_op ctx e2;
-	| TBinop (op,e1,e2) ->		
+	| TBinop (op,e1,e2) ->
 		gen_value_op ctx e1;
 		print ctx " %s " (Ast.s_binop op);
 		gen_value_op ctx e2;
@@ -584,24 +584,13 @@ let generate_class ctx c =
 	generate_package_create ctx c.cl_path;
 	print ctx "%s = " p;
 	(match c.cl_constructor with
-	| Some { cf_expr = Some e } ->
-		gen_value ctx (Transform.block_vars e);
-		newline ctx;
-		print ctx "%s.__construct__ = %s" p p;
-	| _ ->
-		print ctx "function() { }";
-		newline ctx;
-		print ctx "%s.__construct__ = null" p;
-	);
+	| Some { cf_expr = Some e } -> gen_value ctx (Transform.block_vars e)
+	| _ -> print ctx "function() { }");
 	newline ctx;
 	print ctx "%s.__name__ = [%s]" p (String.concat "," (List.map (fun s -> Printf.sprintf "\"%s\"" (Ast.s_escape s)) (fst c.cl_path @ [snd c.cl_path])));
 	newline ctx;
-	print ctx "%s.toString = $class_str" p;
-	newline ctx;
 	(match c.cl_super with
-	| None ->
-		print ctx "%s.__super__ = null" p;
-		newline ctx;
+	| None -> ()
 	| Some (csup,_) ->
 		let psup = s_path csup.cl_path in
 		print ctx "%s.__super__ = %s" p psup;
@@ -613,8 +602,11 @@ let generate_class ctx c =
 	PMap.iter (fun _ f -> gen_class_field ctx c f) c.cl_fields;
 	print ctx "%s.prototype.__class__ = %s" p p;
 	newline ctx;
-	print ctx "%s.__interfaces__ = [%s]" p (String.concat "," (List.map (fun (i,_) -> s_path i.cl_path) c.cl_implements));
-	newline ctx
+	match c.cl_implements with
+	| [] -> ()
+	| l ->
+		print ctx "%s.__interfaces__ = [%s]" p (String.concat "," (List.map (fun (i,_) -> s_path i.cl_path) l));
+		newline ctx
 
 let generate_enum ctx e =
 	let p = s_path e.e_path in
@@ -665,8 +657,6 @@ let generate file types hres =
 		handle_break = false;
 		id_counter = 0;
 	} in
-	print ctx "$class_str = function() { return this.__name__.join(\".\"); }";
-	newline ctx;
 	List.iter (generate_type ctx) types;
 	print ctx "js.Boot.__res = {}";
 	newline ctx;

+ 13 - 9
genneko.ml

@@ -452,15 +452,18 @@ let gen_class ctx c =
 		[]
 	) in
 	let fserialize = "__serialize" , ident p "@serialize" in
-	let interf = array p (List.map (fun (c,_) -> gen_type_path p c.cl_path) c.cl_implements) in
+	let others = (match c.cl_implements with
+		| [] -> []
+		| l -> ["__interfaces__",array p (List.map (fun (c,_) -> gen_type_path p c.cl_path) l)]
+	) @ (match c.cl_super with
+		| None -> []
+		| Some (c,_) -> ["__super__", gen_type_path p c.cl_path]
+	) in
 	let estat = (EBinop ("=",
 		stpath,
 		(EObject (
 			("prototype",clpath) ::
-			("__string", ident p "@class_to_string") ::
-			("__super__", match c.cl_super with None -> null p | Some (c,_) -> gen_type_path p c.cl_path) ::
-			("__interfaces__", interf) ::
-			PMap.fold (gen_method ctx p) c.cl_statics fnew
+			PMap.fold (gen_method ctx p) c.cl_statics (fnew @ others)
 		),p)
 	),p) in
 	let eclass = (EBinop ("=",
@@ -597,11 +600,13 @@ let gen_name acc t =
 		else
 			let p = pos c.cl_pos in
 			let name = fst c.cl_path @ [snd c.cl_path] in
-			let interf = field p (gen_type_path p c.cl_path) "__interfaces__" in
 			let arr = call p (field p (ident p "Array") "new1") [array p (List.map (fun n -> gen_constant c.cl_pos (TString n)) name); int p (List.length name)] in
 			(EBinop ("=",field p (gen_type_path p c.cl_path) "__name__",arr),p) ::
-			(EBinop ("=",interf, call p (field p (ident p "Array") "new1") [interf; int p (List.length c.cl_implements)]),p) ::
-			acc
+			(match c.cl_implements with
+			| [] -> acc
+			| l ->
+				let interf = field p (gen_type_path p c.cl_path) "__interfaces__" in
+				(EBinop ("=",interf, call p (field p (ident p "Array") "new1") [interf; int p (List.length l)]),p) :: acc)
 	| TTypeDecl _ ->
 		acc
 
@@ -615,7 +620,6 @@ let generate file types hres =
 	let header = ENeko (
 		"@classes = $new(null);" ^
 		"@enum_to_string = function() { return neko.Boot.__enum_str(this); };" ^
-		"@class_to_string = function() { return this.__name__.join(String.new(\".\")); };" ^
 		"@serialize = function() { return neko.Boot.__serialize(this); };"
 	) , { psource = "<header>"; pline = 1; } in
 	let packs = List.concat (List.map (gen_package h) types) in

+ 3 - 12
genswf8.ml

@@ -1175,15 +1175,9 @@ let gen_type_def ctx t =
 			f());
 		write ctx (ASetReg 0);
 		setvar ctx acc;
-		if !have_constr then begin
-			push ctx [VReg 0; VStr ("__construct__",false); VReg 0];
-			setvar ctx VarObj
-		end;
 		init_name ctx c.cl_path false;
 		(match c.cl_super with
-		| None ->
-			push ctx [VReg 0; VStr ("__super__",false); VNull];
-			setvar ctx VarObj
+		| None -> ()
 		| Some (csuper,_) ->
 			let path = (match csuper.cl_path with (["flash"],x) when csuper.cl_extern -> (["_global"],x) | p -> p) in
 			push ctx [VReg 0; VStr ("__super__",false)];
@@ -1211,10 +1205,7 @@ let gen_type_def ctx t =
 			end;
 		);
 		(match c.cl_implements with
-		| [] ->
-			push ctx [VReg 0; VStr ("__interfaces__",false); VInt 0];
-			write ctx AInitArray;
-			setvar ctx VarObj;
+		| [] -> ()
 		| l ->
 			let nimpl = List.length l in
 			push ctx [VReg 0; VStr ("__interfaces__",false)];
@@ -1396,7 +1387,7 @@ let generate file ver header infile types hres =
 	let base_id = ref 0x5000 in
 	let tag_code = (match codeclip with
 		| None -> List.map tag tag_code
-		| Some link -> 
+		| Some link ->
 			incr base_id;
 			[
 				tag (TClip {