Explorar o código

does not allow macro to print something while completion is running

Nicolas Cannasse %!s(int64=14) %!d(string=hai) anos
pai
achega
7d39ecf7bc
Modificáronse 2 ficheiros con 8 adicións e 1 borrados
  1. 5 1
      interp.ml
  2. 3 0
      typer.ml

+ 5 - 1
interp.ml

@@ -86,6 +86,7 @@ type locals = (string, value ref) PMap.t
 type extern_api = {
 type extern_api = {
 	pos : Ast.pos;
 	pos : Ast.pos;
 	get_type : string -> Type.t option;
 	get_type : string -> Type.t option;
+	print : string -> unit;
 	parse_string : string -> Ast.pos -> Ast.expr;
 	parse_string : string -> Ast.pos -> Ast.expr;
 	typeof : Ast.expr -> Type.t;
 	typeof : Ast.expr -> Type.t;
 	type_patch : string -> string -> bool -> string option -> unit;
 	type_patch : string -> string -> bool -> string option -> unit;
@@ -485,7 +486,10 @@ let builtins =
 		"hcount", Fun1 (fun h -> VInt (Hashtbl.length (vhash h)));
 		"hcount", Fun1 (fun h -> VInt (Hashtbl.length (vhash h)));
 		"hsize", Fun1 (fun h -> VInt (Hashtbl.length (vhash h)));
 		"hsize", Fun1 (fun h -> VInt (Hashtbl.length (vhash h)));
 	(* misc *)
 	(* misc *)
-		"print", FunVar (fun vl -> List.iter (fun v -> print_string ((get_ctx()).do_string v)) vl; VNull);
+		"print", FunVar (fun vl -> List.iter (fun v -> 
+			let ctx = get_ctx() in
+			ctx.curapi.print (ctx.do_string v)
+		) vl; VNull);
 		"throw", Fun1 (fun v -> exc v);
 		"throw", Fun1 (fun v -> exc v);
 		"rethrow", Fun1 (fun v -> exc v);
 		"rethrow", Fun1 (fun v -> exc v);
 		"istrue", Fun1 (fun v ->
 		"istrue", Fun1 (fun v ->

+ 3 - 0
typer.ml

@@ -1856,6 +1856,9 @@ let make_macro_api ctx p =
 			) in
 			) in
 			Hashtbl.replace h (f,s) v			
 			Hashtbl.replace h (f,s) v			
 		);
 		);
+		Interp.print = (fun s ->
+			if not !Common.display then print_string s
+		);
 	}
 	}
 
 
 let load_macro ctx cpath f p =
 let load_macro ctx cpath f p =