-D profileKiss to see each file's build() time

This commit is contained in:
2022-01-07 18:51:44 -07:00
parent d5e948c952
commit af293c142d
3 changed files with 80 additions and 58 deletions

View File

@@ -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);

View File

@@ -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({

View File

@@ -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<Field> {
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
});
}