changeset 109:4f9d95dc4efd

fix createInstance
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Thu, 21 Nov 2019 21:10:25 +0900
parents 8162269b5682
children 8c7c1ea49f21
files src/context.h src/file.cbc src/gearsTools/trans_impl.pl src/impl/FileRead.cbc src/impl/FileRead.h
diffstat 5 files changed, 64 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/context.h	Thu Nov 21 17:25:11 2019 +0900
+++ b/src/context.h	Thu Nov 21 21:10:25 2019 +0900
@@ -472,9 +472,6 @@
     struct String {
       char* string;
     } String;
-    struct SysFileRead {
-        struct file *f;
-    } SysFileRead;
     struct CbCPipe {
         struct pipe *p;
     } CbCPipe;
@@ -491,6 +488,9 @@
         enum Code read;
         enum Code next;
     } SysRead;
+    struct FileRead {
+        struct file *f;
+    } FileRead;
 }; // union Data end       this is necessary for cbc_context generator
 
 /*
--- a/src/file.cbc	Thu Nov 21 17:25:11 2019 +0900
+++ b/src/file.cbc	Thu Nov 21 21:10:25 2019 +0900
@@ -11,7 +11,6 @@
 #include "proc.h"
 
 #define __ncode __code
-#
 
 #interface "SysRead.h"
 
@@ -29,13 +28,14 @@
     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;
+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;
+    sys_read->num = NULL;
+    sys_read->read = C_readFileRead;
+    sys_read->next = C_nextFileRead;
     return sys_read;
 }
 
@@ -235,3 +235,13 @@
     }
 
     panic("filewrite");
+}
+
+__code readFileRead(__code next(...)) {
+
+  goto next(...);
+}
+
+__code nextFileRead(...) {
+
+}
--- a/src/gearsTools/trans_impl.pl	Thu Nov 21 17:25:11 2019 +0900
+++ b/src/gearsTools/trans_impl.pl	Thu Nov 21 21:10:25 2019 +0900
@@ -54,6 +54,7 @@
   my ($out, $impl_ir, $inter_ir) = @_;
 
   my @inter_data = @{$inter_ir->{data}};
+  my @impl_data = @{$impl_ir->{data}};
   my $instance_inter = shift @inter_data;
   if ($instance_inter =~ /union\s*Data\*\s*(\w+)/) {
     $instance_inter = $1;
@@ -68,7 +69,7 @@
     $instance_inter->$instance_inter = (union Data*)$instance_impl;
 EOF
 
-  for my $datum (@inter_data) {
+  for my $datum (@impl_data) {
         if ($datum =~ /\w+ \w+\* (\w+)/) {
             print $out "    ${instance_impl}->$1 = NULL;\n";
             next;
@@ -78,6 +79,16 @@
         }
   }
 
+  for my $datum (@inter_data) {
+        if ($datum =~ /\w+ \w+\* (\w+)/) {
+            print $out "    ${instance_inter}->$1 = NULL;\n";
+            next;
+        }
+        if ($datum =~ /\w+ \w+ (\w+)/) {
+            print $out "    ${instance_inter}->$1 = 0;\n";
+        }
+  }
+
   for my $code (@{$inter_ir->{codes}}) {
       my $code_gear = $code->[0];
       print $out "    ${instance_inter}->$code_gear = C_$code_gear$impl_ir->{name};\n"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/impl/FileRead.cbc	Thu Nov 21 21:10:25 2019 +0900
@@ -0,0 +1,28 @@
+#include "../context.h";
+#interface "SysRead.h";
+
+// ----
+// typedef struct FileRead<Type, Isa> impl SysRead {
+//   struct file* f;
+// } 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;
+    sys_read->num = NULL;
+    sys_read->read = C_readFileRead;
+    sys_read->next = C_nextFileRead;
+    return sys_read;
+}
+__code readFileRead(__code next(...)) {
+
+  goto next(...);
+}
+
+__code nextFileRead(...) {
+
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/impl/FileRead.h	Thu Nov 21 21:10:25 2019 +0900
@@ -0,0 +1,3 @@
+typedef struct FileRead<Type, Isa> impl SysRead {
+  struct file* f;
+} FileRead;