diff --git a/kiss/src/kiss/Macros.hx b/kiss/src/kiss/Macros.hx index cc104cd6..4b2ef013 100644 --- a/kiss/src/kiss/Macros.hx +++ b/kiss/src/kiss/Macros.hx @@ -792,6 +792,13 @@ class Macros { // Maybe the NEW wildest code in Kiss? macros["#extern"] = (wholeExp:ReaderExp, exps:Array, k:KissState) -> { wholeExp.checkNumArgs(4, null, "(#extern [] )"); + var b = wholeExp.expBuilder(); + + // Skip all extern code generation if -D null-extern is provided to the compiler + if (Context.defined("null-extern")) { + return b.symbol("null"); + } + var bodyType = exps.shift(); var langExp = exps.shift(); @@ -834,9 +841,6 @@ class Macros { {}; } - var b = wholeExp.expBuilder(); - - // TODO generate tink_json writers and parsers for this var bindingList = bindingListExp.bindingList("#extern", true); var idx = 0; diff --git a/kiss/src/kiss/Main.hx b/kiss/src/kiss/Main.hx index 770ae7e2..a9e01902 100644 --- a/kiss/src/kiss/Main.hx +++ b/kiss/src/kiss/Main.hx @@ -37,7 +37,7 @@ class Main { // kiss implement [type] [fromLib] var _pwd = args.pop(); var theInterface = args.shift(); - var pArgs = ["build-scripts/common-args.hxml", "-lib", "kiss"]; + var pArgs = ["-D", "null-extern", "build-scripts/common-args.hxml", "-lib", "kiss"]; // pass --lib and the lib containing the interface as specified if (args.length > 0) { pArgs = pArgs.concat(["-lib", args.shift()]); @@ -175,10 +175,29 @@ class Main { #end } + // edge cases for this: + // TODO interfaces that extend other interfaces + // TODO generic interfaces + // TODO this could be useful for typedefs as well + // TODO merging a generated implementation with a Kiss file that already has some functions implemented static function implement(theInterface:String) { + // This runs in a subprocess whose stdout output can only be read all at once, + // so re-implement trace to write to a file: + haxe.Log.trace = (v, ?infos) -> { + File.saveContent("implementLog.txt", ""); + File.saveContent("implementLog.txt", File.getContent("implementLog.txt") + "\n" + Std.string(v)); + v; + } #if macro var type = Context.resolveType(Helpers.parseComplexType(theInterface), Context.currentPos()); - trace(type); + switch (type) { + case TInst(classTypeRef, params): + var classType = classTypeRef.get(); + var fields = classType.fields.get(); + trace(fields); + default: + throw 'Unexpected result from resolveType of $theInterface'; + } #end } }