From e9ff1c6fbbbac9ece2604876ab589ac282360446 Mon Sep 17 00:00:00 2001 From: Nicholas Date: Mon, 15 Nov 2021 15:08:03 -0800 Subject: Feat: added if/else branching and switch statement Unsure about my modification to the language. I found the parsing of the case body within switches to be odd - specifically that it parses liberally and then checks that it has case -> cmd structuring while it walks the code. This means the language is more permissive than the semantics. I modified it to be more explicit, but at the cost of having to end each case statement with a semicolon. I wanted a colon, but this is a valid word character and thus will be lexed as part of the word. --- src/cmd/rc/wait.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'src/cmd/rc/wait.c') diff --git a/src/cmd/rc/wait.c b/src/cmd/rc/wait.c index 911601c..295cc57 100644 --- a/src/cmd/rc/wait.c +++ b/src/cmd/rc/wait.c @@ -10,7 +10,11 @@ struct WaitMsg int pid; int type; ulong time[3]; - int status; + struct{ + int code; + char *str; + }status; + char *str; }; // ----------------------------------------------------------------------- @@ -44,9 +48,11 @@ await(int pid4, int opt, struct WaitMsg *msg) msg->time[0] = u; msg->time[1] = s; msg->time[2] = u+s; - msg->status = WEXITSTATUS(status); msg->type = Pdone; + msg->status.code = WEXITSTATUS(status); + msg->status.str = nil; + return 1; } @@ -55,9 +61,11 @@ await(int pid4, int opt, struct WaitMsg *msg) msg->time[0] = u; msg->time[1] = s; msg->time[2] = u+s; - msg->status = WTERMSIG(status); msg->type = Psig; + msg->status.code = WTERMSIG(status); + msg->status.str = nil; + return 1; } @@ -66,7 +74,8 @@ await(int pid4, int opt, struct WaitMsg *msg) msg->time[0] = u; msg->time[1] = s; msg->time[2] = u+s; - msg->status = WSTOPSIG(status); + msg->status.code = WSTOPSIG(status); + msg->status.str = nil; msg->type = Pstop; return 1; @@ -88,22 +97,23 @@ shouldwait(Thread *job) return 0; } -static inline -void +static inline void notify(Thread *job, struct WaitMsg msg) { int i; for(i=0; i < job->wait.len; i++){ if(job->wait.on[i].pid == msg.pid){ - job->status = msg.status; + job->status = msg.status.code; switch(msg.type){ case Pstop: + /* NOTE: this needs to have an interactive check */ print(shell.err, "%d: suspended\n", msg.pid); job->wait.status = Pstop; job->wait.on[i].status = Pstop; break; case Psig: + /* NOTE: this needs to have an interactive check */ print(shell.err, "%d: terminated by signal %d\n", msg.pid, msg.status); /* fallthrough */ case Pdone: @@ -114,6 +124,7 @@ notify(Thread *job, struct WaitMsg msg) break; default: + /* NOTE: this needs to have an interactive check */ fatal("%d: unrecognized message type %d\n", msg.pid, msg.type); } break; -- cgit v1.2.1