shithub: mc

Download patch

ref: b3ea4473f2850dbd625848bdefa7c7ac943c301a
parent: 8f1267793eb4f2bfee751dab4273496c3954950b
author: Ori Bernstein <[email protected]>
date: Sun Jul 22 11:18:33 EDT 2012

Many build fixes.

--- a/alloc.myr
+++ b/alloc.myr
@@ -14,9 +14,9 @@
 const Zbyte	= 0 castto(byte*)
 const Zslab	= 0 castto(slab*)
 const Zbin	= 0 castto(bin*)
-const Pagesz 	= 4096 /* on the systems this supports, anyways... */
-const Bucketmax	= 1024 /* Pagesz / 4; a tolerable balance. */
-const Align	= 16 /* minimum allocation alignment */
+const Pagesz 	= 4096	/* on the systems this supports, anyways... */
+const Bucketmax	= 1024	/* Pagesz / 4; a tolerable balance. */
+const Align	= 16	/* minimum allocation alignment */
 
 type bucket = struct
 	sz	: size	/* aligned size */
@@ -32,13 +32,21 @@
 	nfree	: size  /* the number of free nodes */
 ;;
 
-type bin = struct /* NB: must be smaller than sizeof(slab) */
-	next	: bin* /* the next bin in the free list */
+type bin = struct	/* NB: must be smaller than sizeof(slab) */
+	next	: bin*	/* the next bin in the free list */
 ;;
 
-var buckets : bucket[32] /* excessive number of buckets. */
+var buckets : bucket[32] /* excessive */
 var initdone : int
 
+generic alloc = {-> @a*
+	-> bytealloc(sizeof(@a)) castto(@a*)
+}
+
+generic free = {v:@a* -> void
+	bytefree(v castto(byte*), sizeof(@a))
+}
+
 const bytealloc = {sz
 	var i
 	var bkt
@@ -54,7 +62,7 @@
 		bkt = &buckets[bucketnum(sz)]
 		-> bktalloc(bkt)
 	else
-		die("Size too big for now")
+		-> mmap(Zbyte, sz, Mprotrw, Mpriv | Manon, -1, 0)
 	;;
 }
 
@@ -65,7 +73,7 @@
 		bkt = &buckets[bucketnum(sz)]
 		bktfree(bkt, m)
 	else
-		die("Size too big for now")
+		munmap(m, sz)
 	;;
 }
 
--- a/bld.sh
+++ b/bld.sh
@@ -15,32 +15,41 @@
 esac
 
 function use {
-    N=`basename $1 .myr`
+    for i in $@; do
+        N=`basename $i .myr`
 
-    echo $MU -o $N.use $1 && \
-    $MU -o $N.use $1
+        echo $MU -o $N.use $i && \
+        $MU -o $N.use $i
+    done
 }
 
 function build {
-    N=`basename $1 .myr`
+    for i in $@; do
+        N=`basename $i .myr`
 
-    echo $MC $1 && \
-    $MC -I. $1
+        echo $MC $i && \
+            $MC -I. $i
+    done
 }
 
 function assem {
-    $CC $ASOPT -m32 -c $1
+    for i in $@; do
+        $CC $ASOPT -m32 -c $i
+    done
 }
 
+ASM=syscall-$SYS.s
+# Myrddin source must be specified in dependency order
+MYR="sys-$SYS.myr \
+    types.myr \
+    alloc.myr \
+    die.myr \
+    hello.myr"
+OBJ="$(echo $ASM | sed 's/\.s/.o /g') $(echo $MYR | sed 's/\.myr/.o /g')"
+assem $ASM
+use $MYR
+build $MYR
 
-use sys-$SYS.myr
-use types.myr 
-use die.myr 
-assem syscall-$SYS.s
-build sys-$SYS.myr
-build alloc.myr
-build die.myr
+echo $CC -m32 -o hello $OBJ
+$CC -m32 -o hello $OBJ
 
-build hello.myr
-
-$CC -m32 -o hello sys.o hello.o syscall.o
--- a/hello.myr
+++ b/hello.myr
@@ -1,5 +1,8 @@
 use "sys.use"
+use "alloc.use"
 
 const main = {
+	var x : int*
+	x = std.alloc()
 	std.write(1, "Hello world\n")
 }