Let the ordering operators also work on strings

E.g. ‘"foo" < "bar"’ now works.
This commit is contained in:
Eelco Dolstra 2013-08-02 18:53:02 +02:00
parent 3d77b28eac
commit 8e74c0bfd1
3 changed files with 12 additions and 4 deletions

View file

@ -183,8 +183,8 @@ static void prim_genericClosure(EvalState & state, Value * * args, Value & v)
list<Value> res; list<Value> res;
set<Value, CompareValues> doneKeys; // !!! use Value *? set<Value, CompareValues> doneKeys; // !!! use Value *?
while (!workSet.empty()) { while (!workSet.empty()) {
Value * e = *(workSet.begin()); Value * e = *(workSet.begin());
workSet.pop_front(); workSet.pop_front();
state.forceAttrs(*e); state.forceAttrs(*e);
@ -1032,7 +1032,10 @@ static void prim_div(EvalState & state, Value * * args, Value & v)
static void prim_lessThan(EvalState & state, Value * * args, Value & v) static void prim_lessThan(EvalState & state, Value * * args, Value & v)
{ {
mkBool(v, state.forceInt(*args[0]) < state.forceInt(*args[1])); state.forceValue(*args[0]);
state.forceValue(*args[1]);
CompareValues comp;
mkBool(v, comp(*args[0], *args[1]));
} }

View file

@ -1 +1 @@
2185 2188

View file

@ -50,6 +50,11 @@ let {
(if 2 > 1 == 1 < 2 then 1 else err) (if 2 > 1 == 1 < 2 then 1 else err)
(if 1 + 2 * 3 >= 7 then 1 else err) (if 1 + 2 * 3 >= 7 then 1 else err)
(if 1 + 2 * 3 < 7 then err else 1) (if 1 + 2 * 3 < 7 then err else 1)
# Not integer, but so what.
(if "aa" < "ab" then 1 else err)
(if "aa" < "aa" then err else 1)
(if "foo" < "foobar" then 1 else err)
]; ];
} }