Skip to content

Instantly share code, notes, and snippets.

@nadako
Created August 30, 2015 23:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nadako/87bd48d98e70805ef8cc to your computer and use it in GitHub Desktop.
Save nadako/87bd48d98e70805ef8cc to your computer and use it in GitHub Desktop.
class Main {
static function main() {
var s = new Signature<Int->Void>();
}
}
// Generated by Haxe
(function () { "use strict";
var Main = function() { };
Main.main = function() {
var s = "Int -> Void";
};
Main.main();
})();
#if macro
import haxe.macro.Context;
import haxe.macro.Expr;
import haxe.macro.Type;
using haxe.macro.Tools;
#end
#if !macro
@:genericBuild(Signature.build())
#end
@:dce
class Signature<T> {
#if macro
static function build():ComplexType {
var typeString = switch (Context.getLocalType()) {
case TInst(_, [type]): type.toString();
default:
throw false;
}
var pos = Context.currentPos();
var name = "Signature$" + typeString;
var ctor = {
pos: pos,
name: "new",
kind: FFun({
args: [],
ret: null,
expr: macro this = $v{typeString}
}),
access: [APublic, AInline],
};
Context.defineType({
pos: pos,
pack: [],
name: name,
kind: TDAbstract(macro : String, null, [macro : String]),
fields: [ctor],
meta: [{name: ":dce", pos: pos}]
});
return TPath({pack: [], name: name});
}
#end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment