Provide both eval-and-compile and eval-when-compile
This commit is contained in:
parent
80105d9731
commit
6eacf63b53
@ -1664,8 +1664,8 @@ class HyASTCompiler(object):
|
|||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
@builds("eval_when_compile")
|
@builds("eval_and_compile")
|
||||||
def compile_eval_when_compile(self, expression):
|
def compile_eval_and_compile(self, expression):
|
||||||
expression[0] = HySymbol("progn")
|
expression[0] = HySymbol("progn")
|
||||||
hy.importer.hy_eval(expression,
|
hy.importer.hy_eval(expression,
|
||||||
compile_time_ns(self.module_name),
|
compile_time_ns(self.module_name),
|
||||||
@ -1673,6 +1673,14 @@ class HyASTCompiler(object):
|
|||||||
expression.pop(0)
|
expression.pop(0)
|
||||||
return self._compile_branch(expression)
|
return self._compile_branch(expression)
|
||||||
|
|
||||||
|
@builds("eval_when_compile")
|
||||||
|
def compile_eval_when_compile(self, expression):
|
||||||
|
expression[0] = HySymbol("progn")
|
||||||
|
hy.importer.hy_eval(expression,
|
||||||
|
compile_time_ns(self.module_name),
|
||||||
|
self.module_name)
|
||||||
|
return Result()
|
||||||
|
|
||||||
@builds(HyInteger)
|
@builds(HyInteger)
|
||||||
def compile_integer(self, number):
|
def compile_integer(self, number):
|
||||||
return ast.Num(n=int(number),
|
return ast.Num(n=int(number),
|
||||||
|
@ -45,3 +45,12 @@
|
|||||||
(defn test-fn-calling-macro []
|
(defn test-fn-calling-macro []
|
||||||
"NATIVE: test macro calling a plain function"
|
"NATIVE: test macro calling a plain function"
|
||||||
(assert (= 3 (bar 1 2))))
|
(assert (= 3 (bar 1 2))))
|
||||||
|
|
||||||
|
; Macro that checks a variable defined at compile or load time
|
||||||
|
(setv phase "load")
|
||||||
|
(eval-when-compile
|
||||||
|
(setv phase "compile"))
|
||||||
|
(defmacro phase-when-compiling [] phase)
|
||||||
|
(assert (= phase "load"))
|
||||||
|
(assert (= (phase-when-compiling) "compile"))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user