zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 935f10502f9308b262c3d4b979a3fbe20baf670f (tree)
parent df3d2115b5e45eefb3898d89307b05505c2f5b5a
Author: Andrea Orru <andrea@orru.io>
Date:   Sun, 18 Mar 2018 14:45:23 -0400

Message type, Undefined mailbox, read syscall, more constructors

Diffstat:
Mstd/os/zen.zig | 41++++++++++++++++++++++++++++++++++++-----
1 file changed, 36 insertions(+), 5 deletions(-)

diff --git a/std/os/zen.zig b/std/os/zen.zig @@ -5,26 +5,39 @@ pub const Message = struct { sender: MailboxId, receiver: MailboxId, + type: usize, payload: usize, pub fn from(mailbox_id: &const MailboxId) Message { return Message { - .sender = undefined, + .sender = MailboxId.Undefined, .receiver = *mailbox_id, - .payload = undefined, + .type = 0, + .payload = 0, }; } - pub fn to(mailbox_id: &const MailboxId, payload: usize) Message { + pub fn to(mailbox_id: &const MailboxId, msg_type: usize) Message { return Message { .sender = MailboxId.This, .receiver = *mailbox_id, + .type = msg_type, + .payload = 0, + }; + } + + pub fn withData(mailbox_id: &const MailboxId, msg_type: usize, payload: usize) Message { + return Message { + .sender = MailboxId.This, + .receiver = *mailbox_id, + .type = msg_type, .payload = payload, }; } }; pub const MailboxId = union(enum) { + Undefined, This, Kernel, Port: u16, @@ -56,13 +69,31 @@ pub const getErrno = @import("linux/index.zig").getErrno; use @import("linux/errno.zig"); // TODO: implement this correctly. +pub fn read(fd: i32, buf: &u8, count: usize) usize { + switch (fd) { + STDIN_FILENO => { + var i: usize = 0; + while (i < count) : (i += 1) { + send(Message.to(Server.Keyboard, 0)); + + var message = Message.from(MailboxId.This); + receive(&message); + + buf[i] = u8(message.payload); + } + }, + else => unreachable, + } + return count; +} + +// TODO: implement this correctly. pub fn write(fd: i32, buf: &const u8, count: usize) usize { switch (fd) { - STDIN_FILENO => unreachable, STDOUT_FILENO, STDERR_FILENO => { var i: usize = 0; while (i < count) : (i += 1) { - send(Message.to(Server.Terminal, buf[i])); + send(Message.withData(Server.Terminal, 1, buf[i])); } }, else => unreachable,