# HG changeset patch # User anatofuz # Date 1594036345 -32400 # Node ID 097a58a16a047396254612989d16133fdd324b9e # Parent 6fc38a3f38f92c0b786717ad8cb8516b8650285a remove IO* diff -r 6fc38a3f38f9 -r 097a58a16a04 src/impl/ConsoleIO.cbc --- a/src/impl/ConsoleIO.cbc Mon Jul 06 11:25:47 2020 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,104 +0,0 @@ -#include "../context.h" -#interface "IO.h" - -// ---- -// typedef struct ConsoleIO impl IO { -// __code consoleread(Type* IO, struct inode* ip, char* dst, int n, __code next(...)); -// __code consoleread1(Type* IO, int n, int target, char* dst, struct inode* ip, __code next(...)); -// __code consoleread2(Type* IO, struct inode* ip, __code next(...)); -// __code next(....); -// } ConsoleIO; -// ---- - -IO* createConsoleIO(struct Context* cbc_context) { - struct IO* io = new IO(); - struct ConsoleIO* console_io = new ConsoleIO(); - io->io = (union Data*)console_io; - console_io->IO = NULL; - console_io->ip = NULL; - console_io->dst = NULL; - console_io->n = 0; - console_io->target = 0; - console_io->consoleread = C_consoleread; - console_io->consoleread1 = C_consoleread1; - console_io->consoleread2 = C_consoleread2; - io->read = C_readConsoleIO; - io->write = C_writeConsoleIO; - io->close = C_closeConsoleIO; - return io; -} - -__code readConsoleIO(struct ConsoleIO* io, struct file* file, char* addr, int n, __code next(...)) { - struct inode* ip = file->ip; - // args should be assigned to the impl structure - goto io->consoleread(__code next(...)); -} - -__code consoleread(struct ConsoleIO* io, struct inode* ip, char* dst, int n, __code next(...)) { - uint target; - - iunlock(ip); - - target = n; - acquire(&input.lock); - - if (n > 0) { - goto io->consoleread2(io, n, ip, target, dst, ip, next); - } - goto io->consoleread1(io, n, target, dst, ip, next); -} - -__code consoleread1(struct ConsoleIO* io, int n, int target, char* dst, struct inode* ip, __code next(...)) { - int c = input.buf[input.r++ % INPUT_BUF]; - - if (c == C('D')) { // EOF - if (n < target) { - // Save ^D for next time, to make sure - // caller gets a 0-byte result. - input.r--; - } - cont = 0; - } - - *dst++ = c; - --n; - - if (c == '\n') { - cont = 0; - } - - if (cont == 1) { - if (n > 0) { - goto cbc_sleep(&input.r, &input.lock, cbc_consoleread2); - } - } - - release(&input.lock); - ilock(ip); - - goto next(target - n); -} - -__code consoleread2(struct ConsoleIO* io, struct inode* ip, __code next(...)) { - if (input.r == input.w) { // input is global variable - if (proc->killed) { - release(&input.lock); - ilock(ip); - goto next(-1); - } - goto cbc_sleep(&input.r, &input.lock, cbc_consoleread2); - } - goto io->consoleread1(); -} - - -__code writeConsoleIO(struct ConsoleIO* io, struct file* file, char* addr, int n, __code next(...)) { - - goto next(...); -} - -__code closeConsoleIO(struct ConsoleIO* io, struct file* file, int fd, __code next(...)) { - - goto next(...); -} - diff -r 6fc38a3f38f9 -r 097a58a16a04 src/impl/ConsoleIO.h --- a/src/impl/ConsoleIO.h Mon Jul 06 11:25:47 2020 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -typedef struct ConsoleIO impl IO { - __code consoleread(Type* io, struct inode* ip, char* dst, int n, __code next(...)); - __code consoleread1(Type* io, int n, int target, char* dst, struct inode* ip, __code next(...)); - __code consoleread2(Type* io, struct inode* ip, __code next(...)); - __code next(....); -} ConsoleIO; diff -r 6fc38a3f38f9 -r 097a58a16a04 src/interface/IO.h --- a/src/interface/IO.h Mon Jul 06 11:25:47 2020 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -typedef struct IO { - __code read(Impl* io, struct file* file, char* addr, int n, __code next(...)); - __code write(Impl* io, struct file* file, char* addr, int n, __code next(...)); - __code close(Impl* io, struct file* file, int fd, __code next(...)); - __code next(...); -} IO;