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
|
||||
|
||||
@builds("eval_when_compile")
|
||||
def compile_eval_when_compile(self, expression):
|
||||
@builds("eval_and_compile")
|
||||
def compile_eval_and_compile(self, expression):
|
||||
expression[0] = HySymbol("progn")
|
||||
hy.importer.hy_eval(expression,
|
||||
compile_time_ns(self.module_name),
|
||||
@ -1673,6 +1673,14 @@ class HyASTCompiler(object):
|
||||
expression.pop(0)
|
||||
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)
|
||||
def compile_integer(self, number):
|
||||
return ast.Num(n=int(number),
|
||||
|
@ -45,3 +45,12 @@
|
||||
(defn test-fn-calling-macro []
|
||||
"NATIVE: test macro calling a plain function"
|
||||
(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…
x
Reference in New Issue
Block a user