diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2003-11-01T19·15+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2003-11-01T19·15+0000 |
commit | 16104446712acf7e381039199eaf39dfa0fcea35 (patch) | |
tree | f5f9126a42304fbaba7632773cafc5b1a5ab226f /src/fix-ng/eval.cc | |
parent | 1b4184ccbb01634792897d3412c489b989674567 (diff) |
* Conditions, string equality.
Diffstat (limited to 'src/fix-ng/eval.cc')
-rw-r--r-- | src/fix-ng/eval.cc | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/fix-ng/eval.cc b/src/fix-ng/eval.cc index 46bb1f94188d..c58a06dff8d9 100644 --- a/src/fix-ng/eval.cc +++ b/src/fix-ng/eval.cc @@ -106,6 +106,15 @@ Path evalPath(EvalState & state, Expr e) } +bool evalBool(EvalState & state, Expr e) +{ + e = evalExpr(state, e); + if (ATmatch(e, "True")) return true; + else if (ATmatch(e, "False")) return false; + else throw badTerm("expecting a boolean", e); +} + + Expr evalExpr2(EvalState & state, Expr e) { Expr e1, e2, e3, e4; @@ -165,6 +174,21 @@ Expr evalExpr2(EvalState & state, Expr e) if (ATmatch(e, "LetRec(<term>)", &e1)) return evalExpr(state, ATmake("Select(Rec(<term>), \"body\")", e1)); + /* Conditionals. */ + if (ATmatch(e, "If(<term>, <term>, <term>)", &e1, &e2, &e3)) { + if (evalBool(state, e1)) + return evalExpr(state, e2); + else + return evalExpr(state, e3); + } + + /* Equality. Just strings for now. */ + if (ATmatch(e, "OpEq(<term>, <term>)", &e1, &e2)) { + string s1 = evalString(state, e1); + string s2 = evalString(state, e2); + return s1 == s2 ? ATmake("True") : ATmake("False"); + } + /* Barf. */ throw badTerm("invalid expression", e); } |