Nicolas Cannasse 15 éve
szülő
commit
cb00f534b1
5 módosított fájl, 14 hozzáadás és 9 törlés
  1. 1 1
      codegen.ml
  2. 3 1
      interp.ml
  3. 1 0
      typecore.ml
  4. 4 4
      typeload.ml
  5. 5 3
      typer.ml

+ 1 - 1
codegen.ml

@@ -367,7 +367,7 @@ let on_generate ctx t =
 			c.cl_ordered_statics <- f :: c.cl_ordered_statics;
 			c.cl_statics <- PMap.add f.cf_name f c.cl_statics;
 		end;
-		if not (Common.defined ctx.com "macro") then List.iter (fun f ->
+		if not ctx.in_macro then List.iter (fun f ->
 			match f.cf_kind with
 			| Method MethMacro -> 
 				c.cl_statics <- PMap.remove f.cf_name c.cl_statics;

+ 3 - 1
interp.ml

@@ -1667,7 +1667,9 @@ and base_op ctx op v1 v2 p =
 	| "*" ->
 		number_op ctx p op ( * ) ( *. ) "__mult" "__rmul" v1 v2
 	| "/" ->
-		number_op ctx p op (/) (/.) "__div" "__rdiv" v1 v2
+		(match v1, v2 with
+		| VInt i, VInt j -> VFloat ((float_of_int i) /. (float_of_int j))
+		| _ -> number_op ctx p op (/) (/.) "__div" "__rdiv" v1 v2)
 	| "%" ->
 		number_op ctx p op (fun x y -> x mod y) mod_float "__mod" "__rmod" v1 v2
 	| "&" ->

+ 1 - 0
typecore.ml

@@ -44,6 +44,7 @@ and typer = {
 	com : context;
 	mutable t : basic_types;
 	g : typer_globals;
+	mutable in_macro : bool;
 	(* per-module *)
 	current : module_def;
 	mutable local_types : module_type list;

+ 4 - 4
typeload.ml

@@ -634,8 +634,7 @@ let init_class ctx c p herits fields meta =
 	set_heritance ctx c herits p;
 	let core_api = has_meta ":core_api" meta in
 	let is_macro = has_meta ":macro" meta in
-	let in_macro = Common.defined ctx.com "macro" in
-	let fields, herits = if is_macro && not in_macro then begin
+	let fields, herits = if is_macro && not ctx.in_macro then begin
 		c.cl_extern <- true;
 		List.filter (function (FFun (_,_,_,acc,_,_),_) -> List.mem AStatic acc | _ -> false) fields, []
 	end else fields, herits in
@@ -739,7 +738,7 @@ let init_class ctx c p herits fields meta =
 			if is_macro && not stat then error "Only static methods can be macros" p;
 			let f = if not is_macro then
 				f
-			else if in_macro then
+			else if ctx.in_macro then
 				let texpr = CTPath { tpackage = ["haxe";"macro"]; tname = "Expr"; tparams = []; tsub = None } in
 				{
 					f_type = (match f.f_type with None -> Some texpr | t -> t);
@@ -1042,6 +1041,7 @@ let type_module ctx m tdecls loadp =
 		in_super_call = false;
 		in_constructor = false;
 		in_static = false;
+		in_macro = ctx.in_macro;
 		in_display = false;
 		in_loop = false;
 		opened = [];
@@ -1107,7 +1107,7 @@ let type_module ctx m tdecls loadp =
 			let index = ref 0 in
 			let rec loop = function
 				| (":build",(EConst (String s),p) :: el) :: _ ->
-					if Common.defined ctx.com "macro" then error "You cannot used :build inside a macro : make sure that your enum is not used in macro" p;
+					if ctx.in_macro then error "You cannot used :build inside a macro : make sure that your enum is not used in macro" p;
 					(match apply_macro ctx s el p with
 					| None -> error "Enum build failure" p
 					| Some (EArrayDecl el,_) | Some (EBlock el,_) ->

+ 5 - 3
typer.ml

@@ -44,8 +44,9 @@ type access_kind =
 	| AKUsing of texpr * texpr
 
 let mk_infos ctx p params =
+	let file = if ctx.in_macro then p.pfile else Filename.basename p.pfile in
 	(EObjectDecl (
-		("fileName" , (EConst (String (Filename.basename p.pfile)) , p)) ::
+		("fileName" , (EConst (String file) , p)) ::
 		("lineNumber" , (EConst (Int (string_of_int (Lexer.get_error_line p))),p)) ::
 		("className" , (EConst (String (s_type_path ctx.curclass.cl_path)),p)) ::
 		if ctx.curmethod = "" then
@@ -1528,7 +1529,7 @@ and type_expr ctx ?(need_val=true) (e,p) =
 			| _ -> TAnon { a_fields = use_methods; a_status = ref Closed }
 		) in
 		(match follow t with
-		| TMono _ | TDynamic _ when Common.defined ctx.com "macro" -> mk (TConst TNull) t p
+		| TMono _ | TDynamic _ when ctx.in_macro -> mk (TConst TNull) t p
 		| _ -> raise (Display t))
 	| EDisplayNew t ->
 		let t = Typeload.load_instance ctx t p true in
@@ -1873,7 +1874,7 @@ let type_macro ctx cpath f el p =
 		| None -> None
 		| Some v -> Some (try Interp.decode_expr v with Interp.Invalid_expr -> error "The macro didn't return a valid expression" p)
 	in
-	let e = (if Common.defined ctx.com "macro" then begin
+	let e = (if ctx.in_macro then begin
 		(*
 			this is super-tricky : we can't evaluate a macro inside a macro because we might trigger some cycles.
 			So instead, we generate a haxe.macro.Context.delayedCalled(i) expression that will only evaluate the
@@ -1940,6 +1941,7 @@ let rec create com =
 		in_loop = false;
 		in_super_call = false;
 		in_display = false;
+		in_macro = Common.defined com "macro";
 		ret = mk_mono();
 		locals = PMap.empty;
 		locals_map = PMap.empty;