Implement ifdef and ifndef
diff --git a/eval.go b/eval.go
index 6f092cc..4d4c07f 100644
--- a/eval.go
+++ b/eval.go
@@ -221,6 +221,26 @@
}
}
+func (ev *Evaluator) evalIf(ast *IfAST) {
+ var stmts []AST
+ switch ast.op {
+ case "ifdef", "ifndef":
+ value, _ := ev.getVar(ev.evalExpr(ast.lhs))
+ if (value != "") == (ast.op == "ifdef") {
+ stmts = ast.trueStmts
+ } else {
+ stmts = ast.falseStmts
+ }
+ case "ifeq", "ifneq":
+ panic("TODO")
+ default:
+ panic(fmt.Sprintf("unknown if statement: %q", ast.op))
+ }
+ for _, stmt := range stmts {
+ ev.eval(stmt)
+ }
+}
+
func (ev *Evaluator) eval(ast AST) {
ast.eval(ev)
}