2019-02-04 02:04:02 +00:00
|
|
|
: stdout ' putc task-emit ! ;
|
2019-02-09 16:48:40 +00:00
|
|
|
s" jorth.log" open const LOGFILE
|
2019-02-04 02:04:02 +00:00
|
|
|
: log-emit LOGFILE fputc ;
|
|
|
|
|
2019-02-09 16:48:40 +00:00
|
|
|
' cells @ const docolon ( get the colon execution token )
|
|
|
|
: :noname here docolon , ] ;
|
|
|
|
|
2019-02-02 20:30:18 +00:00
|
|
|
: 2dup over over ;
|
2019-02-11 00:17:58 +00:00
|
|
|
: noop ;
|
|
|
|
|
2019-02-12 04:23:00 +00:00
|
|
|
|
2019-02-11 00:17:58 +00:00
|
|
|
: defer word new-word docolon , ' noop , ' ret , ;
|
2019-02-12 04:23:00 +00:00
|
|
|
: redefine ( cp cpdeferred ) cell + ! ;
|
2019-02-02 20:30:18 +00:00
|
|
|
|
|
|
|
: decompile
|
2019-02-04 02:04:02 +00:00
|
|
|
word lookup if 1 begin ( cp i )
|
2019-02-02 20:30:18 +00:00
|
|
|
2dup cells + @ ( cp i @cp+i )
|
2019-02-04 02:04:02 +00:00
|
|
|
dup ' ret != ( cp i @cp+i bool )
|
2019-02-02 20:30:18 +00:00
|
|
|
while
|
2019-02-04 02:04:02 +00:00
|
|
|
dup ` dup if type drop else drop . then bl ( cp i )
|
2019-02-02 20:30:18 +00:00
|
|
|
1 + ( cp i+1 )
|
2019-02-04 02:04:02 +00:00
|
|
|
repeat drop drop then drop ;
|
|
|
|
|
|
|
|
( tasks )
|
|
|
|
: mailbox 2 cells + ;
|
|
|
|
: task-ip task-user-size cells + ;
|
|
|
|
: task-sp task-user-size 1 + cells + ;
|
|
|
|
: task-rsp task-user-size 2 + cells + ;
|
|
|
|
: task-stack task-user-size 3 + cells + ;
|
|
|
|
: task-rstack task-stack stacksize cells + ;
|
|
|
|
|
|
|
|
: doactivate ( task ip -- )
|
|
|
|
over task-ip !
|
|
|
|
dup task-stack over task-sp !
|
|
|
|
dup task-rstack over task-rsp !
|
|
|
|
drop
|
|
|
|
;
|
|
|
|
|
|
|
|
: activate
|
|
|
|
here 4 cells + lit
|
|
|
|
' doactivate ,
|
|
|
|
' ret ,
|
|
|
|
; immediate
|
|
|
|
|
|
|
|
: send ( val task -- )
|
|
|
|
mailbox
|
|
|
|
begin dup @ while suspend repeat ( wait for empty mailbox )
|
|
|
|
! ;
|
|
|
|
|
|
|
|
: receive ( -- val )
|
|
|
|
running mailbox
|
|
|
|
begin dup @ not while suspend repeat ( wait for mail )
|
|
|
|
dup @ 0 rot ! ;
|
|
|
|
|