Skip to content

Commit e4be2f9

Browse files
authored
Fix primitive string comparison on Chez (#792)
Found when debugging #561 -- string comparison was present on Chez, but it never worked as strings are compared with operations that look like `string<?`. See section 7.4 here https://www.scheme.com/csug8/objects.html :) I also added a tiny test to ensure that this doesn't confuse anybody else down the line.
1 parent 6c2faba commit e4be2f9

File tree

4 files changed

+88
-4
lines changed

4 files changed

+88
-4
lines changed

effekt/jvm/src/test/scala/effekt/StdlibTests.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,8 @@ class StdlibLLVMTests extends StdlibTests {
4646

4747
// Conditional jump or move depends on uninitialised value(s)
4848
examplesDir / "stdlib" / "io" / "filesystem" / "wordcount.effekt",
49+
50+
// String comparison using `<`, `<=`, `>`, `>=` is not implemented yet on LLVM
51+
examplesDir / "stdlib" / "string" / "compare.effekt",
4952
)
5053
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
false
2+
true
3+
false
4+
true
5+
false
6+
true
7+
false
8+
true
9+
10+
true
11+
true
12+
false
13+
false
14+
false
15+
false
16+
true
17+
true
18+
19+
true
20+
true
21+
false
22+
false
23+
false
24+
false
25+
true
26+
true
27+
28+
true
29+
true
30+
false
31+
false
32+
false
33+
false
34+
true
35+
true
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
def main() = {
2+
val empty = ""
3+
val a = "a"
4+
5+
println(empty < empty)
6+
println(empty <= empty)
7+
println(empty > empty)
8+
println(empty >= empty)
9+
println(a < a)
10+
println(a <= a)
11+
println(a > a)
12+
println(a >= a)
13+
println("")
14+
15+
val b = "b"
16+
17+
println(a < b)
18+
println(a <= b)
19+
println(a > b)
20+
println(a >= b)
21+
println(b < a)
22+
println(b <= a)
23+
println(b > a)
24+
println(b >= a)
25+
println("")
26+
27+
val ab = "ab"
28+
println(ab < b)
29+
println(ab <= b)
30+
println(ab > b)
31+
println(ab >= b)
32+
println(b < ab)
33+
println(b <= ab)
34+
println(b > ab)
35+
println(b >= ab)
36+
println("")
37+
38+
println(a < ab)
39+
println(a <= ab)
40+
println(a > ab)
41+
println(a >= ab)
42+
println(ab < a)
43+
println(ab <= a)
44+
println(ab > a)
45+
println(ab >= a)
46+
}

libraries/common/effekt.effekt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -572,19 +572,19 @@ extern pure def infixGte(x: Double, y: Double): Bool =
572572
// TODO do we really need those? if yes, move to string.effekt
573573
extern pure def infixLt(x: String, y: String): Bool =
574574
js "(${x} < ${y})"
575-
chez "(< ${x} ${y})"
575+
chez "(string<? ${x} ${y})"
576576

577577
extern pure def infixLte(x: String, y: String): Bool =
578578
js "(${x} <= ${y})"
579-
chez "(<= ${x} ${y})"
579+
chez "(string<=? ${x} ${y})"
580580

581581
extern pure def infixGt(x: String, y: String): Bool =
582582
js "(${x} > ${y})"
583-
chez "(> ${x} ${y})"
583+
chez "(string>? ${x} ${y})"
584584

585585
extern pure def infixGte(x: String, y: String): Bool =
586586
js "(${x} >= ${y})"
587-
chez "(>= ${x} ${y})"
587+
chez "(string>=? ${x} ${y})"
588588

589589

590590
// Boolean operations

0 commit comments

Comments
 (0)