changeset 96:d5c4016c65b8

implement read interfacce
author anatofuz
date Sat, 09 Nov 2019 19:56:07 +0900
parents 0ddcd561d975
children 70eae4b230f2
files src/context.h src/file.cbc src/interface/CbCSysFile.h src/interface/SysRead.h src/pipe.cbc
diffstat 5 files changed, 78 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/src/context.h	Mon Nov 04 17:24:00 2019 +0900
+++ b/src/context.h	Sat Nov 09 19:56:07 2019 +0900
@@ -235,15 +235,6 @@
     struct CUDAWorker {
     } CUDAWorker;
 #endif
-    struct CbCSysFile {
-        struct file *f;
-        int  n;
-        char *p;
-        struct UInteger* num;
-        enum Code next;
-        enum Code read;
-        enum Code cbc_file_ret;
-    } CbCSysFile;
     struct Main {
         enum Code code;
         enum Code next;
@@ -481,8 +472,42 @@
     struct String {
       char* string;
     } String;
+    struct SysRead {
+        union Data* sys_read;
+        struct UInteger* num;
+        struct String* str;
+        enum Code next;
+        enum Code read;
+        enum Code ret;
+    } SysRead;
+    struct SysFileRead {
+        struct file *f;
+    } SysFileRead;
+    struct CbCPipe {
+        struct pipe *p;
+    } CbCPipe;
+    struct PipeRead {
+        struct CbCPipe *pipe;
+        struct String *addr; 
+        struct Integer* i;
+    } PipeRead;
 }; // union Data end       this is necessary for cbc_context generator
 
+/*
+        struct cbc_console_arg {
+            int n;
+            int target;
+            char* dst;
+            struct inode *ip;
+            struct file *f;
+            int num;
+            struct pipe *p;
+            char *addr;
+            int i;
+            __code (*next)(int ret);
+        } cbc_console_arg;
+*/
+
 typedef union Data Data;
 
 #include "c/typedefData.h"
--- a/src/file.cbc	Mon Nov 04 17:24:00 2019 +0900
+++ b/src/file.cbc	Sat Nov 09 19:56:07 2019 +0900
@@ -12,6 +12,10 @@
 
 #define __ncode __code
 #
+
+#interface "SysRead.h"
+
+
 struct devsw devsw[NDEV];
 struct cbc_devsw cbc_devsw[NDEV];
 
@@ -25,6 +29,16 @@
     initlock(&ftable.lock, "ftable");
 }
 
+struct SysFileRead* createSysFileRead(struct Context* context) {
+    struct SysRead* sys_read = new SysRead();
+    struct SysFileRead* sys_file_read = new SysFileRead();
+    sys_read->sys_read = (union Data*)sys_file_read;
+    sys_read->read = C_cbc_fileread;
+    sys_read->ret  = C_cbc_fileret;
+    sys_read->next = NULL;
+    return sys_read;
+}
+
 // Allocate a file structure.
 struct file* filealloc (void)
 {
@@ -221,5 +235,3 @@
     }
 
     panic("filewrite");
-}
-
--- a/src/interface/CbCSysFile.h	Mon Nov 04 17:24:00 2019 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-typedef struct CbCSysFile<Type, Impl>{
-   struct CbCSysFile* cbc_file;
-   struct UInteger* num;
-   int n;
-   char *p;
-   struct file *f;
-   __code file_read(__code next(...));
-   __code cbc_ret(Impl* cbc_sys_file, UInteger* num);
-   __code next(...);
-} CbCSysFile;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/interface/SysRead.h	Sat Nov 09 19:56:07 2019 +0900
@@ -0,0 +1,9 @@
+typedef struct SysRead<Type, Impl>{
+   union  Data* sys_read;
+   struct UInteger* num;
+   int n;
+   char *p;
+   __code read(__code next(...));
+   __code ret(Impl* cbc_sys_file, UInteger* num);
+   __code next(...);
+} SysRead;
--- a/src/pipe.cbc	Mon Nov 04 17:24:00 2019 +0900
+++ b/src/pipe.cbc	Sat Nov 09 19:56:07 2019 +0900
@@ -20,6 +20,14 @@
     int writeopen;  // write fd is still open
 };
 
+struct PipeRead* create_pipe_read(struct Context* context) {
+    struct SysRead* sys_read = new SysRead();
+    struct PipeRead* pipe_read = new PipeRead();
+    sys_read->sys_read = (union Data*)pipe_read;
+    sys_red->read = C_cbc_piperead;
+    return sys_read;
+}
+
 int pipealloc(struct file **f0, struct file **f1)
 {
     struct pipe *p;
@@ -144,30 +152,30 @@
     goto cbc_wakeup(&p->nwrite, cbc_piperead3);  //DOC: piperead-wakeup
 }
 
-__ncode cbc_piperead1(){
-    struct pipe *p = proc->cbc_arg.cbc_console_arg.p;
+__ncode cbc_piperead1(struct PipeRead* pipe_read){
+    struct pipe *p = pipe_read->pipe;
     __code(*next)(int ret) = proc->cbc_arg.cbc_console_arg.next;
-    if (p->nread == p->nwrite && p->writeopen){
+    if (pipe->nread == pipe->nwrite && pipe->writeopen){
         if(proc->killed){
-            release(&p->lock);
+            release(&pipe->lock);
             goto next(-1);
         }
-        proc->cbc_arg.cbc_console_arg.p = p;
-        goto cbc_sleep(&p->nread, &p->lock, cbc_piperead1);        
+        //pipe_read->pipe = p;
+        goto cbc_sleep(&pipe->nread, &pipe->lock, cbc_piperead1);        
     }
     int i = 0;
-    proc->cbc_arg.cbc_console_arg.i = i;
-    proc->cbc_arg.cbc_console_arg.p = p;
+    pipe_read->i->value = i;
+    //pipe_read->pipe = p;
     goto cbc_piperead2();
 }
 
-__ncode cbc_piperead(struct pipe *p, char *addr, int n, __code (*next)(int ret))
+__ncode cbc_piperead(struct PipeRead* pipe_read, struct pipe *p, char *addr, int n, __code (*next)(int ret))
 {
     acquire(&p->lock);
-    proc->cbc_arg.cbc_console_arg.n = n;
-    proc->cbc_arg.cbc_console_arg.p = p;
-    proc->cbc_arg.cbc_console_arg.addr = addr;
-    proc->cbc_arg.cbc_console_arg.next = next;
+    //proc->cbc_arg.cbc_console_arg.n = n;
+    //proc->cbc_arg.cbc_console_arg.p = p;
+    //proc->cbc_arg.cbc_console_arg.addr = addr;
+    //proc->cbc_arg.cbc_console_arg.next = next;
     goto cbc_piperead1();
 }