annotate src/file_read.cbc @ 146:fd166dda4361

tweak return value at file_read.cbc
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Sun, 15 Dec 2019 14:15:27 +0900
parents f70c4ec3fb8a
children 06449f2ae0c7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
143
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
1 #include "../context.h"
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
2 #interface "SysRead.h"
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
3
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
4 // ----
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
5 // typedef struct FileRead<Type, Isa> impl SysRead {
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
6 // struct file* f;
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
7 // int r;
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
8 // __code cbc_fileread1(Type* file_read, struct file* f,int r,__code next(r,...));
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
9 // __code next(...);
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
10 // } FileRead;
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
11 // ----
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
12
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
13 SysRead* createFileRead(struct Context* cbc_context) {
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
14 struct SysRead* sys_read = new SysRead();
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
15 struct FileRead* file_read = new FileRead();
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
16 sys_read->sys_read = (union Data*)file_read;
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
17 file_read->f = NULL;
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
18 file_read->r = 0;
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
19 sys_read->impl = NULL;
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
20 sys_read->addr = NULL;
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
21 sys_read->n = 0;
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
22 sys_read->read = C_readFileRead;
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
23 sys_read->next = C_nextFileRead;
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
24 return sys_read;
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
25 }
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
26
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
27 SysRead* createFileReadInstFromFile(struct Context* cbc_context, struct file* f,char* addr, int n) {
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
28 if (f->type == FD_PIPE) {
146
fd166dda4361 tweak return value at file_read.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 143
diff changeset
29 return create_piperead(cbc_context, f->pipe, addr, n, next);
143
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
30 }
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
31
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
32 if (f->type == FD_INODE) {
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
33 ilock(f->ip);
146
fd166dda4361 tweak return value at file_read.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 143
diff changeset
34 return create_readi(cbc_context, f->ip, addr, f->off, n, cbc_fileread1);
143
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
35 }
146
fd166dda4361 tweak return value at file_read.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 143
diff changeset
36 return NULL; //Error?
143
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
37 }
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
38
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
39
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
40 __code cbc_fileread1FileRead(struct FileRead* file_read, struct file* f,int r,__code next(r,...)) {
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
41
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
42 goto next(r,...);
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
43 }
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
44
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
45 __code nextFileRead(...) {
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
46
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
47 }
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
48
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
49 __code readFileRead(struct FileRead* sys_read, union Data* impl, char* addr, int n, __code next(int ret,...)) {
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
50
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
51 goto next(int ret,...);
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
52 }
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
53
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
54 __code selectReadInstance(struct file* f) {
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
55 if (f->readable == 0) {
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
56 goto next(-1);
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
57 }
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
58 SysRead* read = createFileReadInstFromFile(proc->cbc_context, f);
146
fd166dda4361 tweak return value at file_read.cbc
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 143
diff changeset
59 goto read->read(f,addr,n);
143
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
60 }
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
61
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
62 __code nextFileRead(...) {
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
63
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
64 }
f70c4ec3fb8a add file_read.cbc (uncomplete)
anatofuz
parents:
diff changeset
65