Nicolas Cannasse пре 19 година
родитељ
комит
1b2d582ccd
4 измењених фајлова са 16 додато и 17 уклоњено
  1. 9 10
      main.ml
  2. 1 6
      parser.ml
  3. 5 0
      plugin.ml
  4. 1 1
      typer.ml

+ 9 - 10
main.ml

@@ -82,7 +82,7 @@ let make_path f =
 	in
 	in
 	loop cl
 	loop cl
 
 
-let base_defines = Hashtbl.copy Parser.defines
+let base_defines = !Plugin.defines
 
 
 let rec init argv argv_start =
 let rec init argv argv_start =
 try	
 try	
@@ -98,8 +98,7 @@ try
 	let current = ref argv_start in
 	let current = ref argv_start in
 	let next = ref (fun() -> ()) in
 	let next = ref (fun() -> ()) in
 	let hres = Hashtbl.create 0 in
 	let hres = Hashtbl.create 0 in
-	Hashtbl.clear Parser.defines;
-	Hashtbl.iter (Hashtbl.add Parser.defines) base_defines;
+	Plugin.defines := base_defines;
 	Plugin.verbose := false;
 	Plugin.verbose := false;
 	Typer.forbidden_packages := ["js"; "neko"; "flash"];
 	Typer.forbidden_packages := ["js"; "neko"; "flash"];
 	Plugin.class_path := [base_path ^ "std/";"";"/"];
 	Plugin.class_path := [base_path ^ "std/";"";"/"];
@@ -138,7 +137,7 @@ try
 			classes := cpath :: !classes
 			classes := cpath :: !classes
 		),"<class> : select startup class");
 		),"<class> : select startup class");
 		("-D",Arg.String (fun def ->
 		("-D",Arg.String (fun def ->
-			Hashtbl.add Parser.defines def ();
+			Plugin.define def;
 		),"<var> : define the macro variable");
 		),"<var> : define the macro variable");
 		("-fheader",Arg.String (fun h ->
 		("-fheader",Arg.String (fun h ->
 			try
 			try
@@ -196,14 +195,14 @@ try
 	| No ->
 	| No ->
 		()
 		()
 	| Swf _ ->
 	| Swf _ ->
-		Hashtbl.add Parser.defines "flash" ();
-		if Hashtbl.mem Parser.defines "flash6" then swf_version := 6
-		else if Hashtbl.mem Parser.defines "flash7" then swf_version := 7
-		else Hashtbl.add Parser.defines "flash8" ();
+		Plugin.define "flash";
+		if Plugin.defined "flash6" then swf_version := 6
+		else if Plugin.defined "flash7" then swf_version := 7
+		else Plugin.define "flash8";
 	| Neko _ ->
 	| Neko _ ->
-		Hashtbl.add Parser.defines "neko" ();
+		Plugin.define "neko";
 	| Js _ ->
 	| Js _ ->
-		Hashtbl.add Parser.defines "js" ();
+		Plugin.define "js";
 	);
 	);
 	if !classes = [([],"Std")] then begin
 	if !classes = [([],"Std")] then begin
 		Arg.usage args_spec usage
 		Arg.usage args_spec usage

+ 1 - 6
parser.ml

@@ -45,11 +45,6 @@ let last_token s =
 
 
 let serror() = raise (Stream.Error "")
 let serror() = raise (Stream.Error "")
 
 
-let defines =
-	let h = Hashtbl.create 0 in
-	Hashtbl.add h "true" ();
-	h
-
 let priority = function
 let priority = function
 	| OpAssign | OpAssignOp _ -> -4
 	| OpAssign | OpAssignOp _ -> -4
 	| OpBoolOr -> -3
 	| OpBoolOr -> -3
@@ -426,7 +421,7 @@ let parse code file =
 		match Lexer.token code with
 		match Lexer.token code with
 		| (Const (Ident s),p) ->
 		| (Const (Ident s),p) ->
 			if s = "error" then error Unimplemented p;
 			if s = "error" then error Unimplemented p;
-			if Hashtbl.mem defines s then
+			if Plugin.defined s then
 				mstack := p :: !mstack
 				mstack := p :: !mstack
 			else
 			else
 				skip_tokens true		
 				skip_tokens true		

+ 5 - 0
plugin.ml

@@ -21,6 +21,11 @@ let verbose = ref false
 
 
 let class_path = ref ([] : string list)
 let class_path = ref ([] : string list)
 
 
+let defines = ref (PMap.add "true" () PMap.empty)
+
+let defined v = PMap.mem v (!defines)
+let define v = defines := PMap.add v () (!defines)
+
 let find_file f =
 let find_file f =
 	let rec loop = function
 	let rec loop = function
 		| [] -> raise Not_found
 		| [] -> raise Not_found

+ 1 - 1
typer.ml

@@ -1258,7 +1258,7 @@ and type_expr ctx ?(need_val=true) (e,p) =
 		let e = type_expr ctx e in
 		let e = type_expr ctx e in
 		mk (TThrow e) (mk_mono()) p
 		mk (TThrow e) (mk_mono()) p
 	| ECall ((EConst (Ident "trace"),p),e :: el) ->
 	| ECall ((EConst (Ident "trace"),p),e :: el) ->
-		if Hashtbl.mem Parser.defines "notrace" then
+		if Plugin.defined "notrace" then
 			mk (TConst TNull) (t_void ctx) p
 			mk (TConst TNull) (t_void ctx) p
 		else
 		else
 		let params = (match el with [] -> [] | _ -> ["customParams",(EArrayDecl el , p)]) in
 		let params = (match el with [] -> [] | _ -> ["customParams",(EArrayDecl el , p)]) in