refactoring aoc

This commit is contained in:
2021-07-12 18:41:39 -06:00
parent dacdaccd8e
commit 1134b50caf
4 changed files with 14 additions and 2 deletions

View File

@@ -259,6 +259,7 @@ class Helpers {
ReaderExpDef: ReaderExpDef
},
Operand: {
toDynamic: Operand.toDynamic,
fromDynamic: Operand.fromDynamic
}
});

View File

@@ -20,6 +20,13 @@ class KissInterp extends Interp {
this.nullForUnknownVar = nullForUnknownVar;
variables.set("Prelude", Prelude);
variables.set("kiss", {
Operand: {
fromDynamic: Operand.fromDynamic,
toDynamic: Operand.toDynamic
}
});
trace(variables["kiss"]);
variables.set("Lambda", Lambda);
variables.set("Std", Std);
variables.set("Keep", ExtraElementHandling.Keep);

View File

@@ -192,7 +192,11 @@ class Macros {
conditionInterp.variables.set(flag, value);
}
try {
var conditionHScript = parser.parseString(Prelude.convertToHScript(conditionStr));
var hscriptStr = Prelude.convertToHScript(conditionStr);
#if test
Prelude.print(hscriptStr);
#end
var conditionHScript = parser.parseString(hscriptStr);
return if (Prelude.truthy(conditionInterp.execute(conditionHScript))) {
thenExp;
} else {

View File

@@ -25,7 +25,7 @@ abstract Operand(Either<String, Float>) from Either<String, Float> to Either<Str
// Doing this one implicitly just wasn't working in conjunction with Lambda.fold
/* @:from */
public inline static function fromDynamic(d:Dynamic):Operand {
public static function fromDynamic(d:Dynamic):Operand {
return switch (Type.typeof(d)) {
case TInt | TFloat: Right(0.0 + d);
// Treating true and false as operands can be useful for equality. In practice, no one should use them