ref: 5c11d9f0c97f8b466597c680e1178a61c676c489
parent: 0fce274714b986665ce6f5f97ac259fa3d7a7c6c
parent: b8129e8dd68fa9f1257f4e368cb70a08fb5813b9
author: Ori Bernstein <[email protected]>
date: Thu Jan 2 17:52:32 EST 2014
Merge branch 'master' of git+ssh://mimir.eigenstate.org/git/ori/mc
--- a/libstd/cmp.myr
+++ b/libstd/cmp.myr
@@ -13,6 +13,16 @@
const strncmp : (a : byte[:], b : byte[:], n : size -> order)
;;
+generic numcmp = {a, b
+ if a < b
+ -> `Before
+ elif a == b
+ -> `Equal
+ else
+ -> `After
+ ;;
+}
+
const strcmp = {a, b
var l
var i
@@ -20,10 +30,10 @@
l = min(a.len, b.len)
for i = 0; i < l; i++
- v = b[i] - a[i]
+ v = a[i] - b[i]
if v < 0
-> `Before
- elif v < 0
+ elif v > 0
-> `After
;;
;;
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -1239,7 +1239,7 @@
if (n->decl.isconst && !n->decl.init->expr.isconst)
fatal(n->line, "non-const initializer for \"%s\"", ctxstr(st, n));
} else {
- if (n->decl.isconst && !n->decl.isextern)
+ if ((n->decl.isconst || n->decl.isgeneric) && !n->decl.isextern)
fatal(n->line, "non-extern \"%s\" has no initializer", ctxstr(st, n));
}
}
--- a/test/data/stdsort-expected
+++ b/test/data/stdsort-expected
@@ -8,3 +8,23 @@
7
8
9
+1
+2
+3
+4
+5
+6
+7
+8
+9
+10
+C
+Cc
+a
+aa
+b
+cC
+d
+f
+fuckit
+go
--- a/test/stdsort.myr
+++ b/test/stdsort.myr
@@ -5,7 +5,7 @@
3, 5, 4, 9, 7, 2, 6, 0, 1, 8,
]
var b = [
- 3, 5, 4, 9, 7, 2, 6, 0, 1, 8,
+ 3, 4, 5, 1, 2, 6, 7, 8, 9, 10
]
var c = [
"a", "aa", "b", "C", "Cc", "cC", "d", "f", "fuckit", "go",