From 6cd7a2e14fdf534b3def315f59c20617ee96e756 Mon Sep 17 00:00:00 2001 From: Brad Nelson Date: Fri, 8 Jan 2021 09:06:57 -0800 Subject: [PATCH] Adding tasks. --- ueforth/Makefile | 5 +++-- ueforth/common/tasks.fs | 30 ++++++++++++++++++++++++++++++ ueforth/posix/posix.fs | 4 ++++ 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 ueforth/common/tasks.fs diff --git a/ueforth/Makefile b/ueforth/Makefile index 97eee11..51e789a 100644 --- a/ueforth/Makefile +++ b/ueforth/Makefile @@ -71,7 +71,8 @@ $(GEN): POSIX_BOOT = common/boot.fs common/terminal.fs \ posix/posix.fs posix/posix_highlevel.fs \ - common/filetools.fs posix/posix_desktop.fs + common/filetools.fs posix/posix_desktop.fs \ + common/tasks.fs $(GEN)/posix_boot.h: common/source_to_string.js $(POSIX_BOOT) | $(GEN) echo "ok" | cat $(POSIX_BOOT) - | $< boot >$@ @@ -81,7 +82,7 @@ $(GEN)/windows_boot.h: common/source_to_string.js $(WINDOWS_BOOT) | $(GEN) ARDUINO_BOOT = common/boot.fs arduino/arduino.fs \ posix/posix_highlevel.fs common/filetools.fs \ - arduino/arduino_server.fs \ + common/tasks.fs arduino/arduino_server.fs \ arduino/autoboot.fs $(GEN)/arduino_boot.h: common/source_to_string.js $(ARDUINO_BOOT) | $(GEN) echo "ok" | cat $(ARDUINO_BOOT) - | $< boot >$@ diff --git a/ueforth/common/tasks.fs b/ueforth/common/tasks.fs new file mode 100644 index 0000000..bcf72bd --- /dev/null +++ b/ueforth/common/tasks.fs @@ -0,0 +1,30 @@ +( Cooperative Tasks ) + +variable task-list + +: add-task ( t -- ) + task-list @ if + task-list @ @ over ! + task-list @ ! + else + dup task-list ! + dup ! + then +; + +: task ( xt rsz dsz "name" ) + create here >r 0 , 0 , 0 , + here cell+ r@ cell+ ! cells allot + here r@ 2 cells + ! cells allot + dup 0= if drop else >:body r@ 2 cells + @ ! then + r> add-task ; + +: pause + rp@ task-list @ 2 cells + ! + sp@ task-list @ cell+ ! + task-list @ @ task-list ! + task-list @ cell+ @ sp! + task-list @ 2 cells + @ rp! +; + +0 0 0 task main-task diff --git a/ueforth/posix/posix.fs b/ueforth/posix/posix.fs index 2cd6e9c..5c0bdc4 100644 --- a/ueforth/posix/posix.fs +++ b/ueforth/posix/posix.fs @@ -32,6 +32,7 @@ z" rename" 2 sysfunc rename z" malloc" 1 sysfunc malloc z" free" 1 sysfunc sysfree z" realloc" 2 sysfunc realloc +z" usleep" 1 sysfunc usleep ( Errno ) z" __errno_location" 0 sysfunc __errno_location @@ -95,3 +96,6 @@ octal 777 constant 0777 decimal dup 0 SEEK_CUR lseek >r dup 0 SEEK_END lseek r> swap >r SEEK_SET lseek drop r> 0