Browse Source

forbidden packages

Nicolas Cannasse 19 years ago
parent
commit
1f6045ba0b
2 changed files with 11 additions and 3 deletions
  1. 3 2
      main.ml
  2. 8 1
      typer.ml

+ 3 - 2
main.ml

@@ -87,10 +87,12 @@ try
 		),"<path> : add a directory to find source files");
 		("-swf",Arg.String (fun file ->
 			check_targets();
+			Typer.forbidden_packages := ["js"; "neko"];
 			swf_out := Some file
 		),"<file> : compile code to SWF file");
 		("-neko",Arg.String (fun file ->
 			check_targets();
+			Typer.forbidden_packages := ["js"; "flash"];
 			neko_out := Some file
 		),"<file> : compile code to Neko Binary");
 		("-xml",Arg.String (fun file ->
@@ -116,13 +118,12 @@ try
 	| None -> ()
 	| Some _ ->
 		Hashtbl.add Parser.defines "flash" ();
-		Plugin.class_path := (base_path ^ "flash/") :: !Plugin.class_path;
 		Hashtbl.add Parser.defines ("flash" ^ string_of_int !swf_version) ());
 	(match !neko_out with
 	| None -> ()
 	| Some _ ->
 		Hashtbl.add Parser.defines "neko" ();
-		Plugin.class_path := (base_path ^ "neko/") :: !Plugin.class_path);
+	);
 	if !classes = [([],"Std")] then begin
 		Arg.usage args_spec usage
 	end else begin

+ 8 - 1
typer.ml

@@ -60,6 +60,8 @@ let error_msg = function
 		s_type ctx t1 ^ " should be " ^ s_type ctx t2
 	| Custom s -> s
 
+let forbidden_packages = ref []
+
 let error msg p = raise (Error (Custom msg,p))
 
 let load_ref : (context -> module_path -> pos -> module_def) ref = ref (fun _ _ _ -> assert false)
@@ -1187,7 +1189,12 @@ let load ctx m p =
 		Hashtbl.find ctx.modules m
 	with
 		Not_found ->
-			let file = (match m with [] , name -> name | l , name -> String.concat "/" l ^ "/" ^ name) ^ ".hx" in
+			let file = (match m with 
+				| [] , name -> name 
+				| x :: l , name -> 
+					if List.mem x (!forbidden_packages) then error ("You can't access the " ^ x ^ " package with current compilation flags") p;
+					String.concat "/" (x :: l) ^ "/" ^ name
+			) ^ ".hx" in
 			let file = (try Plugin.find_file file with Not_found -> raise (Error (Module_not_found m,p))) in
 			let ch = (try open_in file with _ -> error ("Could not open " ^ file) p) in
 			let pack , decls = (try Parser.parse (Lexing.from_channel ch) file with e -> close_in ch; raise e) in