kissCache use haxe compilation server

This commit is contained in:
2023-07-08 11:01:27 -06:00
parent 9e916a4823
commit 7f4f823271
3 changed files with 15 additions and 11 deletions

View File

@@ -175,6 +175,8 @@ class AsyncEmbeddedScript {
classFields = classFields.concat(Kiss.build(dslFile, k)); classFields = classFields.concat(Kiss.build(dslFile, k));
scriptFile = Path.join([loadingDirectory, scriptFile]); scriptFile = Path.join([loadingDirectory, scriptFile]);
Context.registerModuleDependency(Context.getLocalModule(), scriptFile);
k.fieldList = []; k.fieldList = [];
Kiss._try(() -> { Kiss._try(() -> {
#if profileKiss #if profileKiss

View File

@@ -63,6 +63,7 @@ class EmbeddedScript {
// As a side-effect, it also fills the KissState with the macros and reader macros that make the DSL syntax // As a side-effect, it also fills the KissState with the macros and reader macros that make the DSL syntax
classFields = classFields.concat(Kiss.build(dslFile, k)); classFields = classFields.concat(Kiss.build(dslFile, k));
scriptFile = Path.join([loadingDirectory, scriptFile]); scriptFile = Path.join([loadingDirectory, scriptFile]);
Context.registerModuleDependency(Context.getLocalModule(), scriptFile);
Kiss._try(() -> { Kiss._try(() -> {
#if profileKiss #if profileKiss

View File

@@ -377,6 +377,8 @@ class Kiss {
} else { } else {
Path.join([loadingDirectory, kissFile]); Path.join([loadingDirectory, kissFile]);
}; };
Context.registerModuleDependency(Context.getLocalModule(), fullPath);
var previousFile = k.file; var previousFile = k.file;
k.file = fullPath; k.file = fullPath;
@@ -450,9 +452,13 @@ class Kiss {
} }
static var macroUsed = false; static var macroUsed = false;
static var expCache:haxe.DynamicAccess<String> = null;
static var cacheFile = ".kissCache.json"; #if kissCache
static var cacheThreshold = 0.2; @:persistent
static var expCache:Map<String,Expr> = null;
static var cacheThreshold = 0.05;
#end
public static function readerExpToHaxeExpr(exp, k): Expr { public static function readerExpToHaxeExpr(exp, k): Expr {
return switch (macroExpandAndConvert(exp, k, false)) { return switch (macroExpandAndConvert(exp, k, false)) {
@@ -474,15 +480,11 @@ class Kiss {
var str = Reader.toString(exp.def); var str = Reader.toString(exp.def);
if (!macroExpandOnly) { if (!macroExpandOnly) {
if (expCache == null) { if (expCache == null) {
expCache = if (sys.FileSystem.exists(cacheFile)) { expCache = new Map();
haxe.Json.parse(File.getContent(cacheFile));
} else {
{};
}
} }
if (expCache.exists(str)) { if (expCache.exists(str)) {
return Right(Context.parse(expCache[str], Helpers.macroPos(exp))); return Right(expCache[str]);
} }
} }
#end #end
@@ -683,10 +685,9 @@ class Kiss {
if (!macroExpandOnly) { if (!macroExpandOnly) {
if (conversionTime > cacheThreshold && !k.stateChanged) { if (conversionTime > cacheThreshold && !k.stateChanged) {
expCache[str] = switch (expr) { expCache[str] = switch (expr) {
case Right(expr): expr.toString(); case Right(expr): expr;
default: throw "macroExpandAndConvert is broken"; default: throw "macroExpandAndConvert is broken";
} }
File.saveContent(cacheFile, haxe.Json.stringify(expCache));
} }
} }
#end #end