shithub: mc

Download patch

ref: 948799fdb2b9120a1b64f48e8f3fd33193632e96
parent: d8c459cc126c7175b799c368612f9ae33c95dc91
parent: efb1de08fbc7c6d5ee8966362549c95bca536067
author: Ori Bernstein <[email protected]>
date: Thu Apr 24 07:44:41 EDT 2014

Merge branch 'master' of git+ssh://git.eigenstate.org/git/ori/mc

Conflicts:
	parse/infer.c
	parse/use.c

--- a/libstd/slcp.myr
+++ b/libstd/slcp.myr
@@ -1,16 +1,34 @@
 use "die.use"
+use "types.use"
 
 pkg std =
 	generic slcp : (a : @a[:], b : @a[:] -> void)
 ;;
 
-generic slcp = {a, b
+generic slcp = {a : @a[:], b : @a[:]
 	var i
+	var addr_a, addr_b
 
 	assert(a.len == b.len, "arguments to slcp() must be of equal length")
 
-	for i = 0; i < a.len; i++
-		a[i] = b[i]
+	addr_a = a castto(@a#) castto(intptr)
+	addr_b = b castto(@a#) castto(intptr)
+	if forwardcopy(addr_a, addr_b)
+		for i = 0; i < a.len; i++
+			a[i] = b[i]
+		;;
+	else
+		for i = a.len; i > 0; i--
+			a[i - 1] = b[i - 1]
+		;;
 	;;
+		
 }
 
+const forwardcopy = {a, b
+	if a <= b
+		-> true
+	else
+		-> false
+	;;
+}
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -1362,9 +1362,9 @@
     size_t i, j;
 
     t = gettrait(curstab(), n->impl.traitname);
-    n->impl.trait = t;
     if (!t)
         fatal(n->line, "No trait %s\n", namestr(n->impl.traitname));
+    n->impl.trait = t;
     n->impl.type = tf(st, n->impl.type);
     putimpl(curstab(), n);
 
@@ -1374,11 +1374,12 @@
         /* look up the prototype */
         proto = NULL;
         dcl = n->impl.decls[i];
+
         /*
            since the decls in an impl are not installed in a namespace, their names
-           are not updated when we call updatens() on the symbol table. Since we need
+           are not updated when we call updatens() on the symbol table. Because we need
            to do namespace dependent comparisons for specializing, we need to set the
-           namespace.
+           namespace here.
          */
         if (file->file.globls->name)
             setns(dcl->decl.name, namestr(file->file.globls->name));
--- /dev/null
+++ b/test/data/stdslcp-expected
@@ -1,0 +1,2 @@
+3 4 5 4 5 
+6 7 6 7 8 
--- /dev/null
+++ b/test/stdslcp.myr
@@ -1,0 +1,19 @@
+use std
+
+const main = {
+	var a = [1,2,3,4,5]
+	var b = [6,7,8,9,10]
+	
+
+	std.slcp(a[:a.len-2], a[2:])
+	std.slcp(b[2:], b[:b.len-2])
+
+	for x in a
+		std.put("%i ", x)
+	;;
+	std.put("\n")
+	for x in b
+		std.put("%i ", x)
+	;;
+	std.put("\n")
+}
--- a/test/tests
+++ b/test/tests
@@ -119,6 +119,7 @@
 B strsplit	C
 B strfind	C
 B strjoin	C
+B stdslcp	C
 B bigint	C
 B exporttrait
 # B local-labels	E	10 ## BUGGERED