<commit_before>package lime.app;


#if macro
import haxe.macro.Context;
import haxe.macro.Expr;
import haxe.macro.Type;
using haxe.macro.Tools;
#end

#if !macro
@:genericBuild(lime.app.Event.build())
#end


class Event<T> {
	
	
	@:noCompletion @:dox(hide) public var listeners:Array<T>;
	@:noCompletion @:dox(hide) public var repeat:Array<Bool>;
	
	private var priorities:Array<Int>;
	
	
	public function new () {
		
		#if !macro
		listeners = new Array ();
		priorities = new Array<Int> ();
		repeat = new Array<Bool> ();
		#end
		
	}
	
	
	public function add (listener:T, once:Bool = false, priority:Int = 0):Void {
		
		#if !macro
		for (i in 0...priorities.length) {
			
			if (priority > priorities[i]) {
				
				listeners.insert (i, cast listener);
				priorities.insert (i, priority);
				repeat.insert (i, !once);
				return;
				
			}
			
		}
		
		listeners.push (cast listener);
		priorities.push (priority);
		repeat.push (!once);
		#end
		
	}
	
	
	#if macro
	private static function build () {
		
		var typeArgs;
		var typeResult;
		
		switch (Context.getLocalType ()) {
			
			case TInst (_, [ TFun (args, result) ]):
				
				typeArgs = args;
				typeResult = result;
				
			default:
				
				throw false;
			
		}
		
		var typeParam = TFun (typeArgs, typeResult);
		var typeString = "";
		
		if (typeArgs.length == 0) {
			
			typeString = "Void->";
			
		} else {
			
			for (arg in typeArgs) {
				
				typeString += arg.t.toString () + "->";
				
			}
			
		}
		
		typeString += typeResult.toString ();
		
		var name = "Event$" + StringTools.replace (StringTools.replace (typeString, ".", "_"), "->", "__");
		
		try {
			
			Context.getType ("lime.app." + name);
			
		} catch (e:Dynamic) {
			
			var pos = Context.currentPos ();
			var fields = Context.getBuildFields ();
			
			var args:Array<FunctionArg> = [];
			var argName, argNames = [];
			
			for (i in 0...typeArgs.length) {
				
				if (i == 0) {
					
					argName = "a";
					
				} else {
					
					argName = "a" + i;
					
				}
				
				argNames.push (Context.parse (argName, pos));
				args.push ({ name: argName, type: typeArgs[i].t.toComplexType () });
				
			}
			
			var dispatch = macro {
				
				var listeners = this.listeners;
				var repeat = this.repeat;
				var i = 0;
				
				while (i < listeners.length) {
					
					listeners[i] ($a{argNames});
					
					if (!repeat[i]) {
						
						this.remove (cast listeners[i]);
						
					} else {
						
						i++;
						
					}
					
				}
				
			}
			
			for (field in fields) {
				
				if (field.name == "listeners") {
					
					fields.remove (field);
					break;
					
				}
				
			}
			
			fields.push ( { name: "listeners", access: [ APublic ], kind: FVar (TPath ({ pack: [], name: "Array", params: [ TPType (typeParam.toComplexType ()) ] })), pos: pos } );
			fields.push ( { name: "dispatch", access: [ APublic ], kind: FFun ( { args: args, expr: dispatch, params: [], ret: macro :Void } ), pos: pos } );
			
			Context.defineType ({
				pos: pos,
				pack: [ "lime", "app" ],
				name: name,
				kind: TDClass (),
				fields: fields,
				params: [ { name: "T" } ],
				meta: [ ]
			});
			
		}
		
		return TPath ( { pack: [ "lime", "app" ], name: name, params: [ TPType (typeParam.toComplexType ()) ] } ).toType ();
		
	}<commit_msg>Compile fix<commit_after>package lime.app;


#if macro
import haxe.macro.Context;
import haxe.macro.Expr;
import haxe.macro.Type;
using haxe.macro.Tools;
#end

#if !macro
@:genericBuild(lime.app.Event.build())
#end


class Event<T> {
	
	
	#if macro
	private static var lastID = 0;
	private static var typeIDs = new Map<String, Int> ();
	#end
	
	@:noCompletion @:dox(hide) public var listeners:Array<T>;
	@:noCompletion @:dox(hide) public var repeat:Array<Bool>;
	
	private var priorities:Array<Int>;
	
	
	public function new () {
		
		#if !macro
		listeners = new Array ();
		priorities = new Array<Int> ();
		repeat = new Array<Bool> ();
		#end
		
	}
	
	
	public function add (listener:T, once:Bool = false, priority:Int = 0):Void {
		
		#if !macro
		for (i in 0...priorities.length) {
			
			if (priority > priorities[i]) {
				
				listeners.insert (i, cast listener);
				priorities.insert (i, priority);
				repeat.insert (i, !once);
				return;
				
			}
			
		}
		
		listeners.push (cast listener);
		priorities.push (priority);
		repeat.push (!once);
		#end
		
	}
	
	
	#if macro
	private static function build () {
		
		var typeArgs;
		var typeResult;
		
		switch (Context.getLocalType ()) {
			
			case TInst (_, [ TFun (args, result) ]):
				
				typeArgs = args;
				typeResult = result;
				
			default:
				
				throw false;
			
		}
		
		var typeParam = TFun (typeArgs, typeResult);
		var typeString = "";
		
		if (typeArgs.length == 0) {
			
			typeString = "Void->";
			
		} else {
			
			for (arg in typeArgs) {
				
				typeString += arg.t.toString () + "->";
				
			}
			
		}
		
		typeString += typeResult.toString ();
		
		var id, name;
		
		if (typeIDs.exists (typeString)) {
			
			id = typeIDs.get (typeString);
			name = "Event$" + id;
			
		} else {
			
			id = lastID++;
			name = "Event$" + id;
		
			var pos = Context.currentPos ();
			var fields = Context.getBuildFields ();
			
			var args:Array<FunctionArg> = [];
			var argName, argNames = [];
			
			for (i in 0...typeArgs.length) {
				
				if (i == 0) {
					
					argName = "a";
					
				} else {
					
					argName = "a" + i;
					
				}
				
				argNames.push (Context.parse (argName, pos));
				args.push ({ name: argName, type: typeArgs[i].t.toComplexType () });
				
			}
			
			var dispatch = macro {
				
				var listeners = this.listeners;
				var repeat = this.repeat;
				var i = 0;
				
				while (i < listeners.length) {
					
					listeners[i] ($a{argNames});
					
					if (!repeat[i]) {
						
						this.remove (cast listeners[i]);
						
					} else {
						
						i++;
						
					}
					
				}
				
			}
			
			for (field in fields) {
				
				if (field.name == "listeners") {
					
					fields.remove (field);
					break;
					
				}
				
			}
			
			fields.push ( { name: "listeners", access: [ APublic ], kind: FVar (TPath ({ pack: [], name: "Array", params: [ TPType (typeParam.toComplexType ()) ] })), pos: pos } );
			fields.push ( { name: "dispatch", access: [ APublic ], kind: FFun ( { args: args, expr: dispatch, params: [], ret: macro :Void } ), pos: pos } );
			
			Context.defineType ({
				pos: pos,
				pack: [ "lime", "app" ],
				name: name,
				kind: TDClass (),
				fields: fields,
				params: [ { name: "T" } ],
				meta: [ ]
			});
			
			typeIDs.set (typeString, id);
			
		}
		
		return TPath ( { pack: [ "lime", "app" ], name: name, params: [ TPType (typeParam.toComplexType ()) ] } ).toType ();
		
	}
{'fraction_non_alphanumeric': 0.15657992565055762, 'fraction_numerical': 0.001933085501858736, 'mean_word_length': 2.1327433628318584, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7345407', 'n_tokens_mistral': 3180, 'n_tokens_neox': 2255, 'n_words': 559}