(macroDepth) and generativetestcase depth limit

This commit is contained in:
2021-08-08 11:42:24 -06:00
parent 91c264cfab
commit 4e0c2f5024
2 changed files with 37 additions and 26 deletions

View File

@@ -337,6 +337,7 @@ class Helpers {
}
// This is kind of a big deal:
interp.variables.set("eval", Helpers.runAtCompileTimeDynamic.bind(_, k));
interp.variables.set("macroDepth", () -> interps.length);
interps.push(interp);
} else {

View File

@@ -1,6 +1,7 @@
(defMacroVar maxInt 1000000000)
(defMacroVar maxStringLength 20)
(defMacroVar maxExps 4)
(defMacroVar maxDepth 15)
(defMacroFunction _macroList [func length]
(for _ (range length) (func)))
@@ -22,37 +23,46 @@
(defMacroFunction _randomFalsyExp []
((chooseRandom
(concat
[
->{`null}
->{`false}
->{`""}
->{`[]}
]
(if (< (macroDepth) maxDepth)
[
->{`(or ,@(_randomLengthMacroList _randomFalsyExp))}
->{`(and
,@(_randomLengthMacroList _randomUncertainExp)
,(_randomFalsyExp)
,@(_randomLengthMacroList _randomUncertainExp))}
])))
]
[])))))
(defMacro randomFalsyExp []
(printExp (_randomFalsyExp) "Falsy"))
(defMacroFunction _randomTruthyExp []
((chooseRandom
(concat
[
->{`true}
->(_randomLetterString)
->(_randomInt)
->(_randomFloat)
// These cause stack overflows because it's hard to implement a recursion limit at macro time
/*->{`[,@(_randomLengthMacroList _randomLetterString)]}
]
(if (< (macroDepth) maxDepth)
[
->{`[,@(_randomLengthMacroList _randomLetterString)]}
->{`[,@(_randomLengthMacroList _randomInt)]}
->{`[,@(_randomLengthMacroList _randomFloat)]}
->{`(and ,@(_randomLengthMacroList _randomTruthyExp))}
->{`(or
,@(_randomLengthMacroList _randomUncertainExp)
,(_randomTruthyExp)
,@(_randomLengthMacroList _randomUncertainExp))}*/
])))
,@(_randomLengthMacroList _randomUncertainExp))}
]
[])))))
(defMacro randomTruthyExp []
(printExp (_randomTruthyExp) "Truthy"))