summaryrefslogtreecommitdiff
path: root/libstd
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-04-23 21:58:54 -0700
committerOri Bernstein <ori@eigenstate.org>2015-04-23 21:58:54 -0700
commitc323281f1f6649f87a6f06c8e37d9d5f25001945 (patch)
tree5c4f0b8a58154fd323aa300bdf8684cb2c920eb9 /libstd
parentf8b5e94caa6de168b47e47900176ff3b56c5e2c4 (diff)
downloadmc-c323281f1f6649f87a6f06c8e37d9d5f25001945.tar.gz
Fix bootstrap on plan9.
We still don't generate type descriptions, but we at least run and bootstrap.
Diffstat (limited to 'libstd')
-rw-r--r--libstd/dial+plan9.myr6
-rw-r--r--libstd/env+plan9.myr6
-rw-r--r--libstd/resolve+plan9.myr2
-rw-r--r--libstd/syserrno+plan9.myr38
-rw-r--r--libstd/syswrap+plan9.myr22
-rw-r--r--libstd/syswrap-ss+plan9.myr56
6 files changed, 102 insertions, 28 deletions
diff --git a/libstd/dial+plan9.myr b/libstd/dial+plan9.myr
index f198e10..9c0f90d 100644
--- a/libstd/dial+plan9.myr
+++ b/libstd/dial+plan9.myr
@@ -94,7 +94,7 @@ const csdial = {netdir, proto, rem
const call = {clone, addr, netdir
var namebuf : byte[Maxpath]
var databuf : byte[Maxpath]
- var name, base
+ var name, base, dpath
var cfd, datafd
var c, n
@@ -117,8 +117,8 @@ const call = {clone, addr, netdir
| `None: die("there should be a '/' here\n")
| `Some i: base = c[:i]
;;
- n = bfmt(databuf[:], "%s/%s/data", base, name)
- datafd = open(databuf[:n], Ordwr)
+ dpath = bfmt(databuf[:], "%s/%s/data", base, name)
+ datafd = open(dpath, Ordwr)
:cleanup
close(cfd)
slfree(c)
diff --git a/libstd/env+plan9.myr b/libstd/env+plan9.myr
index 55d59c3..cb051d4 100644
--- a/libstd/env+plan9.myr
+++ b/libstd/env+plan9.myr
@@ -32,13 +32,13 @@ const envfind = {key
const getenv = {name
var buf : byte[128]
- var n
+ var s
match envfind(name)
| `Some val: -> `Some val
| `None:
- n = bfmt(buf[:], "/env/%s", name)
- match std.slurp(buf[:n])
+ s = bfmt(buf[:], "/env/%s", name)
+ match std.slurp(s)
| `Fail m: -> `None
| `Ok data:
envkey = slpush(envkey, sldup(name))
diff --git a/libstd/resolve+plan9.myr b/libstd/resolve+plan9.myr
index e69de29..ef73843 100644
--- a/libstd/resolve+plan9.myr
+++ b/libstd/resolve+plan9.myr
@@ -0,0 +1,2 @@
+pkg std =
+;;
diff --git a/libstd/syserrno+plan9.myr b/libstd/syserrno+plan9.myr
index e69de29..18a3fc2 100644
--- a/libstd/syserrno+plan9.myr
+++ b/libstd/syserrno+plan9.myr
@@ -0,0 +1,38 @@
+pkg sys =
+ type errno = int
+
+ const Eperm : errno = -1 /* Operation not permitted */
+ const Enoent : errno = -2 /* No such file or directory */
+ const Esrch : errno = -3 /* No such process */
+ const Eintr : errno = -4 /* Interrupted system call */
+ const Eio : errno = -5 /* I/O error */
+ const Enxio : errno = -6 /* No such device or address */
+ const E2big : errno = -7 /* Argument list too long */
+ const Enoexec : errno = -8 /* Exec format error */
+ const Ebadf : errno = -9 /* Bad file number */
+ const Echild : errno = -10 /* No child processes */
+ const Eagain : errno = -11 /* Try again */
+ const Enomem : errno = -12 /* Out of memory */
+ const Eacces : errno = -13 /* Permission denied */
+ const Efault : errno = -14 /* Bad address */
+ const Enotblk : errno = -15 /* Block device required */
+ const Ebusy : errno = -16 /* Device or resource busy */
+ const Eexist : errno = -17 /* File exists */
+ const Exdev : errno = -18 /* Cross-device link */
+ const Enodev : errno = -19 /* No such device */
+ const Enotdir : errno = -20 /* Not a directory */
+ const Eisdir : errno = -21 /* Is a directory */
+ const Einval : errno = -22 /* Invalid argument */
+ const Enfile : errno = -23 /* File table overflow */
+ const Emfile : errno = -24 /* Too many open files */
+ const Enotty : errno = -25 /* Not a typewriter */
+ const Etxtbsy : errno = -26 /* Text file busy */
+ const Efbig : errno = -27 /* File too large */
+ const Enospc : errno = -28 /* No space left on device */
+ const Espipe : errno = -29 /* Illegal seek */
+ const Erofs : errno = -30 /* Read-only file system */
+ const Emlink : errno = -31 /* Too many links */
+ const Epipe : errno = -32 /* Broken pipe */
+ const Edom : errno = -33 /* Math argument out of domain of func */
+ const Erange : errno = -34 /* Math result not representable */
+;;
diff --git a/libstd/syswrap+plan9.myr b/libstd/syswrap+plan9.myr
index 9870268..030772e 100644
--- a/libstd/syswrap+plan9.myr
+++ b/libstd/syswrap+plan9.myr
@@ -60,7 +60,6 @@ pkg std =
const fork : (-> pid)
const execv : (cmd : byte[:], args : byte[:][:] -> int64)
const execve : (cmd : byte[:], args : byte[:][:], env : byte[:][:] -> int64)
- const exit : (status:int -> void)
const waitpid : (pid:pid, loc:int32#, opt : int64 -> pid)
pkglocal const Canunmap : bool = true
@@ -162,27 +161,6 @@ const suicide = {; (0 castto(byte#))#} /* let's happy segfault!! t */
const fork = {; -> sys.rfork(sys.Rffdg | sys.Rfrend | sys.Rfproc) castto(pid)}
const execv = {cmd, args; -> sys.exec(cmd, args) castto(int64)}
const execve = {cmd, args, env; -> sys.exec(cmd, args) castto(int64)}
-const digitchars = "0123456789"
-const exit = {status
- var buf : byte[32] /* big enough for exit status numbers */
- var n, i
-
- if status == 0
- sys.exits("")
- else
- status &= 255
- i = 100
- n = 0
- while i > 0
- if status >= i
- buf[n++] = digitchars[(status/i)%10]
- ;;
- i /= 10
- ;;
- sys.exits(buf[:n])
- ;;
-}
-
/* memory stuff */
const getmem = {sz
diff --git a/libstd/syswrap-ss+plan9.myr b/libstd/syswrap-ss+plan9.myr
new file mode 100644
index 0000000..9615a6e
--- /dev/null
+++ b/libstd/syswrap-ss+plan9.myr
@@ -0,0 +1,56 @@
+use sys
+
+use "errno.use"
+use "cstrconv.use"
+
+pkg std =
+ const exit : (status : int -> void)
+ pkglocal const bgetcwd : (buf : byte[:] -> errno)
+;;
+
+const bgetcwd = {buf
+ var fd
+
+ fd = sys.open(".", sys.Ordonly)
+ if fd < 0
+ -> fd castto(errno)
+ ;;
+
+ if sys.fd2path(fd, buf) == 0
+ /*
+ Because we don't return the size, the best we can do is
+ assume that if the buffer is completely full, we have
+ truncated it. Since we truncate at utf8 characters, we
+ can have at most 3 bytes truncated (4 bytes will fit
+ any utf8 char), and one byte for the nul terminator.
+ */
+ if cstrlen(buf) + 5 == buf.len
+ -> Erange
+ else
+ -> cstrlen(buf) castto(errno)
+ ;;
+ ;;
+ -> Emisc
+}
+
+const digitchars = "0123456789"
+const exit = {status
+ var buf : byte[32] /* big enough for exit status numbers */
+ var n, i
+
+ if status == 0
+ sys.exits("")
+ else
+ status &= 255
+ i = 100
+ n = 0
+ while i > 0
+ if status >= i
+ buf[n++] = digitchars[(status/i)%10]
+ ;;
+ i /= 10
+ ;;
+ sys.exits(buf[:n])
+ ;;
+}
+