Nicolas Cannasse преди 19 години
родител
ревизия
ef9fd339ae
променени са 3 файла, в които са добавени 78 реда и са изтрити 21 реда
  1. 42 0
      genjs.ml
  2. 3 0
      haxe.vcproj
  3. 33 21
      main.ml

+ 42 - 0
genjs.ml

@@ -0,0 +1,42 @@
+(*
+ *  Haxe Compiler
+ *  Copyright (c)2005 Nicolas Cannasse
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *)
+open Type
+
+type ctx = {
+	buf : Buffer.t;
+}
+
+let generate_class ctx c = 
+	()
+
+let generate_enum ctx e =
+	()
+
+let generate_type ctx = function
+	| TClassDecl c -> generate_class ctx c
+	| TEnumDecl e -> generate_enum ctx e
+
+let generate file types =
+	let ctx = {
+		buf = Buffer.create 16000;
+	} in
+	List.iter (generate_type ctx) types;
+	let ch = open_out file in
+	output_string ch (Buffer.contents ctx.buf);
+	close_out ch

+ 3 - 0
haxe.vcproj

@@ -54,6 +54,9 @@
 		<File
 			RelativePath=".\ast.ml">
 		</File>
+		<File
+			RelativePath=".\genjs.ml">
+		</File>
 		<File
 			RelativePath=".\genswf.ml">
 		</File>

+ 33 - 21
main.ml

@@ -18,6 +18,12 @@
  *)
 open Printf
 
+type target = 
+	| No 
+	| Js of string
+	| Swf of string
+	| Neko of string
+
 let prompt = ref false
 
 let normalize_path p =
@@ -77,9 +83,8 @@ try
 	let usage = "Haxe Compiler Beta 2 - (c)2005-2006 Motion-Twin\n Usage : haxe.exe [options] <class names...>\n Options :" in
 	let base_path = normalize_path (try Extc.executable_path() with _ -> "./") in
 	let classes = ref [([],"Std")] in
-	let swf_out = ref None in
+	let target = ref No in
 	let swf_in = ref None in
-	let neko_out = ref None in
 	let xml_out = ref None in
 	let main_class = ref None in
 	let swf_version = ref 8 in
@@ -91,24 +96,29 @@ try
 	Typer.forbidden_packages := ["js"; "neko"; "flash"];
 	Plugin.class_path := [base_path;base_path ^ "std/";"";"/"];
 	let check_targets() =
-		if !swf_out <> None || !neko_out <> None then failwith "Multiple targets";
+		if !target <> No then failwith "Multiple targets";
 	in
 	let args_spec = [
 		("-cp",Arg.String (fun path ->
 			Plugin.class_path := normalize_path path :: !Plugin.class_path
 		),"<path> : add a directory to find source files");
+		("-js",Arg.String (fun file ->
+			check_targets();
+			Typer.forbidden_packages := ["neko"; "flash"];
+			target := Js file
+		),"<file> : compile code to JavaScript file");
 		("-swf",Arg.String (fun file ->
 			check_targets();
 			Typer.forbidden_packages := ["js"; "neko"];
-			swf_out := Some file
-		),"<file> : compile code to SWF file");
+			target := Swf file
+		),"<file> : compile code to Flash SWF file");
 		("-swf-lib",Arg.String (fun file ->
 			swf_in := Some file
 		),"<file> : add the SWF library to the compiled SWF");
 		("-neko",Arg.String (fun file ->
 			check_targets();
 			Typer.forbidden_packages := ["js"; "flash"];
-			neko_out := Some file
+			target := Neko file
 		),"<file> : compile code to Neko Binary");
 		("-xml",Arg.String (fun file ->
 			xml_out := Some file
@@ -155,15 +165,16 @@ try
 		| _ -> classes := make_path cl :: !classes
 	in
 	Arg.parse_argv ~current argv args_spec args_callback usage;
-	(match !swf_out with
-	| None -> ()
-	| Some _ ->
+	(match !target with
+	| No ->
+		()
+	| Swf _ ->
 		Hashtbl.add Parser.defines "flash" ();
-		Hashtbl.add Parser.defines ("flash" ^ string_of_int !swf_version) ());
-	(match !neko_out with
-	| None -> ()
-	| Some _ ->
+		Hashtbl.add Parser.defines ("flash" ^ string_of_int !swf_version) ();
+	| Neko _ ->
 		Hashtbl.add Parser.defines "neko" ();
+	| Js _ ->
+		Hashtbl.add Parser.defines "js" ();
 	);
 	if !classes = [([],"Std")] then begin
 		Arg.usage args_spec usage
@@ -173,17 +184,18 @@ try
 		List.iter (fun cpath -> ignore(Typer.load ctx cpath Ast.null_pos)) (List.rev !classes);
 		Typer.finalize ctx;
 		let types = Typer.types ctx (!main_class) in
-		(match !swf_out with
-		| None -> ()
-		| Some file ->
+		(match !target with
+		| No -> ()
+		| Swf file ->
 			if !Plugin.verbose then print_endline ("Generating swf : " ^ file);
 			Genswf.generate file (!swf_version) (!swf_in) types
-		);
-		(match !neko_out with
-		| None -> ()
-		| Some file ->
+		| Neko file ->
 			if !Plugin.verbose then print_endline ("Generating neko : " ^ file);
-			Genneko.generate file types);
+			Genneko.generate file types
+		| Js file ->
+			if !Plugin.verbose then print_endline ("Generating js : " ^ file);
+			Genjs.generate file types
+		);
 		(match !xml_out with
 		| None -> ()
 		| Some file ->