changeset 336:0e1c64818c0d

remove file struct, omit //:skip
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Sat, 15 Feb 2020 21:18:21 +0900
parents 98a9b99df4dc
children cb6045bce1d5
files src/file.cbc src/file.h src/gearsTools/lib/Gears/Context.pm src/gearsTools/lib/Gears/Util.pm src/impl/file_impl_inode.cbc src/impl/file_impl_none.cbc src/impl/file_impl_pipe.cbc src/impl/inode_impl.h src/impl/none.h src/impl/pipe.h src/inode.h src/interface/file.dg src/pipe.cbc src/sysfile.cbc
diffstat 14 files changed, 16 insertions(+), 398 deletions(-) [+]
line wrap: on
line diff
--- a/src/file.cbc	Sat Feb 15 20:23:55 2020 +0900
+++ b/src/file.cbc	Sat Feb 15 21:18:21 2020 +0900
@@ -12,8 +12,6 @@
 
 #define __ncode __code
 
-// data_gear "file.dg"
-
 struct devsw devsw[NDEV];
 struct cbc_devsw cbc_devsw[NDEV];
 
--- a/src/file.h	Sat Feb 15 20:23:55 2020 +0900
+++ b/src/file.h	Sat Feb 15 21:18:21 2020 +0900
@@ -1,5 +1,4 @@
-/*
-typedef struct file {
+struct file {
     enum { FD_NONE, FD_PIPE, FD_INODE } type;
     int          ref;   // reference count
     char         readable;
@@ -7,11 +6,9 @@
     struct pipe  *pipe;
     struct inode *ip;
     uint         off;
-} file;
-*/
+};
 // in-memory copy of an inode
 
-/*
 struct inode {
     uint    dev;        // Device number
     uint    inum;       // Inode number
@@ -25,7 +22,6 @@
     uint    size;
     uint    addrs[NDIRECT+1];
 };
-*/
 
 #define I_BUSY 0x1
 #define I_VALID 0x2
--- a/src/gearsTools/lib/Gears/Context.pm	Sat Feb 15 20:23:55 2020 +0900
+++ b/src/gearsTools/lib/Gears/Context.pm	Sat Feb 15 21:18:21 2020 +0900
@@ -5,7 +5,7 @@
 
 use Gears::Util;
 use Gears::Context::Template::XV6;
-use Carp qw/croak/;
+use Carp qw/croak carp/;
 
 sub new {
   my ($class, %args) = @_;
@@ -52,7 +52,8 @@
   for my $kind (keys %$dgs) {
     map {
       if ($new_dgs->{$kind}->{$_} =~ /^\d+$/) {
-        croak "failed: not found $_.(h|dg)\n";
+        carp "failed: not found $_.(h|dg)\n";
+        delete $new_dgs->{$kind}->{$_};
       }
     } keys %{$new_dgs->{$kind}};
   }
@@ -105,14 +106,16 @@
   print Dumper $dg2path;
   print Dumper  $self;
 
-  map { $dg_str{$_}->{elem} = Gears::Util->parse_interface($inters->{$_}) } keys %$inters;
+  map {  my $ir = Gears::Util->parse_interface($inters->{$_});   $dg_str{$_}->{elem} = $ir if $ir} keys %$inters;
 
   map {
     my $res = Gears::Util->parse($impls->{$_});
-    if ($res->{isa}) {
-        $dg_str{$res->{isa}}->{impl}->{$_} = $res;
-    } else {
-        $dg_str{$_}->{elem} = $res;
+    if ($res) {
+      if ($res->{isa}) {
+          $dg_str{$res->{isa}}->{impl}->{$_} = $res;
+      } else {
+          $dg_str{$_}->{elem} = $res;
+      }
     }
   } keys %$impls;
   return \%dg_str;
--- a/src/gearsTools/lib/Gears/Util.pm	Sat Feb 15 20:23:55 2020 +0900
+++ b/src/gearsTools/lib/Gears/Util.pm	Sat Feb 15 21:18:21 2020 +0900
@@ -41,6 +41,10 @@
     }
   }
 
+  unless ($ir->{name}) {
+    return undef;
+  }
+
   my @tmp_args;
   while ($line = <$fh>) {
     if ($line =~ m|\s*/\*|) {
--- a/src/impl/file_impl_inode.cbc	Sat Feb 15 20:23:55 2020 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,48 +0,0 @@
-#include "../../context.h"
-#interface "file.dg"
-
-
-// ----
-// typedef struct inode_impl<Impl, Isa> impl file {
-//
-// } inode_impl;
-// ----
-
-file* createinode(struct Context* cbc_context) {
-    struct file* file  = new file();
-    struct inode_impl* inode_impl = new inode_impl();
-    file->file = (union Data*)inode_impl;
-    inode_impl->st = NULL;
-    inode_impl->ip = NULL;
-    file->stat = C_statinode;
-    inode_impl->cbc_statinode = C_cbc_statinode_impl;
-    file->read = C_readinode;
-    file->write = C_writeinode;
-    file->close = C_closeinode;
-    return file;
-}
-__code statinode(struct inode* ip, struct stat* st, __code next(int ret, ...)) { //:skip
-
-    goto cbc_statinode(ip, st, next(ret, ...));
-}
-
-__code cbc_statinode_impl(struct inode* ip, struct stat* st, __code next(int ret, ...)){
-
-    goto next(...);
-}
-
-__code readinode(struct inode* file, char* addr, __code next(...)) {
-
-    goto next(...);
-}
-
-__code writeinode(struct inode* file, char* addr, int n, __code next(...)) {
-
-    goto next(...);
-}
-
-__code closeinode(struct inode* file,int fd, __code next(...)) {
-
-    goto next(...);
-}
-
--- a/src/impl/file_impl_none.cbc	Sat Feb 15 20:23:55 2020 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,64 +0,0 @@
-#include "../context.h"
-#interface "file.h"
-
-// ----
-// typedef struct none<Impl, Isa> impl file {
-//
-// } none;
-// ----
-
-file* createnone(struct Context* cbc_context) {
-    struct file* file  = new file();
-    struct none* none = new none();
-    file->file = (union Data*)none;
-    file->remoe  = 0;
-    file->off = 0;
-    file->st = NULL;
-    file->addr = NULL;
-    file->pipe  = 0;
-    file->inode  = 0;
-    file->n  = 0;
-    file->fd  = 0;
-    file->stat = C_statnone;
-    file->read = C_readnone;
-    file->write = C_writenone;
-    file->close = C_closenone;
-    return file;
-}
-__code statnone(struct none* file, struct stat* st, __code next(...)) {
-
-    goto next(...);
-}
-
-__code readnone(struct none* file, char* addr, __code next(...)) {
-
-    goto next(...);
-}
-
-__code writenone(struct none* file, char* addr, int n, __code next(...)) {
-
-    goto next(...);
-}
-
-__code closenone(struct none* file,int fd, __code next(...)) {
-
-    goto file->noneclose(file->file, next);
-}
-
-__code noneclose(struct none* none, struct file* file, __code next(...){
-  struct file ff;
-  acquire(*ftable.loc)
-
-  if (f->ref < 1) {
-     goto cbc_context->kernel_error->panic("file close");
-  }
-  goto pipe->cbc_noneclose2(f,ff,next);
-}
-
-__code noneclose2(struct none* none,struct file* file, struct file* ff,__code next(...)){
-  if (--f->ref > 0) {
-     release(&ftable.lock);
-     goto cbc_context->return();
-  }
-  goto pipe->cbc_pipeclose3(f,ff,next);
-}
--- a/src/impl/file_impl_pipe.cbc	Sat Feb 15 20:23:55 2020 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,191 +0,0 @@
-#include "../../context.h"
-#interface "file.h"
-
-// ----
-// typedef struct pipe<Impl, Isa> impl file {
-//     #define PIPESIZE 512
-//     union Data* file;
-//     struct spinlock lock;
-//     char data[PIPESIZE];
-//     uint nread;     // number of bytes read
-//     uint nwrite;    // number of bytes written
-//     int readopen;   // read fd is still open
-//     int writeopen;  // write fd is still open
-//
-//     int          ref;   // reference count
-//     char         readable;
-//     char         writable;
-//     unsigned int off;
-//
-//     // interface field
-//     int n;
-//     char* addr;
-//
-//     // private code gear
-//     __code piperead1(Impl* pipe, char* addr, int n, __code next(...));
-//     __code piperead2(Impl* pipe, char* addr, int n, __code next(...));
-//     __code cbc_pipeclose(Impl* pipe, Isa* file, __code next(...));
-//     __code cbc_pipeclose2(Impl* pipe, Isa* file, Isa* ff,  __code next(...));
-//     __code cbc_pipeclose3(Impl* pipe, Isa* file, Isa* ff,  __code next(...));
-//     __code cbc_pipeclose4(Impl* pipe, int writable, __code next(...));
-//     __code cbc_pipe_close_writeopen(Impl* pipe, __code next(...));
-//     __code cbc_pipe_close_readopen(Impl* pipe, __code next(...));
-// } pipe;
-// ----
-
-file* createpipe(struct Context* cbc_context) {
-    //initialize
-    struct file* file  = new file();
-    struct pipe* pipe = new pipe();
-    file->file = (union Data*)pipe;
-    pipe->file = (union Data*)file;
-
-    //assign
-    pipe->lock = 0;
-    pipe->spinlock  = 0;
-    pipe->data  = 0;
-    pipe->nread  = 0;
-    pipe->nwrite  = 0;
-    pipe->readopen  = 0;
-    pipe->writeopen  = 0;
-    pipe->ref  = 0;
-    pipe->readable  = 0;
-    pipe->writable  = 0;
-    pipe->off = 0;
-    pipe->int  = 0;
-    pipe->n  = 0;
-    pipe->addr = NULL;
-
-    /*
-    API
-    file->st = NULL;
-    file->addr = NULL;
-    file->n  = 0;
-    file->fd  = 0;
-    */
-
-    // CodeGear Init
-    pipe->piperead1 = C_piperead1pipe;
-    pipe->piperead2 = C_piperead2pipe;
-    pipe->cbc_pipeclose = C_cbc_pipeclosepipe;
-    pipe->cbc_pipeclose2 = C_cbc_pipeclose2pipe;
-    pipe->cbc_pipeclose3 = C_cbc_pipeclose3pipe;
-    pipe->cbc_pipeclose4 = C_cbc_pipeclose4pipe;
-    pipe->cbc_pipe_close_writeopen = C_cbc_pipe_close_writeopenpipe;
-    pipe->cbc_pipe_close_readopen = C_cbc_pipe_close_readopenpipe;
-    file->read = C_readpipe;
-    file->write = C_writepipe;
-    file->close = C_closepipe;
-    return file;
-}
-
-
-__code statpipe(struct pipe* file, struct stat* st, __code next(...)) { //:skip
-
-    goto next(...);
-}
-
-__code readpipe(struct pipe* file, char* addr, int n, __code next(...)) {
-    acquire(&p->lock);
-    goto cbc_piperead1(file,addr,n,next);
-}
-
-__code piperead1(struct pipe* p, char* addr, int n, __code next(...)) {
-    if (p->nread == p->nwrite && p->writeopen){
-        goto cbc_piperead2(p,addr,n,next);
-    }
-    n = 0;
-    goto cbc_piperead3(p,addr,n,next);
-}
-
-__code piperead2(struct pipe* p, char* addr, int n, __code next(...)) {
-    if(proc->killed){
-        release(&p->lock);
-        goto cbc_context->error();
-    }
-    goto cbc_sleep(p,&p->nread, &p->lock, next,cbc_piperead1);
-}
-
-
-__code cbc_sleep(struct pipe* p, unit* nread, struct spinlock* lock, __code next(...), __code pread(...)){ //:skip
-    if(proc == 0) {
-        goto cbc_context->panic("sleep");
-    }
-
-    if(lk == 0) {
-        goto cbc_context->panic("sleep without lk");
-    }
-
-    if(lk != &ptable.lock){  //DOC: sleeplock0
-        acquire(&ptable.lock);  //DOC: sleeplock1
-        release(lk);
-    }
-    goto cbc_sched(cbc_sleep1);
-}
-
-__code cbc_sched_stub(struct pipe* p, unit* nread, struct spinlock* lock, __code next(...), __code pread(...)){ //:skip
-    proc->chan = chan;
-    proc->state = SLEEPING;
-    proc->lk = lk;
-    proc->cbc_next = next1;
-}
-
-__code writepipe(struct pipe* file, char* addr, int n, __code next(...)) {
-
-    goto next(...);
-}
-
-__code pipeclose(struct pipe* file,int fd,__code next(...)) {
-    proc->ofile[fd] = 0;
-    goto file->cbc_pipeclose(file->file, next);
-}
-
-
-__code cbc_pipeclose(struct pipe* pipe, struct file* file, __code next(...)) {
-    struct file ff;
-    acquire(*ftable.loc)
-
-    if (f->ref < 1) {
-        goto cbc_context->kernel_error->panic("file close");
-    }
-    goto pipe->cbc_pipeclose2(f,ff,next);
-}
-
-__code cbc_pipeclose2(struct pipe* pipe,struct file* file, struct file* ff,__code next(...)) {
-    if (--f->ref > 0) {
-        release(&ftable.lock);
-        goto cbc_context->return();
-    }
-    goto pipe->cbc_pipeclose3(f,ff,next);
-}
-
-__code cbc_pipeclose3(struct pipe* pipe,struct file* file, struct file* ff,__code next(...)) {
-    *ff = *f;
-    f->ref = 0;
-    f->type = FD_NONE;
-    relsease(&ftable.lock);
-    struct pipe* p = ff.pipe;
-    int writable = ff.writable;
-    
-    goto pipe->cbc_pipeclose4(p,writable,next);
-}
-
-__code cbc_pipeclose4(struct pipe* pipe, int writable, __code next(...)) {
-    acquire(&pipe->lock);
-    if (writable) {
-        goto pipe->cbc_pipe_close_writeopen(next);
-    }
-    goto pipe->cbc_pipe_close_readopen(next);
-}
-
-
-__code cbc_pipe_close_writeopen(struct pipe* pipe, __code next(...)) {
-    pipe->writeopen = 0;
-    goto cbc_wakeup(&pipe->nread,pipe,cbc_pipe_release,next);
-}
-
-__code cbc_pipe_close_readopen(struct pipe* pipe, __code next(...)) {
-    pipe->readopen = 0;
-    goto cbc_context->wakeup(&pipe->nwrite,pipe,cbc_pipe_release,next);
-}
-
--- a/src/impl/inode_impl.h	Sat Feb 15 20:23:55 2020 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,11 +0,0 @@
-typedef struct inode_impl<Impl, Isa> impl file {
-
-struct inode* ip;
-struct stat* st;
-int ret;
-
-__code cbc_statinode(struct inode* ip, struct stat* st, __code next(int ret, ...));
-
-//__code next(...);
-
-} inode_impl;
--- a/src/impl/none.h	Sat Feb 15 20:23:55 2020 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,3 +0,0 @@
-typedef struct none<Impl, Isa> impl file {
-
-} none;
--- a/src/impl/pipe.h	Sat Feb 15 20:23:55 2020 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,31 +0,0 @@
-typedef struct pipe<Impl, Isa> impl file {
-    #define PIPESIZE 512
-    union Data* file;
-    struct spinlock lock;
-    char data[PIPESIZE];
-    uint nread;     // number of bytes read
-    uint nwrite;    // number of bytes written
-    int readopen;   // read fd is still open
-    int writeopen;  // write fd is still open
-
-    int ref;   // reference count
-    /*
-    char readable;
-    char writable;
-    */
-    unsigned int off;
-
-    // interface field
-    int n;
-    char* addr;
-
-    // private code gear
-    __code piperead1(Impl* pipe, char* addr, int n, __code next(...));
-    __code piperead2(Impl* pipe, char* addr, int n, __code next(...));
-    __code cbc_pipeclose(Impl* pipe, Isa* file, __code next(...));
-    __code cbc_pipeclose2(Impl* pipe, Isa* file, Isa* ff,  __code next(...));
-    __code cbc_pipeclose3(Impl* pipe, Isa* file, Isa* ff,  __code next(...));
-    __code cbc_pipeclose4(Impl* pipe, int writable, __code next(...));
-    __code cbc_pipe_close_writeopen(Impl* pipe, __code next(...));
-    __code cbc_pipe_close_readopen(Impl* pipe, __code next(...));
-} pipe;
--- a/src/inode.h	Sat Feb 15 20:23:55 2020 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,13 +0,0 @@
-typedef struct inode <Impl, Isa> impl file {
-    uint    dev;        // Device number
-    uint    inum;       // Inode number
-    int     ref;        // Reference count
-    int     flags;      // I_BUSY, I_VALID
-
-    short   type;       // copy of disk inode
-    short   major;
-    short   minor;
-    short   nlink;
-    uint    size;
-    uint    addrs[NDIRECT+1];
-} inode;
--- a/src/interface/file.dg	Sat Feb 15 20:23:55 2020 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,20 +0,0 @@
-typedef struct file <Impl> {
-    union Data* file;
-    union Data* inode_impl;
-    enum { FD_NONE, FD_PIPE, FD_INODE } type;
-    int ref;   // reference count
-    char readable;
-    char writable;
-    struct pipe  *pipe;
-    struct inode *ip;
-    unsigned int off;
-    struct stat* st;
-    char* addr;
-    int n;
-    int fd;
-    __code stat(struct inode* ip, struct stat* st, __code next(...));
-    __code read(Impl* file, char* addr, __code next(...));
-    __code write(Impl* file, char* addr, int n, __code next(...));
-    __code close(Impl* file,int fd, __code next(...));
-    __code next(...);
-} file;
--- a/src/pipe.cbc	Sat Feb 15 20:23:55 2020 +0900
+++ b/src/pipe.cbc	Sat Feb 15 21:18:21 2020 +0900
@@ -10,7 +10,6 @@
 #define PIPESIZE 512
 
 #define __ncode __code
-// data_gear "pipe.h"
 
 /*
 struct pipe {
--- a/src/sysfile.cbc	Sat Feb 15 20:23:55 2020 +0900
+++ b/src/sysfile.cbc	Sat Feb 15 21:18:21 2020 +0900
@@ -14,7 +14,6 @@
 #include "file.h"
 #include "fcntl.h"
 
-//data_gear "inode.h"
 
 #define __ncode __code