merge branch 'eval-param-types'
This commit is contained in:
commit
1297cce4e2
@ -723,13 +723,20 @@ class HyASTCompiler(object):
|
|||||||
def compile_eval(self, expr):
|
def compile_eval(self, expr):
|
||||||
expr.pop(0)
|
expr.pop(0)
|
||||||
|
|
||||||
|
if not isinstance(expr[0], (HyExpression, HySymbol)):
|
||||||
|
raise HyTypeError(expr, "expression expected as first argument")
|
||||||
|
|
||||||
elist = [HySymbol("hy_eval")] + [expr[0]]
|
elist = [HySymbol("hy_eval")] + [expr[0]]
|
||||||
if len(expr) >= 2:
|
if len(expr) >= 2:
|
||||||
|
if not isinstance(expr[1], (HyDict, HySymbol)):
|
||||||
|
raise HyTypeError(expr, "Globals must be a dictionary")
|
||||||
elist.append(expr[1])
|
elist.append(expr[1])
|
||||||
else:
|
else:
|
||||||
elist.append(HyExpression([HySymbol("locals")]))
|
elist.append(HyExpression([HySymbol("locals")]))
|
||||||
|
|
||||||
if len(expr) == 3:
|
if len(expr) == 3:
|
||||||
|
if not isinstance(expr[2], HyString):
|
||||||
|
raise HyTypeError(expr, "Module name must be a string")
|
||||||
elist.append(expr[2])
|
elist.append(expr[2])
|
||||||
else:
|
else:
|
||||||
elist.append(HyString(self.module_name))
|
elist.append(HyString(self.module_name))
|
||||||
|
@ -845,6 +845,19 @@
|
|||||||
(assert (= 27 (eval (+ (quote (*)) (* [(quote 3)] 3)))))
|
(assert (= 27 (eval (+ (quote (*)) (* [(quote 3)] 3)))))
|
||||||
(assert (= None (eval (quote (print ""))))))
|
(assert (= None (eval (quote (print ""))))))
|
||||||
|
|
||||||
|
|
||||||
|
(defmacro assert-throw [exc-type &rest body]
|
||||||
|
`(try
|
||||||
|
(do
|
||||||
|
(eval ~@body)
|
||||||
|
(assert False "we shouldn't have arrived here"))
|
||||||
|
(catch [e Exception]
|
||||||
|
(assert (instance? ~exc-type e)
|
||||||
|
(.format "Expected exception of type {}, got {}: {}"
|
||||||
|
(. ~exc-type --name--)
|
||||||
|
(. (type e) --name--)
|
||||||
|
(str e))))))
|
||||||
|
|
||||||
(defn test-eval-globals []
|
(defn test-eval-globals []
|
||||||
"NATIVE: test eval with explicit global dict"
|
"NATIVE: test eval with explicit global dict"
|
||||||
(assert (= 'bar (eval (quote foo) {'foo 'bar})))
|
(assert (= 'bar (eval (quote foo) {'foo 'bar})))
|
||||||
@ -860,6 +873,15 @@
|
|||||||
(catch [e Exception]
|
(catch [e Exception]
|
||||||
(assert (isinstance e NameError))))))
|
(assert (isinstance e NameError))))))
|
||||||
|
|
||||||
|
(defn test-eval-failure []
|
||||||
|
"NATIVE: test eval failure modes"
|
||||||
|
(import [hy.errors [HyTypeError]])
|
||||||
|
(assert-throw HyTypeError '(eval))
|
||||||
|
(assert-throw HyTypeError '(eval "snafu"))
|
||||||
|
(assert-throw HyTypeError '(eval 'false []))
|
||||||
|
(assert-throw HyTypeError '(eval 'false {} 1)))
|
||||||
|
|
||||||
|
|
||||||
(defn test-import-syntax []
|
(defn test-import-syntax []
|
||||||
"NATIVE: test the import syntax."
|
"NATIVE: test the import syntax."
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user