shithub: mc

Download patch

ref: bd389067cb68d0d7b4c55db95f1b8021f1d95524
parent: 88e09f2323da6f5f3e8b04bfe492fdf53ffdefbc
parent: a3f00eee7003eae5aaf6c91fd674915e098b8b18
author: Ori Bernstein <[email protected]>
date: Wed Oct 24 10:01:46 EDT 2012

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

--- a/libstd/Makefile
+++ b/libstd/Makefile
@@ -3,6 +3,7 @@
     alloc.myr \
     chartype.myr \
     die.myr \
+    extremum.myr \
     fmt.myr \
     option.myr \
     rand.myr \
@@ -30,7 +31,7 @@
 	cp start-$(SYS).s start.s
 
 test: libstd.a
-	../myrbuild/myrbuild -b test test.myr -I.
+	../myrbuild/myrbuild -b test -I. test.myr
 
 
 $(MYRLIB): $(MYRSRC) $(ASMSRC)
--- a/libstd/alloc.myr
+++ b/libstd/alloc.myr
@@ -1,13 +1,15 @@
 use "die.use"
 use "sys.use"
 use "types.use"
+use "extremum.use"
 
 pkg std =
 	generic alloc	: (		-> @a*)
 	generic free	: (v:@a*	-> void)
 
-	generic mkslice	: (len : size	-> @a[:])
-	generic freeslice: (sl : @a[:]	-> void)
+	generic slalloc	: (len : size	-> @a[:])
+	generic slfree	: (sl : @a[:]	-> void)
+	generic slgrow	: (sl : @a[:], len : size	-> @a[:])
 
 	const bytealloc	: (sz:size	-> byte*)
 	const bytefree	: (m:byte*, sz:size	-> void)
@@ -35,8 +37,8 @@
 ;;
 
 type slab = struct
-	head		: byte*	/* head of virtual addresses, so we don't leak address space */
-	next		: slab*	/* the next slab on the chain */
+	head	: byte*	/* head of virtual addresses, so we don't leak address space */
+	next	: slab*	/* the next slab on the chain */
 	freehd	: chunk*	/* the nodes we're allocating */
 	nfree	: size	/* the number of free nodes */
 ;;
@@ -53,7 +55,7 @@
 	bytefree(v castto(byte*), sizeof(@a))
 }
 
-generic mkslice = {len
+generic slalloc = {len
 	var p
 
 	p = bytealloc(len*sizeof(@a)) castto(@a*)
@@ -60,8 +62,21 @@
 	-> p[0:len]
 }
 
-generic freeslice = {sl
+generic slfree	 = {sl
 	-> bytefree(sl castto(byte*), sl.len * sizeof(@a))
+}
+
+generic slgrow = {sl, len
+	var i
+	var n
+	var new
+
+	new = slalloc(len)
+	n = min(len, sl.len)
+	for i = 0; i < n; i++
+		new[i] = sl[i]
+	;;
+	-> new
 }
 
 const bytealloc = {sz
--- /dev/null
+++ b/libstd/extremum.myr
@@ -1,0 +1,20 @@
+pkg std =
+	generic min	: (a : @a::tcnum, b : @a::tcnum  -> @a::tcnum)
+	generic max	: (a : @a::tcnum, b : @a::tcnum  -> @a::tcnum)
+;;
+
+generic min = {a, b
+	if a < b
+		-> a
+	else
+		-> b
+	;;
+}
+
+generic max = {a, b
+	if a > b
+		-> a
+	else
+		-> b
+	;;
+}
--- a/libstd/fmt.myr
+++ b/libstd/fmt.myr
@@ -3,6 +3,7 @@
 use "types.use"
 use "utf.use"
 use "varargs.use"
+use "extremum.use"
 
 pkg std =
 	const bfmt	: (buf : byte[:], fmt : byte[:], args:... -> size)
@@ -123,13 +124,5 @@
 		n += encode(buf[n:], b[j])
 	;;
 	-> n 
-}
-
-const min = {a : size, b : size
-	if a < b
-		-> a
-	else
-		-> b
-	;;
 }
 
--- a/myrbuild/myrbuild.c
+++ b/myrbuild/myrbuild.c
@@ -290,8 +290,8 @@
     snprintf(buf, sizeof buf, "-L%s%s", Instroot, "/lib/myr");
     lappend(&args, &nargs, strdup(buf));
     for (i = 0; i < nincpaths; i++) {
-        lappend(&args, &nargs, strdup("-L"));
-        lappend(&args, &nargs, strdup(incpaths[i]));
+        snprintf(buf, sizeof buf, "-L%s", incpaths[i]);
+        lappend(&args, &nargs, strdup(buf));
     }
     for (i = 0; i < nlibs; i++) {
         snprintf(buf, sizeof buf, "-l%s", libs[i]);
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -689,7 +689,7 @@
         settype(st, var, tyfreshen(st, s->decl.type));
     else
         settype(st, var, s->decl.type);
-    if (s->decl.isgeneric) {
+    if (s->decl.isgeneric && !st->ingeneric) {
         lappend(&st->specializationscope, &st->nspecializationscope, curstab());
         lappend(&st->specializations, &st->nspecializations, var);
         lappend(&st->genericdecls, &st->ngenericdecls, s);
@@ -913,7 +913,7 @@
                 t = s->decl.type;
             settype(st, n, t);
             n->expr.did = s->decl.did;
-            if (s->decl.isgeneric) {
+            if (s->decl.isgeneric && !st->ingeneric) {
                 lappend(&st->specializationscope, &st->nspecializationscope, curstab());
                 lappend(&st->specializations, &st->nspecializations, n);
                 lappend(&st->genericdecls, &st->ngenericdecls, s);