fix GenerativeTestCase
This commit is contained in:
@@ -412,7 +412,10 @@ class Helpers {
|
|||||||
for (name => value in k.macroVars) {
|
for (name => value in k.macroVars) {
|
||||||
interp.variables.set(name, value);
|
interp.variables.set(name, value);
|
||||||
}
|
}
|
||||||
|
var locals = interp.getLocals();
|
||||||
|
interp.setLocals(new Cloner().clone(locals));
|
||||||
var value = interp.publicExprReturn(compileTimeHScript(innerExp, k));
|
var value = interp.publicExprReturn(compileTimeHScript(innerExp, k));
|
||||||
|
interp.setLocals(locals);
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
throw CompileError.fromExp(exp, "compile-time evaluation returned null");
|
throw CompileError.fromExp(exp, "compile-time evaluation returned null");
|
||||||
}
|
}
|
||||||
@@ -452,6 +455,7 @@ class Helpers {
|
|||||||
// but it needs to be a ReaderExp for evalUnquotes()
|
// but it needs to be a ReaderExp for evalUnquotes()
|
||||||
static function compileTimeValueToReaderExp(e:Dynamic, source:ReaderExp):ReaderExp {
|
static function compileTimeValueToReaderExp(e:Dynamic, source:ReaderExp):ReaderExp {
|
||||||
// TODO if it's a string, return a StrExp. That way, symbolNameValue() won't be required
|
// TODO if it's a string, return a StrExp. That way, symbolNameValue() won't be required
|
||||||
|
// TODO if it's a number, return a Symbol(number.toString()).
|
||||||
return if (Std.isOfType(e, Array)) {
|
return if (Std.isOfType(e, Array)) {
|
||||||
var arr:Array<Dynamic> = e;
|
var arr:Array<Dynamic> = e;
|
||||||
var listExps = arr.map(compileTimeValueToReaderExp.bind(_, source));
|
var listExps = arr.map(compileTimeValueToReaderExp.bind(_, source));
|
||||||
|
@@ -118,8 +118,12 @@ class KissInterp extends Interp {
|
|||||||
return exprReturn(e);
|
return exprReturn(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// For debugging:
|
|
||||||
public function getLocals() {
|
public function getLocals() {
|
||||||
return locals;
|
return locals;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setLocals(l) {
|
||||||
|
locals = l;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,9 @@
|
|||||||
(defMacroVar maxInt 1000000000)
|
(defMacroVar maxInt 1000000000)
|
||||||
(defMacroVar maxStringLength 20)
|
(defMacroVar maxStringLength 20)
|
||||||
(defMacroVar maxExps 4)
|
(defMacroVar maxExps 4)
|
||||||
(defMacroVar maxDepth 15)
|
(defMacroVar maxDepth 14)
|
||||||
|
|
||||||
|
(defAlias &ident nd (+ 1 macroDepth))
|
||||||
|
|
||||||
(defMacroFunction _macroList [func length]
|
(defMacroFunction _macroList [func length]
|
||||||
(for _ (range length) (func)))
|
(for _ (range length) (func)))
|
||||||
@@ -13,7 +15,10 @@
|
|||||||
(_macroList func (+ 2 (random (- maxExps 2)))))
|
(_macroList func (+ 2 (random (- maxExps 2)))))
|
||||||
|
|
||||||
(defMacroFunction _randomLetterString []
|
(defMacroFunction _randomLetterString []
|
||||||
(ReaderExp.StrExp (apply + (for _ (range (+ 1 (random (- maxStringLength 1)))) (chooseRandom (.split "abcdefghijklmnopqrstuvwxyz" ""))))))
|
(ReaderExp.StrExp
|
||||||
|
(apply +
|
||||||
|
(for _ (range (+ 1 (random (- maxStringLength 1))))
|
||||||
|
(chooseRandom (.split "abcdefghijklmnopqrstuvwxyz" ""))))))
|
||||||
|
|
||||||
(defMacroFunction _randomInt []
|
(defMacroFunction _randomInt []
|
||||||
(symbol (Std.string (random maxInt))))
|
(symbol (Std.string (random maxInt))))
|
||||||
@@ -21,7 +26,7 @@
|
|||||||
(defMacroFunction _randomFloat []
|
(defMacroFunction _randomFloat []
|
||||||
(symbol (Std.string (+ (random maxInt) (/ 1 (random maxInt))))))
|
(symbol (Std.string (+ (random maxInt) (/ 1 (random maxInt))))))
|
||||||
|
|
||||||
(defMacroFunction _randomFalsyExp []
|
(defMacroFunction _randomFalsyExp [macroDepth]
|
||||||
((chooseRandom
|
((chooseRandom
|
||||||
(concat
|
(concat
|
||||||
[
|
[
|
||||||
@@ -30,19 +35,19 @@
|
|||||||
->{`""}
|
->{`""}
|
||||||
->{`[]}
|
->{`[]}
|
||||||
]
|
]
|
||||||
(if (< (macroDepth) maxDepth)
|
(if (< macroDepth maxDepth)
|
||||||
[
|
[
|
||||||
->{`(or ,@(_randomLengthMacroList _randomFalsyExp))}
|
->{`(or ,@(_randomLengthMacroList ->(_randomFalsyExp nd)))}
|
||||||
->{`(and
|
->{`(and
|
||||||
,@(_randomLengthMacroList _randomUncertainExp)
|
,@(_randomLengthMacroList ->(_randomUncertainExp nd))
|
||||||
,(_randomFalsyExp)
|
,(_randomFalsyExp nd)
|
||||||
,@(_randomLengthMacroList _randomUncertainExp))}
|
,@(_randomLengthMacroList ->(_randomUncertainExp nd)))}
|
||||||
]
|
]
|
||||||
[])))))
|
[])))))
|
||||||
(defMacro randomFalsyExp []
|
(defMacro randomFalsyExp []
|
||||||
(printExp (_randomFalsyExp) "Falsy"))
|
(printExp (_randomFalsyExp 0) "Falsy"))
|
||||||
|
|
||||||
(defMacroFunction _randomTruthyExp []
|
(defMacroFunction _randomTruthyExp [macroDepth]
|
||||||
((chooseRandom
|
((chooseRandom
|
||||||
(concat
|
(concat
|
||||||
[
|
[
|
||||||
@@ -51,26 +56,26 @@
|
|||||||
->(_randomInt)
|
->(_randomInt)
|
||||||
->(_randomFloat)
|
->(_randomFloat)
|
||||||
]
|
]
|
||||||
(if (< (macroDepth) maxDepth)
|
(if (< macroDepth maxDepth)
|
||||||
[
|
[
|
||||||
->{`[,@(_randomLengthMacroList _randomLetterString)]}
|
->{`[,@(_randomLengthMacroList _randomLetterString)]}
|
||||||
->{`[,@(_randomLengthMacroList _randomInt)]}
|
->{`[,@(_randomLengthMacroList _randomInt)]}
|
||||||
->{`[,@(_randomLengthMacroList _randomFloat)]}
|
->{`[,@(_randomLengthMacroList _randomFloat)]}
|
||||||
->{`(and ,@(_randomLengthMacroList _randomTruthyExp))}
|
->{`(and ,@(_randomLengthMacroList ->(_randomTruthyExp nd)))}
|
||||||
->{`(or
|
->{`(or
|
||||||
,@(_randomLengthMacroList _randomUncertainExp)
|
,@(_randomLengthMacroList ->(_randomUncertainExp nd))
|
||||||
,(_randomTruthyExp)
|
,(_randomTruthyExp nd)
|
||||||
,@(_randomLengthMacroList _randomUncertainExp))}
|
,@(_randomLengthMacroList ->(_randomUncertainExp nd)))}
|
||||||
]
|
]
|
||||||
[])))))
|
[])))))
|
||||||
(defMacro randomTruthyExp []
|
(defMacro randomTruthyExp []
|
||||||
(printExp (_randomTruthyExp) "Truthy"))
|
(printExp (_randomTruthyExp 0) "Truthy"))
|
||||||
|
|
||||||
(defMacroFunction _randomUncertainExp []
|
(defMacroFunction _randomUncertainExp [macroDepth]
|
||||||
((chooseRandom
|
((chooseRandom
|
||||||
[
|
[
|
||||||
->(_randomFalsyExp)
|
->(_randomFalsyExp macroDepth)
|
||||||
->(_randomTruthyExp)
|
->(_randomTruthyExp macroDepth)
|
||||||
])))
|
])))
|
||||||
|
|
||||||
(function _testTruthy []
|
(function _testTruthy []
|
||||||
|
Reference in New Issue
Block a user