diff --git a/src/kiss/AsyncEmbeddedScript.hx b/src/kiss/AsyncEmbeddedScript.hx index 599d5de..2550a02 100644 --- a/src/kiss/AsyncEmbeddedScript.hx +++ b/src/kiss/AsyncEmbeddedScript.hx @@ -172,23 +172,30 @@ class AsyncEmbeddedScript { scriptFile = Path.join([loadingDirectory, scriptFile]); k.fieldList = []; Kiss._try(() -> { - Reader.readAndProcess(Stream.fromFile(scriptFile), k, (nextExp) -> { - var exprString = Reader.toString(nextExp.def); - var expr = Kiss.readerExpToHaxeExpr(nextExp, k); + #if profileKiss + haxe.Timer.measure(() -> { + trace(scriptFile); + #end + Reader.readAndProcess(Stream.fromFile(scriptFile), k, (nextExp) -> { + var exprString = Reader.toString(nextExp.def); + var expr = Kiss.readerExpToHaxeExpr(nextExp, k); - #if debug - expr = macro { Prelude.print($v{exprString}); $expr; }; - #end - if (expr != null) { - commandList.push(macro function(self, cc) { - $expr; - }); - } + #if debug + expr = macro { Prelude.print($v{exprString}); $expr; }; + #end + if (expr != null) { + commandList.push(macro function(self, cc) { + $expr; + }); + } - // This return is essential for type unification of concat() and push() above... ugh. - return; + // This return is essential for type unification of concat() and push() above... ugh. + return; + }); + null; + #if profileKiss }); - null; + #end }); classFields = classFields.concat(k.fieldList); diff --git a/src/kiss/EmbeddedScript.hx b/src/kiss/EmbeddedScript.hx index 607edf0..a15dbb8 100644 --- a/src/kiss/EmbeddedScript.hx +++ b/src/kiss/EmbeddedScript.hx @@ -64,23 +64,30 @@ class EmbeddedScript { scriptFile = Path.join([loadingDirectory, scriptFile]); Kiss._try(() -> { - Reader.readAndProcess(Stream.fromFile(scriptFile), k, (nextExp) -> { - var expr = Kiss.readerExpToHaxeExpr(nextExp, k); + #if profileKiss + haxe.Timer.measure(() -> { + trace(scriptFile); + #end + Reader.readAndProcess(Stream.fromFile(scriptFile), k, (nextExp) -> { + var expr = Kiss.readerExpToHaxeExpr(nextExp, k); - if (expr != null) { - commandList.push(macro function(self) { - $expr; - }); - } + if (expr != null) { + commandList.push(macro function(self) { + $expr; + }); + } - // This return is essential for type unification of concat() and push() above... ugh. - return; - // TODO also allow label setting and multiple commands coming from the same expr? - // Multiple things could come from the same expr by returning begin, or a call to a function that does more stuff - // i.e. knot declarations need to end the previous knot, and BELOW that set a label for the new one, then increment the read count - // TODO test await + // This return is essential for type unification of concat() and push() above... ugh. + return; + // TODO also allow label setting and multiple commands coming from the same expr? + // Multiple things could come from the same expr by returning begin, or a call to a function that does more stuff + // i.e. knot declarations need to end the previous knot, and BELOW that set a label for the new one, then increment the read count + // TODO test await + }); + null; + #if profileKiss }); - null; + #end }); classFields.push({ diff --git a/src/kiss/Kiss.hx b/src/kiss/Kiss.hx index 669d41b..078c374 100644 --- a/src/kiss/Kiss.hx +++ b/src/kiss/Kiss.hx @@ -164,6 +164,7 @@ class Kiss { Build macro: add fields to a class from a corresponding .kiss file **/ public static function build(?kissFile:String, ?k:KissState, useClassFields = true):Array { + var classPath = Context.getPosInfos(Context.currentPos()).file; // (load... ) relative to the original file var loadingDirectory = Path.directory(classPath); @@ -173,42 +174,49 @@ class Kiss { //trace('kiss build $kissFile'); return _try(() -> { - if (k == null) - k = defaultKissState(); + #if profileKiss + haxe.Timer.measure(() -> { + trace(kissFile); + #end + if (k == null) + k = defaultKissState(); - if (useClassFields) { - k.fieldList = Context.getBuildFields(); - for (field in k.fieldList) { - k.fieldDict[field.name] = field; + if (useClassFields) { + k.fieldList = Context.getBuildFields(); + for (field in k.fieldList) { + k.fieldDict[field.name] = field; + } } - } - k.loadingDirectory = loadingDirectory; + k.loadingDirectory = loadingDirectory; - var topLevelBegin = load(kissFile, k); + var topLevelBegin = load(kissFile, k); - if (topLevelBegin != null) { - // If no main function is defined manually, Kiss expressions at the top of a file will be put in a main function. - // If a main function IS defined, this will result in an error - if (k.fieldDict.exists("main")) { - throw CompileError.fromExp(topLevelBegin, '$kissFile has expressions outside of field definitions, but already defines its own main function.'); + if (topLevelBegin != null) { + // If no main function is defined manually, Kiss expressions at the top of a file will be put in a main function. + // If a main function IS defined, this will result in an error + if (k.fieldDict.exists("main")) { + throw CompileError.fromExp(topLevelBegin, '$kissFile has expressions outside of field definitions, but already defines its own main function.'); + } + var b = topLevelBegin.expBuilder(); + // This doesn't need to be added to the fieldDict because all code generation is done + k.fieldList.push({ + name: "main", + access: [AStatic], + kind: FFun(Helpers.makeFunction( + b.symbol("main"), + false, + b.list([]), + [topLevelBegin], + k, + "function")), + pos: topLevelBegin.macroPos() + }); } - var b = topLevelBegin.expBuilder(); - // This doesn't need to be added to the fieldDict because all code generation is done - k.fieldList.push({ - name: "main", - access: [AStatic], - kind: FFun(Helpers.makeFunction( - b.symbol("main"), - false, - b.list([]), - [topLevelBegin], - k, - "function")), - pos: topLevelBegin.macroPos() - }); - } - k.fieldList; + k.fieldList; + #if profileKiss + }); + #end }); }