changeset 152:d3f97de63622

merge from menikon branch
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Mon, 16 Dec 2019 21:55:29 +0900
parents 06449f2ae0c7 (diff) 124c59d99fc9 (current diff)
children 49d8aba0002a
files src/impl/PipeRead.h src/interface/SysRead.h
diffstat 5 files changed, 120 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/file_read.cbc	Mon Dec 16 21:55:29 2019 +0900
@@ -0,0 +1,33 @@
+#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* createFileReadInstFromFile(struct Context* cbc_context, struct file* f,char* addr, int n) {
+   if (f->type == FD_PIPE) {
+       return create_piperead(cbc_context, f->pipe, addr, n, next);
+   }
+
+   if (f->type == FD_INODE) {
+       ilock(f->ip);
+       return create_readi(cbc_context, f->ip, addr, f->off, n, cbc_fileread1);
+   }
+   return NULL; //Error?
+}
+
+__code selectReadInstance(struct Context cbc_context, struct file* f, __code ret(int i)) {
+   if (f->readable == 0) {
+     i = -1;
+     goto ret(i);
+   }
+   SysRead* read = createFileReadInstFromFile(proc->cbc_context, f);
+   goto read->read(f,addr,n);
+}
+
--- a/src/gearsTools/trans_impl.pl	Mon Dec 16 17:36:15 2019 +0900
+++ b/src/gearsTools/trans_impl.pl	Mon Dec 16 21:55:29 2019 +0900
@@ -114,6 +114,12 @@
         }
   }
 
+
+  for my $code (@{$impl_ir->{codes}}) {
+      my $code_gear = $code->{name};
+      print $out "    ${instance_impl}->$code_gear = C_$code_gear$impl_ir->{name};\n"
+  }
+
   for my $code (@{$inter_ir->{codes}}) {
       my $code_gear = $code->{name};
       print $out "    ${instance_inter}->$code_gear = C_$code_gear$impl_ir->{name};\n"
--- a/src/impl/PipeRead.cbc	Mon Dec 16 17:36:15 2019 +0900
+++ b/src/impl/PipeRead.cbc	Mon Dec 16 21:55:29 2019 +0900
@@ -1,11 +1,15 @@
-#include "../context.h";
-#interface "SysRead.h";
+#include "../context.h"
+#interface "SysRead.h"
 
 // ----
 // typedef struct PipeRead<Type, Isa> impl SysRead {
-//   struct CbCPipe *pipe;
-//   struct String *addr;
-//   struct Integer* i;
+//   struct pipe* p;
+//   int i;
+//   int n;
+//   __code cbc_piperead1(Type* sys_read, struct pipe* p, __code next(...));
+//   __code cbc_piperead2(Type* sys_read, int i, int n, struct pipe* p, __code next(...));
+//   __code cbc_piperead3(Type* sys_read, int i, struct pipe* p, __code next(...));
+//   __code next(...);
 // } PipeRead;
 // ----
 
@@ -13,17 +17,73 @@
     struct SysRead* sys_read  = new SysRead();
     struct PipeRead* pipe_read = new PipeRead();
     sys_read->sys_read = (union Data*)pipe_read;
-    pipe_read->num = NULL;
+    pipe_read->p = NULL;
+    pipe_read->i  = 0;
+    pipe_read->n  = 0;
+    sys_read->impl = NULL;
+    sys_read->addr = NULL;
+    sys_read->n  = 0;
+    pipe_read->cbc_piperead1 = C_cbc_piperead1PipeRead;
+    pipe_read->cbc_piperead2 = C_cbc_piperead2PipeRead;
+    pipe_read->cbc_piperead3 = C_cbc_piperead3PipeRead;
+    //pipe_read->next = C_nextPipeRead;
     sys_read->read = C_readPipeRead;
     sys_read->next = C_nextPipeRead;
     return sys_read;
 }
-__code readPipeRead(__code next(...)) {
+
+SysRead* createPipeReadUseArgs(struct Context* cbc_context,struct pipe* p, char* addr, int n) {
+    struct SysRead* sys_read  = new SysRead();
+    struct PipeRead* pipe_read = new PipeRead();
+    sys_read->sys_read = (union Data*)pipe_read;
+
+    pipe_read->p = p;
+    pipe_read->i = 0;
+    pipe_read->n = n;
+
+    sys_read->impl = (union Data*)p;
+    sys_read->addr = addr;
+    sys_read->n    = n;
+
+    pipe_read->cbc_piperead1 = C_cbc_piperead1PipeRead;
+    pipe_read->cbc_piperead2 = C_cbc_piperead2PipeRead;
+    pipe_read->cbc_piperead3 = C_cbc_piperead3PipeRead;
+    //pipe_read->next          = C_nextPipeRead;
 
+    sys_read->read = C_readPipeRead;
+    sys_read->next = C_nextPipeRead;
+    return sys_read;
+}
+
+__code cbc_piperead1PipeRead(struct PipeRead* sys_read, struct pipe* p, __code error(int err), __code next(int i, p,...)) {
+   if (p->nread == p->nwrite && p->writeopen){
+     if(proc->killed){
+         release(&p->lock);
+         goto error(-1);
+     }
+     goto cbc_sleep(&p->nread, &p->lock, cbc_piperead1);
+   }
+  goto next(i,p,...);
+}
+
+__code cbc_piperead2PipeRead(struct PipeRead* sys_read, int i, int n, struct pipe* p,char* addr, __code next(...)) {
+  if (i < n && !(p->nread == p->nwrite)) {
+      addr[i] = p->data[p->nread++ % PIPESIZE];
+      i++;
+      goto sys_read->cbc_piperead2(i,n,p,addr,cbc_wakeup);
+  }
+  goto cbc_wakeup(&p->nwrite, cbc_piperead3);  //DOC: piperead-wakeup
   goto next(...);
 }
 
-__code nextPipeRead(...) {
-
+__code cbc_piperead3PipeRead(struct PipeRead* sys_read, int i, struct pipe* p, __code next(...)) {
+  release(&p->lock);
+  goto sys_read->ret(i,...);
 }
 
+__code readPipeRead(struct PipeRead* sys_read, union Data* impl, char* addr, int n, __code next(int ret,...)) {
+
+  goto next(int ret,...);
+}
+
+
--- a/src/impl/PipeRead.h	Mon Dec 16 17:36:15 2019 +0900
+++ b/src/impl/PipeRead.h	Mon Dec 16 21:55:29 2019 +0900
@@ -1,5 +1,9 @@
 typedef struct PipeRead<Type, Isa> impl SysRead {
-  struct CbCPipe *pipe;
-  struct String *addr;
-  struct Integer* i;
+  struct pipe* p;
+  int i;
+  int n;
+  __code cbc_piperead1(Type* sys_read, struct pipe* p, __code next(...));
+  __code cbc_piperead2(Type* sys_read, int i, int n, struct pipe* p, __code next(...));
+  __code cbc_piperead3(Type* sys_read, int i, struct pipe* p, __code next(...));
+  __code next(...);
 } PipeRead;
--- a/src/interface/SysRead.h	Mon Dec 16 17:36:15 2019 +0900
+++ b/src/interface/SysRead.h	Mon Dec 16 21:55:29 2019 +0900
@@ -1,9 +1,9 @@
 typedef struct SysRead<Type, Impl>{
-   union  Data* sys_read;
-   int num;
+   union Data* sys_read;
+   union Data* impl;
    char* addr;
-   struct file* file;
-   __code read(Impl* sys_read, __code next(...));
-   //__code ret(Impl* cbc_sys_file, UInteger* num);
+   int n;
+
+   __code read(Impl* sys_read, union Data* impl, char* addr, int n, __code next(int ret,...));
    __code next(...);
 } SysRead;