shithub: mc

Download patch

ref: 68dc8fd88d1fc23d6b882531343b38a8e2c7ac99
parent: b1739a7f310d9540f309afda175af2ae5a1dcca9
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Apr 14 12:57:15 EDT 2015

Get much closer to getting this whole mess working on OSX.

    It looks like the last missing piece is a working getcwd.

--- a/bootstrap.sh
+++ b/bootstrap.sh
@@ -208,5 +208,5 @@
 	../6/6m	-I ../libstd -I ../libbio -I ../libregex test.myr 
 echo 	../6/6m	-I ../libstd -I ../libbio -I ../libregex main.myr 
 	../6/6m	-I ../libstd -I ../libbio -I ../libregex main.myr 
-echo 	ld	-o mbld ../rt/_myrrt.o clean.o config.o deps.o types.o fsel.o util.o subdir.o main.o parse.o build.o opts.o install.o test.o -L../libstd -L../libbio -L../libregex -L/home/ori/bin/lib/myr -lregex -lbio -lstd -lsys -lsys -lstd -lbio -lregex 
-	ld	-o mbld ../rt/_myrrt.o clean.o config.o deps.o types.o fsel.o util.o subdir.o main.o parse.o build.o opts.o install.o test.o -L../libstd -L../libbio -L../libregex -L/home/ori/bin/lib/myr -lregex -lbio -lstd -lsys -lsys -lstd -lbio -lregex 
+echo 	ld	-macosx_version_min 10.6 -pagezero_size 100000000 -o mbld ../rt/_myrrt.o clean.o config.o deps.o types.o fsel.o util.o subdir.o main.o parse.o build.o opts.o install.o test.o -L../libstd -L../libbio -L../libregex -lregex -lbio -lstd -lsys -lsys -lstd -lbio -lregex 
+ 	ld	-macosx_version_min 10.6 -pagezero_size 100000000 -o mbld ../rt/_myrrt.o clean.o config.o deps.o types.o fsel.o util.o subdir.o main.o parse.o build.o opts.o install.o test.o -L../libstd -L../libbio -L../libregex -lregex -lbio -lstd -lsys -lsys -lstd -lbio -lregex 
--- a/configure
+++ b/configure
@@ -40,8 +40,6 @@
 
 echo '#define Instroot "'$prefix'"' > config.h
 echo '#define Asmcmd {"as", "-g", "-o", NULL}' >> config.h
-echo '#define Arcmd {"ar", "-rcs", NULL}' >> config.h
-echo '#define Ldcmd {"ld", "-o", NULL}' >> config.h
 echo '#define Defaultasm Gnugas' >> config.h
 echo '#define Objsuffix ".o"' >> config.h
 echo 'export SYSCLASS=posixy' >> config.mk
@@ -50,7 +48,6 @@
 echo "pkg config = " > mbld/config.myr
 echo "const Instroot = \"$prefix\"" >> mbld/config.myr
 echo "const Objsuffix = \".o\"" >> mbld/config.myr
-echo "const Linkcmd = [\"ld\", \"-o\"]" >> mbld/config.myr
 echo "const Arcmd = [\"ar\", \"-rcs\"]" >> mbld/config.myr
 echo "const Ascmd = [\"as\", \"-g\"]" >> mbld/config.myr
 echo "const Directlib = false" >> mbld/config.myr
@@ -62,10 +59,15 @@
         echo '#define Defaultasm Gnugas' >> config.h
         echo 'export SYS=linux' >> config.mk
         echo 'const Sys = "Linux"' >> mbld/config.myr
+        echo 'const Linkcmd = ["ld", "-o"]' >> mbld/config.myr
         ;;
     *Darwin*)
         echo '#define Symprefix "_"' >> config.h
         echo 'export SYS=osx' >> config.mk
+        echo 'const Linkcmd = ["ld", ' \
+            '"-pagezero_size", "0x100000000",' \
+            '"-macosx_version_min", "10.6",'\
+            '"-o"]' >> mbld/config.myr
         echo 'const Sys = "OSX"' >> mbld/config.myr
         ;;
     *FreeBSD*)
@@ -72,6 +74,7 @@
         echo '#define Symprefix ""' >> config.h
         echo '#define Defaultasm Gnugas' >> config.h
         echo 'export SYS=freebsd' >> config.mk
+        echo 'const Linkcmd = ["ld", "-o"]' >> mbld/config.myr
         echo 'const Sys = "FreeBSD"' >> mbld/config.myr
         ;;
     *)
--- a/libstd/getcwd.myr
+++ b/libstd/getcwd.myr
@@ -3,6 +3,7 @@
 use "errno.use"
 use "extremum.use"
 use "syswrap.use"
+use "syswrap-ss.use"
 pkg std =
 	const getcwd : (-> byte[:])
 ;;
--- a/libstd/sys+osx-x64.myr
+++ b/libstd/sys+osx-x64.myr
@@ -13,6 +13,7 @@
 	type filemode	= uint16	/* file permission bits */
 	type kflags	= uint16	/* kqueue flags */
 	type whence	= int64
+	type fcntlcmd	= int64
 
 	type timespec = struct
 		sec	: uint64
@@ -129,6 +130,49 @@
 	const Seekcur	: whence = 1
 	const Seekend	: whence = 2
 
+	/* system specific constants */
+	const Maxpathlen	: size = 1024
+
+	/* fcntl constants */
+	const Fdupfd		: fcntlcmd = 0		       /* duplicate file descriptor */
+	const Fgetfd		: fcntlcmd = 1		       /* get file descriptor flags */
+	const Fsetfd		: fcntlcmd = 2		       /* set file descriptor flags */
+	const Fgetfl		: fcntlcmd = 3		       /* get file status flags */
+	const Fsetfl		: fcntlcmd = 4		       /* set file status flags */
+	const Fgetown		: fcntlcmd = 5		       /* get SIGIO/SIGURG proc/pgrp */
+	const Fsetown		: fcntlcmd = 6		       /* set SIGIO/SIGURG proc/pgrp */
+	const Fgetlk		: fcntlcmd = 7		       /* get record locking information */
+	const Fsetlk		: fcntlcmd = 8		       /* set record locking information */
+	const Fsetlkw		: fcntlcmd = 9		       /* F_SETLK; wait if blocked */
+	const Fsetlkwtimeout	: fcntlcmd = 10			/* F_SETLK; wait if blocked, return on timeout */
+	const Fflush_data	: fcntlcmd = 40
+	const Fchkclean		: fcntlcmd = 41			/* Used for regression test */
+	const Fpreallocate	: fcntlcmd = 42			/* Preallocate storage */
+	const Fsetsize		: fcntlcmd = 43			/* Truncate a file without zeroing space */
+	const Frdadvise		: fcntlcmd = 44			/* Issue an advisory read async with no copy to user */
+	const Frdahead		: fcntlcmd = 45			/* turn read ahead off/on for this fd */
+	/* 46,47 used to be F_READBOOTSTRAP and F_WRITEBOOTSTRAP */
+	const Fnocache		: fcntlcmd = 48			/* turn data caching off/on for this fd */
+	const Flog2phys		: fcntlcmd = 49			/* file offset to device offset */
+	const Fgetpath		: fcntlcmd = 50			/* return the full path of the fd */
+	const Ffullfsync	: fcntlcmd = 51			/* fsync + ask the drive to flush to the media */
+	const Fpathpkg_check 	: fcntlcmd = 52			/* find which component (if any) is a package */
+	const Ffreeze_fs	: fcntlcmd = 53			/* "freeze" all fs operations */
+	const Fthaw_fs		: fcntlcmd = 54			/* "thaw" all fs operations */
+	const Fglobal_nocache	: fcntlcmd = 55			/* turn data caching off/on (globally) for this file */
+	const Faddsigs		: fcntlcmd = 59			/* add detached signatures */
+	const Faddfilesigs	: fcntlcmd = 61			/* add signature from same file (used by dyld for shared libs) */
+	const Fgetprotclass	: fcntlcmd = 63			/* Get the protection class of a file from the EA, returns int */
+	const Fsetprotclass	: fcntlcmd = 64			/* Set the protection class of a file for the EA, requires int */
+	const Flog2phys_ext	: fcntlcmd = 65			/* file offset to device offset, extended */
+	const Fgetlkpid		: fcntlcmd = 66			/* get record locking information, per-process */
+	/* See F_DUPFD_CLOEXEC below for 67 */
+	const Fsetbacktore	: fcntlcmd = 70			/* Mark the file as being the backing store for another filesystem */
+	const Fgetpath_mtminfo	: fcntlcmd = 71			/* return the full path of the FD, but error in specific mtmd circumstances */
+	/* 72 is free.	It used to be F_GETENCRYPTEDDATA, which is now removed. */
+	const Fsetnosigpipe	: fcntlcmd = 73			/* No SIGPIPE generated on EPIPE */
+	const Fgetnosigpipe	: fcntlcmd = 74			/* Status of SIGPIPE for this fd */
+
 	/* kqueue events */
 	const Kevadd		: kflags = 0x0001	/* add event to kq (implies enable) */
 	const Kevdelete		: kflags = 0x0002	/* delete event from kq */
@@ -595,6 +639,8 @@
 	const pipe	: (fd : fd[2]# -> int64)
 	const dup	: (fd : fd -> fd)
 	const dup2	: (src : fd, dst : fd -> fd)
+	/* NB: the C ABI uses '...' for the args. */
+	const fcntl	: (fd : fd, cmd : fcntlcmd, args : byte# -> int64)
 
 	/* kqueue */
 	const kqueue	: (-> fd)
@@ -733,6 +779,7 @@
 const pipe	= {fd;	-> __osx_pipe(fd)}
 const dup 	= {fd;	-> syscall(Sysdup, a(fd)) castto(fd)}
 const dup2 	= {src, dst;	-> syscall(Sysdup2, a(src), a(dst)) castto(fd)}
+const fcntl	= {fd, cmd, args; 	-> syscall(Sysfcntl, a(fd), a(cmd), a(args))}
 
 /* kqueueueueueueue */
 const kqueue	= {;	-> syscall(Syskqueue) castto(fd)}
--- a/libstd/syscall+linux-x64.s
+++ b/libstd/syscall+linux-x64.s
@@ -18,6 +18,7 @@
 	harmless.
 	 */
 	movq 80 (%rsp),%rax
+	/* 88: hidden type arg */
 	movq 96 (%rsp),%rdi
 	movq 104(%rsp),%rsi
 	movq 112(%rsp),%rdx
--- a/libstd/syscall+osx-x64.s
+++ b/libstd/syscall+osx-x64.s
@@ -17,12 +17,13 @@
 	harmless.
 	 */
 	movq 80 (%rsp),%rax
-	movq 88 (%rsp),%rdi
-	movq 96 (%rsp),%rsi
-	movq 104(%rsp),%rdx
-	movq 112(%rsp),%r10
-	movq 120(%rsp),%r8
-	movq 128(%rsp),%r9
+	/* 88: hidden type arg */
+	movq 96 (%rsp),%rdi
+	movq 104(%rsp),%rsi
+	movq 112(%rsp),%rdx
+	movq 120(%rsp),%r10
+	movq 128(%rsp),%r8
+	movq 136(%rsp),%r9
 
 	syscall
 	jae .success
--- a/libstd/syswrap+posixy.myr
+++ b/libstd/syswrap+posixy.myr
@@ -68,7 +68,6 @@
 	pkglocal const getmem	: (sz : size -> byte#)
 	pkglocal const freemem	: (p : byte#, sz : size -> void)
 	pkglocal const curtime	: (-> time)
-	pkglocal const bgetcwd	: (buf : byte[:] -> errno)
 ;;
 
 /* fd stuff */
@@ -86,7 +85,6 @@
 const mkdir	= {path, mode;	-> sys.mkdir(path, mode)}
 const chdir	= {path;	-> sys.chdir(path) == 0}
 const remove	= {path;	-> sys.unlink(path) == 0}
-const bgetcwd	= {buf;		-> sys.getcwd(buf) castto(errno)}
 
 /* useful/portable bits of uname */
 const getsysinfo = {si
--- a/libstd/syswrap-ss+posixy-linux.myr
+++ b/libstd/syswrap-ss+posixy-linux.myr
@@ -2,6 +2,8 @@
 
 pkg std =
 	const exit	: (status:int -> void)
+	pkglocal const bgetcwd	: (buf : byte[:] -> errno)
 ;;
 
 const exit	= {status;	sys.exit_group(status)}
+const bgetcwd	= {buf;		-> sys.getcwd(buf) castto(errno)}
--- a/libstd/syswrap-ss+posixy-osx.myr
+++ b/libstd/syswrap-ss+posixy-osx.myr
@@ -1,7 +1,23 @@
 use sys
+use "errno.use"
 
 pkg std =
 	const exit	: (status:int -> void)
+	pkglocal const bgetcwd	: (buf : byte[:] -> errno)
 ;;
 
 const exit	= {status;	sys.exit(status)}
+const bgetcwd	= {buf
+	var path : byte[sys.Maxpathlen]
+	var fd
+
+	fd = sys.open(".", sys.Ordonly)
+	if fd < 0
+		-> fd castto(errno)
+	;;
+	/* 
+	FIXME: if the path is longer than sys.Pathmax, we should fall back to
+	the ugly method of finding the path.
+	*/
+	-> sys.fcntl(fd, sys.Fgetpath, path[:] castto(byte#)) castto(errno)
+}
--- a/mbld/main.myr
+++ b/mbld/main.myr
@@ -18,7 +18,10 @@
 	var bintarg
 	var optctx
 
+	/*
 	optctx = std.optinit("hb:l:s:Sr:I:C:A:M:L:R:d", args)
+	*/
+	optctx = std.optinit("", args)
 	bld.initopts()
 	while !std.optdone(optctx)
 		match std.optnext(optctx)
--- a/mbld/parse.myr
+++ b/mbld/parse.myr
@@ -31,6 +31,7 @@
 	var p : parser#
 	var subpath, subbld, ok
 
+	std.put("loading %s in dir '%s'\n", path, dir)
 	p = mkparser(path, dir, b.basedir)
 	ok = bld.parse(b, p, "")
 	for s in p.subdirs
@@ -62,11 +63,13 @@
 
 const freeparser = {p
 	std.slfree(p.fname)
+	/*
 	std.slfree(p.fdir)
 	std.slfree(p.basedir)
 	std.slfree(p.subdirs)
 	std.slfree(p.data)
 	std.free(p)
+	*/
 }
 
 const failparse = {p, msg, args : ...