changeset 346:36ed64fea8c1

emit context.h
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Mon, 02 Mar 2020 14:19:49 +0900
parents efef0767b1bc
children ea5ee6e71a3b
files src/data_gear/file.dg src/data_gear/inode.h src/gearsTools/generate_context.pl src/gearsTools/lib/Gears/Context.pm src/interface/io.h
diffstat 5 files changed, 39 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/data_gear/file.dg	Mon Mar 02 14:19:49 2020 +0900
@@ -0,0 +1,9 @@
+typedef struct file <DATA> { 
+  enum { FD_NONE, FD_PIPE, FD_INODE } type;
+  int          ref;   // reference count
+  char         readable;
+  char         writable;
+  struct pipe  *pipe;
+  struct inode *ip;
+  uint         off;
+} file;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/data_gear/inode.h	Mon Mar 02 14:19:49 2020 +0900
@@ -0,0 +1,16 @@
+typedef struct inode <DATA> {
+#ifndef INODE_STRUCT
+    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];
+#define INODE_STRUCT
+#endif
+} inode;
--- a/src/gearsTools/generate_context.pl	Sun Mar 01 18:10:05 2020 +0900
+++ b/src/gearsTools/generate_context.pl	Mon Mar 02 14:19:49 2020 +0900
@@ -132,7 +132,12 @@
         if (/struct (\w+) \{/) {
             $dataGear{$1} = 'struct';
         } elsif (/^\s{4}(\w+) (\w+);/) { # primitive type
-            $dataGear{$1} = 'primitive';
+            my $vtype = $1;
+            my $vname = $2;
+            if (exists $dataGear{$vname}) {
+              next;
+            }
+            $dataGear{$vtype} = 'primitive';
         }
         $dataGear{"Context"} = "struct";
     }
--- a/src/gearsTools/lib/Gears/Context.pm	Sun Mar 01 18:10:05 2020 +0900
+++ b/src/gearsTools/lib/Gears/Context.pm	Mon Mar 02 14:19:49 2020 +0900
@@ -165,6 +165,8 @@
 
   $context .= "${space}} $h2context->{name};\n";
   $context .= "#define ". uc($h2context->{name}) ."_STRUCT \n";
+  $context .= "#else\n";
+  $context .=  "${space}struct $h2context->{name};\n";
   $context .= "#endif\n";
   return $context;
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/interface/io.h	Mon Mar 02 14:19:49 2020 +0900
@@ -0,0 +1,6 @@
+typedef struct IO <Type, Impl> {
+    __code read(Impl* io, char* addr, __code next(...));
+    __code write(Impl* io, char* addr, int n, __code next(...));
+    __code close(Impl* io,int fd, __code next(...));
+    __code next(...);
+} IO;