summaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2019-07-13 22:46:57 -0700
committerOri Bernstein <ori@eigenstate.org>2019-07-13 22:46:57 -0700
commit820585fb7338092fa5b5001b81ad45b06376939d (patch)
tree47214d3efdf0459fdcd73994d83d2d54ed00b686 /lib/std
parent77246bfe1b9f147b1b255e811fb8b2032c49dc9e (diff)
downloadmc-820585fb7338092fa5b5001b81ad45b06376939d.tar.gz
Oops, mangled something with git9.
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/dir+openbsd.myr65
-rw-r--r--lib/std/syswrap-ss+openbsd.myr31
-rw-r--r--lib/std/test/bigint.myr8
3 files changed, 96 insertions, 8 deletions
diff --git a/lib/std/dir+openbsd.myr b/lib/std/dir+openbsd.myr
new file mode 100644
index 0000000..274175d
--- /dev/null
+++ b/lib/std/dir+openbsd.myr
@@ -0,0 +1,65 @@
+use sys
+
+use "alloc"
+use "die"
+use "memops"
+use "option"
+use "result"
+use "slcp"
+use "sldup"
+use "types"
+
+pkg std =
+ type dir = struct
+ fd : sys.fd
+ buf : byte[16384]
+ len : int64
+ off : int64
+ ;;
+
+ const diropen : (p : byte[:] -> std.result(dir#, byte[:]))
+ const dirread : (d : dir# -> std.option(byte[:]))
+ const dirclose : (d : dir# -> void)
+;;
+
+const diropen = {p
+ var fd
+ var dir
+
+ fd = sys.open(p, sys.Ordonly | sys.Odir)
+ if fd < 0
+ -> `Err "couldn't open directory"
+ ;;
+ dir = zalloc()
+ dir.fd = fd
+ -> `Ok dir
+}
+
+const dirread = {d
+ var len
+ var dent
+ var namelen
+
+ if d.off >= d.len
+ len = sys.getdents(d.fd, d.buf[:])
+ if len <= 0
+ -> `None
+ ;;
+ d.len = len
+ d.off = 0
+ ;;
+
+ dent = (&d.buf[d.off] : sys.dirent#)
+ namelen = 0
+ d.off += (dent.reclen : int64)
+ while dent.name[namelen] != 0
+ namelen++
+ ;;
+ -> `Some sldup(dent.name[:namelen])
+}
+
+const dirclose = {d
+ sys.close(d.fd)
+ free(d)
+}
+
diff --git a/lib/std/syswrap-ss+openbsd.myr b/lib/std/syswrap-ss+openbsd.myr
new file mode 100644
index 0000000..0f4ed65
--- /dev/null
+++ b/lib/std/syswrap-ss+openbsd.myr
@@ -0,0 +1,31 @@
+use sys
+use "types"
+use "errno"
+use "cstrconv"
+use "slcp"
+use "die"
+
+pkg std =
+ const nanosleep : (nsecs : uint64 -> errno)
+ $noret const exit : (status:int -> void)
+
+ pkglocal const bgetcwd : (buf : byte[:] -> errno)
+;;
+
+const exit = {status; sys.exit(status)}
+
+const bgetcwd = {buf
+ -> (sys.__getcwd(buf) - 1 : errno)
+}
+
+const nanosleep = {nsecs
+ var req, rem
+ var s, ns
+
+ s = (nsecs / 1_000_000_000 : int64)
+ ns = (nsecs % 1_000_000_000 : int64)
+ req = [.sec = s, .nsec = ns]
+
+ -> (sys.nanosleep(&req, &rem) : errno)
+}
+
diff --git a/lib/std/test/bigint.myr b/lib/std/test/bigint.myr
index 77b822f..c87f1f3 100644
--- a/lib/std/test/bigint.myr
+++ b/lib/std/test/bigint.myr
@@ -21,7 +21,6 @@ const main = {
[.name = "format-zero", .fn = fmtzero],
[.name = "division", .fn = smokediv],
[.name = "modulo", .fn = smokemod],
- [.name = "shift", .fn = shiftoff],
[.name = "add-negatives", .fn = addneg],
[.name = "sub-negatives", .fn = subneg],
][:])
@@ -265,13 +264,6 @@ const subneg = {c
"0")
}
-const shiftoff = {c
- run(c, std.mk(`Shr ( \
- std.mk(`Val "1"), \
- std.mk(`Val "65"))), \
- "0")
-}
-
const run = {c : testr.ctx#, e : cmd#, res : byte[:]
var buf : byte[4096]
var v, n