2
0
Эх сурвалжийг харах

[std] cleanup macro related conditionals

Neko and hl stopped running macros long ago
Rudy Ges 7 сар өмнө
parent
commit
ef2dad4bbf

+ 28 - 76
std/haxe/macro/Compiler.hx

@@ -51,14 +51,12 @@ class Compiler {
 		return macro $v{haxe.macro.Context.definedValue(key)};
 		return macro $v{haxe.macro.Context.definedValue(key)};
 	}
 	}
 
 
-	#if (neko || (macro && hl) || (macro && eval))
+	#if macro
 	static var ident = ~/^[A-Za-z_][A-Za-z0-9_]*$/;
 	static var ident = ~/^[A-Za-z_][A-Za-z0-9_]*$/;
 	static var path = ~/^[A-Za-z_][A-Za-z0-9_.]*$/;
 	static var path = ~/^[A-Za-z_][A-Za-z0-9_.]*$/;
 
 
 	public static function allowPackage(v:String) {
 	public static function allowPackage(v:String) {
-		#if (neko || eval)
 		load("allow_package", 1)(v);
 		load("allow_package", 1)(v);
-		#end
 	}
 	}
 
 
 	/**
 	/**
@@ -67,48 +65,30 @@ class Compiler {
 		Usage of this function outside of initialization macros is deprecated and may cause compilation server issues.
 		Usage of this function outside of initialization macros is deprecated and may cause compilation server issues.
 	**/
 	**/
 	public static function define(flag:String, ?value:String) {
 	public static function define(flag:String, ?value:String) {
-		#if (neko || eval)
 		Context.assertInitMacro();
 		Context.assertInitMacro();
 		load("define", 2)(flag, value);
 		load("define", 2)(flag, value);
-		#end
 	}
 	}
 
 
-	#if (!neko && !eval)
-	private static function addGlobalMetadataImpl(pathFilter:String, meta:String, recursive:Bool, toTypes:Bool, toFields:Bool) {}
-	#end
-
 	/**
 	/**
 		Add a class path where ".hx" source files or packages (sub-directories) can be found.
 		Add a class path where ".hx" source files or packages (sub-directories) can be found.
 
 
 		Usage of this function outside of initialization macros is deprecated and may cause compilation server issues.
 		Usage of this function outside of initialization macros is deprecated and may cause compilation server issues.
 	**/
 	**/
 	public static function addClassPath(path:String) {
 	public static function addClassPath(path:String) {
-		#if (neko || eval)
 		Context.assertInitMacro();
 		Context.assertInitMacro();
 		load("add_class_path", 1)(path);
 		load("add_class_path", 1)(path);
-		#end
 	}
 	}
 
 
 	public static function getOutput():String {
 	public static function getOutput():String {
-		#if (neko || eval)
 		return load("get_output", 0)();
 		return load("get_output", 0)();
-		#else
-		return null;
-		#end
 	}
 	}
 
 
 	public static function setOutput(fileOrDir:String) {
 	public static function setOutput(fileOrDir:String) {
-		#if (neko || eval)
 		load("set_output", 1)(fileOrDir);
 		load("set_output", 1)(fileOrDir);
-		#end
 	}
 	}
 
 
 	public static function getDisplayPos():Null<{file:String, pos:Int}> {
 	public static function getDisplayPos():Null<{file:String, pos:Int}> {
-		#if (neko || eval)
 		return load("get_display_pos", 0)();
 		return load("get_display_pos", 0)();
-		#else
-		return null;
-		#end
 	}
 	}
 
 
 	/**
 	/**
@@ -117,11 +97,7 @@ class Compiler {
 		Usage of this function outside a macro context returns `null`.
 		Usage of this function outside a macro context returns `null`.
 	**/
 	**/
 	public static function getConfiguration():Null<CompilerConfiguration> {
 	public static function getConfiguration():Null<CompilerConfiguration> {
-		#if (neko || eval)
 		return load("get_configuration", 0)();
 		return load("get_configuration", 0)();
-		#else
-		return null;
-		#end
 	}
 	}
 
 
 	/**
 	/**
@@ -130,9 +106,7 @@ class Compiler {
 		Usage of this function outside a macro context does nothing.
 		Usage of this function outside a macro context does nothing.
 	**/
 	**/
 	public static function setPlatformConfiguration(config:PlatformConfig):Void {
 	public static function setPlatformConfiguration(config:PlatformConfig):Void {
-		#if (neko || eval)
 		load("set_platform_configuration", 1)(config);
 		load("set_platform_configuration", 1)(config);
-		#end
 	}
 	}
 
 
 	/**
 	/**
@@ -141,10 +115,8 @@ class Compiler {
 		Usage of this function outside of initialization macros is deprecated and may cause compilation server issues.
 		Usage of this function outside of initialization macros is deprecated and may cause compilation server issues.
 	**/
 	**/
 	public static function addNativeLib(name:String) {
 	public static function addNativeLib(name:String) {
-		#if (neko || eval)
 		Context.assertInitMacro();
 		Context.assertInitMacro();
 		load("add_native_lib", 1)(name);
 		load("add_native_lib", 1)(name);
-		#end
 	}
 	}
 
 
 	/**
 	/**
@@ -367,11 +339,7 @@ class Compiler {
 		through `Context.getType`.
 		through `Context.getType`.
 	**/
 	**/
 	public static function addGlobalMetadata(pathFilter:String, meta:String, ?recursive:Bool = true, ?toTypes:Bool = true, ?toFields:Bool = false) {
 	public static function addGlobalMetadata(pathFilter:String, meta:String, ?recursive:Bool = true, ?toTypes:Bool = true, ?toFields:Bool = false) {
-		#if (neko || eval)
 		load("add_global_metadata_impl", 5)(pathFilter, meta, recursive, toTypes, toFields);
 		load("add_global_metadata_impl", 5)(pathFilter, meta, recursive, toTypes, toFields);
-		#else
-		addGlobalMetadataImpl(pathFilter, meta, recursive, toTypes, toFields);
-		#end
 	}
 	}
 
 
 	@:deprecated
 	@:deprecated
@@ -406,80 +374,39 @@ class Compiler {
 		Register a custom metadata for documentation and completion purposes
 		Register a custom metadata for documentation and completion purposes
 	**/
 	**/
 	public static function registerCustomMetadata(meta:MetadataDescription, ?source:String):Void {
 	public static function registerCustomMetadata(meta:MetadataDescription, ?source:String):Void {
-		#if (neko || eval)
 		load("register_metadata_impl", 2)(meta, source);
 		load("register_metadata_impl", 2)(meta, source);
-		#end
 	}
 	}
 
 
 	/**
 	/**
 		Register a custom define for documentation purposes
 		Register a custom define for documentation purposes
 	**/
 	**/
 	public static function registerCustomDefine(define:DefineDescription, ?source:String):Void {
 	public static function registerCustomDefine(define:DefineDescription, ?source:String):Void {
-		#if (neko || eval)
 		load("register_define_impl", 2)(define, source);
 		load("register_define_impl", 2)(define, source);
-		#end
 	}
 	}
 
 
 	/**
 	/**
 		Change the default JS output by using a custom generator callback
 		Change the default JS output by using a custom generator callback
 	**/
 	**/
 	public static function setCustomJSGenerator(callb:JSGenApi->Void) {
 	public static function setCustomJSGenerator(callb:JSGenApi->Void) {
-		#if (neko || eval)
 		load("set_custom_js_generator", 1)(callb);
 		load("set_custom_js_generator", 1)(callb);
-		#end
 	}
 	}
 
 
-	#if (neko || eval)
 	static inline function load(f, nargs):Dynamic {
 	static inline function load(f, nargs):Dynamic {
 		return @:privateAccess Context.load(f, nargs);
 		return @:privateAccess Context.load(f, nargs);
 	}
 	}
-	#end
 
 
 	/**
 	/**
 		Clears cached results of file lookups
 		Clears cached results of file lookups
 	**/
 	**/
 	public static function flushDiskCache() {
 	public static function flushDiskCache() {
-		#if (neko || eval)
 		load("flush_disk_cache", 0)();
 		load("flush_disk_cache", 0)();
-		#end
 	}
 	}
-	#end
-
-	#if (js || lua || macro)
-	/**
-		Embed a JavaScript or Lua file at compile time (can be called by `--macro` or within an `__init__` method).
-	**/
-	public static #if !macro macro #end function includeFile(file:String, position:IncludePosition = Top) {
-		return switch ((position : String).toLowerCase()) {
-			case Inline:
-				if (Context.getLocalModule() == "")
-					Context.error("Cannot use inline mode when includeFile is called by `--macro`", Context.currentPos());
-
-				var f = try sys.io.File.getContent(Context.resolvePath(file)) catch (e:Dynamic) Context.error(Std.string(e), Context.currentPos());
-				var p = Context.currentPos();
-				if (Context.defined("js")) {
-					macro @:pos(p) js.Syntax.plainCode($v{f});
-				} else {
-					macro @:pos(p) untyped __lua__($v{f});
-				}
-			case Top | Closure:
-				@:privateAccess Context.includeFile(file, position);
-				macro {};
-			case _:
-				Context.error("unknown includeFile position: " + position, Context.currentPos());
-		}
-	}
-	#end
 
 
 	/**
 	/**
 		Gets the current hxb writer configuration, if any.
 		Gets the current hxb writer configuration, if any.
 	**/
 	**/
 	static public function getHxbWriterConfiguration():Null<WriterConfig> {
 	static public function getHxbWriterConfiguration():Null<WriterConfig> {
-		#if macro
 		return load("get_hxb_writer_config", 0)();
 		return load("get_hxb_writer_config", 0)();
-		#else
-		return null;
-		#end
 	}
 	}
 
 
 	/**
 	/**
@@ -500,10 +427,35 @@ class Compiler {
 		@see haxe.hxb.WriterConfig
 		@see haxe.hxb.WriterConfig
 	**/
 	**/
 	static public function setHxbWriterConfiguration(config:Null<WriterConfig>) {
 	static public function setHxbWriterConfiguration(config:Null<WriterConfig>) {
-		#if macro
 		load("set_hxb_writer_config", 1)(config);
 		load("set_hxb_writer_config", 1)(config);
-		#end
 	}
 	}
+	#end
+
+	#if (js || lua || macro)
+	/**
+		Embed a JavaScript or Lua file at compile time (can be called by `--macro` or within an `__init__` method).
+	**/
+	public static #if !macro macro #end function includeFile(file:String, position:IncludePosition = Top) {
+		return switch ((position : String).toLowerCase()) {
+			case Inline:
+				if (Context.getLocalModule() == "")
+					Context.error("Cannot use inline mode when includeFile is called by `--macro`", Context.currentPos());
+
+				var f = try sys.io.File.getContent(Context.resolvePath(file)) catch (e:Dynamic) Context.error(Std.string(e), Context.currentPos());
+				var p = Context.currentPos();
+				if (Context.defined("js")) {
+					macro @:pos(p) js.Syntax.plainCode($v{f});
+				} else {
+					macro @:pos(p) untyped __lua__($v{f});
+				}
+			case Top | Closure:
+				@:privateAccess Context.includeFile(file, position);
+				macro {};
+			case _:
+				Context.error("unknown includeFile position: " + position, Context.currentPos());
+		}
+	}
+	#end
 }
 }
 
 
 enum abstract IncludePosition(String) from String to String {
 enum abstract IncludePosition(String) from String to String {

+ 1 - 7
std/haxe/macro/Context.hx

@@ -42,7 +42,7 @@ enum Message {
 	- `haxe.macro.TypeTools`
 	- `haxe.macro.TypeTools`
 **/
 **/
 class Context {
 class Context {
-	#if (neko || eval || display)
+	#if eval
 	/**
 	/**
 		Displays a compilation error `msg` at the given `Position` `pos`
 		Displays a compilation error `msg` at the given `Position` `pos`
 		and aborts the current macro call.
 		and aborts the current macro call.
@@ -871,13 +871,7 @@ class Context {
 	@:allow(haxe.macro.TypedExprTools)
 	@:allow(haxe.macro.TypedExprTools)
 	@:allow(haxe.macro.PositionTools)
 	@:allow(haxe.macro.PositionTools)
 	static function load(f:String, nargs:Int):Dynamic {
 	static function load(f:String, nargs:Int):Dynamic {
-		#if neko
-		return neko.Lib.load("macro", f, nargs);
-		#elseif eval
 		return eval.vm.Context.callMacroApi(f);
 		return eval.vm.Context.callMacroApi(f);
-		#else
-		return Reflect.makeVarArgs(function(_) return throw "Can't be called outside of macro");
-		#end
 	}
 	}
 
 
 	private static function includeFile(file:String, position:String) {
 	private static function includeFile(file:String, position:String) {

+ 0 - 2
std/haxe/macro/MacroStringTools.hx

@@ -37,9 +37,7 @@ class MacroStringTools {
 		elements.
 		elements.
 	**/
 	**/
 	static public function formatString(s:String, pos:Position):Expr {
 	static public function formatString(s:String, pos:Position):Expr {
-		#if (neko || eval)
 		return Context.load("format_string", 2)(s, pos);
 		return Context.load("format_string", 2)(s, pos);
-		#end
 	}
 	}
 
 
 	/**
 	/**

+ 0 - 22
std/haxe/macro/TypeTools.hx

@@ -258,19 +258,9 @@ class TypeTools {
 			throw 'Incompatible arguments: ${typeParameters.length} type parameters and ${concreteTypes.length} concrete types';
 			throw 'Incompatible arguments: ${typeParameters.length} type parameters and ${concreteTypes.length} concrete types';
 		else if (typeParameters.length == 0)
 		else if (typeParameters.length == 0)
 			return t;
 			return t;
-		#if (neko || eval)
 		return Context.load("apply_params", 3)(typeParameters, concreteTypes, t);
 		return Context.load("apply_params", 3)(typeParameters, concreteTypes, t);
-		#else
-		return applyParams(typeParameters, concreteTypes, t);
-		#end
 	}
 	}
 
 
-	#if !neko
-	private static function applyParams(typeParameters:Array<TypeParameter>, concreteTypes:Array<Type>, t:Type):Type {
-		return null;
-	}
-	#end
-
 	/**
 	/**
 		Transforms `t` by calling `f` on each of its subtypes.
 		Transforms `t` by calling `f` on each of its subtypes.
 
 
@@ -359,11 +349,7 @@ class TypeTools {
 		Converts type `t` to a human-readable String representation.
 		Converts type `t` to a human-readable String representation.
 	**/
 	**/
 	static public function toString(t:Type):String {
 	static public function toString(t:Type):String {
-		#if (neko || eval)
 		return Context.load("s_type", 1)(t);
 		return Context.load("s_type", 1)(t);
-		#else
-		return null;
-		#end
 	}
 	}
 
 
 	/**
 	/**
@@ -377,22 +363,14 @@ class TypeTools {
 		Converts type `t` to `haxe.macro.Type.ModuleType`.
 		Converts type `t` to `haxe.macro.Type.ModuleType`.
 	**/
 	**/
 	static public function toModuleType(t:Type):ModuleType {
 	static public function toModuleType(t:Type):ModuleType {
-		#if (neko || eval)
 		return Context.load("type_to_module_type", 1)(t);
 		return Context.load("type_to_module_type", 1)(t);
-		#else
-		return null;
-		#end
 	}
 	}
 
 
 	/**
 	/**
 		Creates a type from the `haxe.macro.Type.ModuleType` argument.
 		Creates a type from the `haxe.macro.Type.ModuleType` argument.
 	**/
 	**/
 	static public function fromModuleType(mt:ModuleType):Type {
 	static public function fromModuleType(mt:ModuleType):Type {
-		#if (neko || eval)
 		return Context.load("module_type_to_type", 1)(mt);
 		return Context.load("module_type_to_type", 1)(mt);
-		#else
-		return null;
-		#end
 	}
 	}
 
 
 	/**
 	/**