changeset 143:f70c4ec3fb8a

add file_read.cbc (uncomplete)
author anatofuz
date Sat, 14 Dec 2019 18:52:21 +0900
parents 819537a244ee
children eef045e9772a
files src/file_read.cbc
diffstat 1 files changed, 66 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/file_read.cbc	Sat Dec 14 18:52:21 2019 +0900
@@ -0,0 +1,66 @@
+#include "../context.h"
+#interface "SysRead.h"
+
+// ----
+// typedef struct FileRead<Type, Isa> impl SysRead {
+//   struct file* f;
+//   int r;
+//   __code cbc_fileread1(Type* file_read, struct file* f,int r,__code next(r,...));
+//   __code next(...);
+// } FileRead;
+// ----
+
+SysRead* createFileRead(struct Context* cbc_context) {
+    struct SysRead* sys_read  = new SysRead();
+    struct FileRead* file_read = new FileRead();
+    sys_read->sys_read = (union Data*)file_read;
+    file_read->f = NULL;
+    file_read->r  = 0;
+    sys_read->impl = NULL;
+    sys_read->addr = NULL;
+    sys_read->n  = 0;
+    sys_read->read = C_readFileRead;
+    sys_read->next = C_nextFileRead;
+    return sys_read;
+}
+
+SysRead* createFileReadInstFromFile(struct Context* cbc_context, struct file* f,char* addr, int n) {
+    SysRead* self;
+    if (f->type == FD_PIPE) {
+        self = create_piperead(cbc_context, f->pipe, addr, n, next);
+    }
+
+    if (f->type == FD_INODE) {
+        ilock(f->ip);
+        self = create_readi(cbc_context, f->ip, addr, f->off, n, cbc_fileread1);
+    }
+    return self;
+}
+
+
+__code cbc_fileread1FileRead(struct FileRead* file_read, struct file* f,int r,__code next(r,...)) {
+
+  goto next(r,...);
+}
+
+__code nextFileRead(...) {
+
+}
+
+__code readFileRead(struct FileRead* sys_read, union Data* impl, char* addr, int n, __code next(int ret,...)) {
+
+  goto next(int ret,...);
+}
+
+__code selectReadInstance(struct file* f) {
+  if (f->readable == 0) {
+    goto next(-1);
+  } 
+  SysRead* read = createFileReadInstFromFile(proc->cbc_context, f);
+  read->read(f,addr,n);
+}
+
+__code nextFileRead(...) {
+
+}
+