shithub: mc

Download patch

ref: 226ef2e101258817ee3c41a28846c607d880a69c
parent: aae6d00697e8b2c4e887aa225eb102b7f88358af
parent: 6734665cb2214ce148e46b719ed6ae36d266f037
author: Ori Bernstein <[email protected]>
date: Mon May 5 10:32:39 EDT 2014

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

--- a/libstd/slcp.myr
+++ b/libstd/slcp.myr
@@ -1,16 +1,26 @@
 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 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]
+		;;
 	;;
+		
 }
-
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -299,7 +299,6 @@
             }
         | implstmt {
                 $1->impl.vis = Visexport;
-                lappend(&exportimpls, &nexportimpls, $1);
             }
         | visdef {die("Unimplemented visdef");}
         | /* empty */
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -857,15 +857,17 @@
         if (nx->impl.isproto) {
             if (!ng)
                 fatal(nx->line, "Missing trait impl body for %s %s\n", namestr(nx->impl.traitname), tystr(nx->impl.type));
-            nx->impl.isproto = 0;
-            nx->impl.decls = ng->impl.decls;
-            nx->impl.ndecls = ng->impl.ndecls;
+            htdel(exports->impl, k[i]);
+            putimpl(exports, ng);
+            lappend(&exportimpls, &nexportimpls, ng);
         } else {
-            if (ng)
+            if (!ng) {
+                putimpl(globls, nx);
+                lappend(&exportimpls, &nexportimpls, nx);
+            } else {
                 fatal(nx->line, "Double trait impl body for %s %s on line %d\n",
                       namestr(nx->impl.traitname), tystr(nx->impl.type), ng->line);
-            else
-                putimpl(globls, nx);
+            }
         }
 
     }
@@ -1362,6 +1364,7 @@
     t = gettrait(curstab(), n->impl.traitname);
     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);
 
@@ -1371,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));
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -297,6 +297,7 @@
 
         struct {
             Node *traitname;
+            Trait *trait;
             Type *type;
             Node **decls;
             size_t ndecls;
--- a/parse/use.c
+++ b/parse/use.c
@@ -263,9 +263,15 @@
         wrsym(fd, tr->funcs[i]);
 }
 
-static void implpickle(FILE *fd, Node *impl)
+static void implpickle(FILE *fd, Node *n)
 {
-    die("Pickling impls not yet supported.");
+    size_t i;
+
+    pickle(fd, n->impl.traitname);
+    wrint(fd, n->impl.trait->uid);
+    wrtype(fd, n->impl.type);
+    for (i = 0; i < n->impl.ndecls; i++)
+        pickle(fd, n->impl.decls[i]);
 }
 
 static void wrtype(FILE *fd, Type *ty)
--- /dev/null
+++ b/test/data/stdslcp-expected
@@ -1,0 +1,2 @@
+3 4 5 4 5 
+6 7 6 7 8 
--- a/test/exporttrait.myr
+++ b/test/exporttrait.myr
@@ -1,3 +1,5 @@
+use std
+
 pkg =
 	trait t @a
 	impl t int
@@ -12,3 +14,7 @@
 		-> v*2
 	}
 ;;
+
+/* shut up the linker: we just want to compile this. */
+const main = {
+}
--- /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