Skip to content

Commit

Permalink
Align sleep and msleep definitions in XS:Lisp with the underlying OS
Browse files Browse the repository at this point in the history
  • Loading branch information
mesheets committed Jul 23, 2024
1 parent 98d0ea7 commit 6985856
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 7 deletions.
2 changes: 1 addition & 1 deletion demo/xs-lisp/hello-xsLisp.lsp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
(putc :char-E 3)
(putc :char-Parallel 2)
(putc :char-O 1)
(sleep 1)
(msleep 1000)

(putc :char-L 4)
(putc :char-E 3)
Expand Down
6 changes: 5 additions & 1 deletion xs/README
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,11 @@ predefined functions:
In 1/10 secs. Overflows in about 13 minutes.

(SLEEP int)
In 1/10 secs.
In seconds.
Returns the argument.

(MSLEEP int)
In 1/10 second.
Returns the argument.

(READ)
Expand Down
39 changes: 34 additions & 5 deletions xs/lisp/eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -1435,17 +1435,46 @@ object eval(object e) {
ts = INTval(e = base[0]);
#ifdef RCX
while (ts-- > 0) {
if (interrupted()) goto LERROR;
msleep(100);
for (int i = 0; i < 10; i++) {
if (interrupted()) goto LERROR;
msleep(100);
}
}
#else
#ifdef JOINT
while (ts-- > 0) {
for (int i = 0; i < 10; i++) {
if (interrupted()) goto LERROR;
usleep(100000);
}
}
#endif
usleep(ts*1000000);
#endif
break;
}
case Lmsleep: {
int ts;
if (check_int_args(base)) goto LERROR;
ts = INTval(e = base[0]);
#ifdef RCX
while (ts > 0) {
if (interrupted()) goto LERROR;
if (ts >= 100) {
msleep(100);
} else {
msleep(ts);
}
ts -= 100;
}
#else
#ifdef JOINT
while (ts-- > 0) {
if (interrupted()) goto LERROR;
usleep(100000);
if (interrupted()) goto LERROR;
usleep(1000);
}
#endif
usleep(ts*100000);
usleep(ts*1000);
#endif
break;
}
Expand Down
1 change: 1 addition & 0 deletions xs/lisp/front.c
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,7 @@ void initGlobals() {
def("reset-time", MKCONST(Lreset_time,0,0,0));
def("time", MKCONST(Ltime,0,0,0));
def("sleep", MKCONST(Lsleep,1,0,0));
def("msleep", MKCONST(Lmsleep,1,0,0));
def("linked?", MKCONST(Llinked,0,0,0));
def("read", MKCONST(Lread,0,1,0));
def("read-char", MKCONST(Lread_char,0,1,0));
Expand Down
1 change: 1 addition & 0 deletions xs/lisp/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ typedef enum {
Lreset_time,
Ltime,
Lsleep,
Lmsleep,
Llinked,
Lread,
Lwrite,
Expand Down
1 change: 1 addition & 0 deletions xs/lisp/wtobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ char *subr_name(int index) {
case Lreset_time: return "reset-time";
case Ltime: return "time";
case Lsleep: return "sleep";
case Lmsleep: return "msleep";
case Llinked: return "linked?";
case Lread: return "read";
case Lwrite: return "write";
Expand Down

0 comments on commit 6985856

Please sign in to comment.