TILE FORTH PACKAGE 4(7)

Mikael Patel mip at massormetrix.ida.liu.se
Tue Dec 19 04:51:39 AEST 1989


#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 4 (of 7)."
# Contents:  COPYING doc/multi-tasking.doc io.c kernel.h
#   src/multi-tasking.f83
# Wrapped by mip at massormetrix on Mon Dec 18 18:40:12 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f COPYING -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"COPYING\"
else
echo shar: Extracting \"COPYING\" \(12488 characters\)
sed "s/^X//" >COPYING <<'END_OF_COPYING'
X
X		    GNU GENERAL PUBLIC LICENSE
X		     Version 1, February 1989
X
X Copyright (C) 1989 Free Software Foundation, Inc.
X                    675 Mass Ave, Cambridge, MA 02139, USA
X Everyone is permitted to copy and distribute verbatim copies
X of this license document, but changing it is not allowed.
X
X			    Preamble
X
X  The license agreements of most software companies try to keep users
Xat the mercy of those companies.  By contrast, our General Public
XLicense is intended to guarantee your freedom to share and change free
Xsoftware--to make sure the software is free for all its users.  The
XGeneral Public License applies to the Free Software Foundation's
Xsoftware and to any other program whose authors commit to using it.
XYou can use it for your programs, too.
X
X  When we speak of free software, we are referring to freedom, not
Xprice.  Specifically, the General Public License is designed to make
Xsure that you have the freedom to give away or sell copies of free
Xsoftware, that you receive source code or can get it if you want it,
Xthat you can change the software or use pieces of it in new free
Xprograms; and that you know you can do these things.
X
X  To protect your rights, we need to make restrictions that forbid
Xanyone to deny you these rights or to ask you to surrender the rights.
XThese restrictions translate to certain responsibilities for you if you
Xdistribute copies of the software, or if you modify it.
X
X  For example, if you distribute copies of a such a program, whether
Xgratis or for a fee, you must give the recipients all the rights that
Xyou have.  You must make sure that they, too, receive or can get the
Xsource code.  And you must tell them their rights.
X
X  We protect your rights with two steps: (1) copyright the software, and
X(2) offer you this license which gives you legal permission to copy,
Xdistribute and/or modify the software.
X
X  Also, for each author's protection and ours, we want to make certain
Xthat everyone understands that there is no warranty for this free
Xsoftware.  If the software is modified by someone else and passed on, we
Xwant its recipients to know that what they have is not the original, so
Xthat any problems introduced by others will not reflect on the original
Xauthors' reputations.
X
X  The precise terms and conditions for copying, distribution and
Xmodification follow.
X
X		    GNU GENERAL PUBLIC LICENSE
X   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
X
X  0. This License Agreement applies to any program or other work which
Xcontains a notice placed by the copyright holder saying it may be
Xdistributed under the terms of this General Public License.  The
X"Program", below, refers to any such program or work, and a "work based
Xon the Program" means either the Program or any work containing the
XProgram or a portion of it, either verbatim or with modifications.  Each
Xlicensee is addressed as "you".
X
X  1. You may copy and distribute verbatim copies of the Program's source
Xcode as you receive it, in any medium, provided that you conspicuously and
Xappropriately publish on each copy an appropriate copyright notice and
Xdisclaimer of warranty; keep intact all the notices that refer to this
XGeneral Public License and to the absence of any warranty; and give any
Xother recipients of the Program a copy of this General Public License
Xalong with the Program.  You may charge a fee for the physical act of
Xtransferring a copy.
X
X  2. You may modify your copy or copies of the Program or any portion of
Xit, and copy and distribute such modifications under the terms of Paragraph
X1 above, provided that you also do the following:
X
X    a) cause the modified files to carry prominent notices stating that
X    you changed the files and the date of any change; and
X
X    b) cause the whole of any work that you distribute or publish, that
X    in whole or in part contains the Program or any part thereof, either
X    with or without modifications, to be licensed at no charge to all
X    third parties under the terms of this General Public License (except
X    that you may choose to grant warranty protection to some or all
X    third parties, at your option).
X
X    c) If the modified program normally reads commands interactively when
X    run, you must cause it, when started running for such interactive use
X    in the simplest and most usual way, to print or display an
X    announcement including an appropriate copyright notice and a notice
X    that there is no warranty (or else, saying that you provide a
X    warranty) and that users may redistribute the program under these
X    conditions, and telling the user how to view a copy of this General
X    Public License.
X
X    d) You may charge a fee for the physical act of transferring a
X    copy, and you may at your option offer warranty protection in
X    exchange for a fee.
X
XMere aggregation of another independent work with the Program (or its
Xderivative) on a volume of a storage or distribution medium does not bring
Xthe other work under the scope of these terms.
X
X  3. You may copy and distribute the Program (or a portion or derivative of
Xit, under Paragraph 2) in object code or executable form under the terms of
XParagraphs 1 and 2 above provided that you also do one of the following:
X
X    a) accompany it with the complete corresponding machine-readable
X    source code, which must be distributed under the terms of
X    Paragraphs 1 and 2 above; or,
X
X    b) accompany it with a written offer, valid for at least three
X    years, to give any third party free (except for a nominal charge
X    for the cost of distribution) a complete machine-readable copy of the
X    corresponding source code, to be distributed under the terms of
X    Paragraphs 1 and 2 above; or,
X
X    c) accompany it with the information you received as to where the
X    corresponding source code may be obtained.  (This alternative is
X    allowed only for noncommercial distribution and only if you
X    received the program in object code or executable form alone.)
X
XSource code for a work means the preferred form of the work for making
Xmodifications to it.  For an executable file, complete source code means
Xall the source code for all modules it contains; but, as a special
Xexception, it need not include source code for modules which are standard
Xlibraries that accompany the operating system on which the executable
Xfile runs, or for standard header files or definitions files that
Xaccompany that operating system.
X
X  4. You may not copy, modify, sublicense, distribute or transfer the
XProgram except as expressly provided under this General Public License.
XAny attempt otherwise to copy, modify, sublicense, distribute or transfer
Xthe Program is void, and will automatically terminate your rights to use
Xthe Program under this License.  However, parties who have received
Xcopies, or rights to use copies, from you under this General Public
XLicense will not have their licenses terminated so long as such parties
Xremain in full compliance.
X
X  5. By copying, distributing or modifying the Program (or any work based
Xon the Program) you indicate your acceptance of this license to do so,
Xand all its terms and conditions.
X
X  6. Each time you redistribute the Program (or any work based on the
XProgram), the recipient automatically receives a license from the original
Xlicensor to copy, distribute or modify the Program subject to these
Xterms and conditions.  You may not impose any further restrictions on the
Xrecipients' exercise of the rights granted herein.
X
X  7. The Free Software Foundation may publish revised and/or new versions
Xof the General Public License from time to time.  Such new versions will
Xbe similar in spirit to the present version, but may differ in detail to
Xaddress new problems or concerns.
X
XEach version is given a distinguishing version number.  If the Program
Xspecifies a version number of the license which applies to it and "any
Xlater version", you have the option of following the terms and conditions
Xeither of that version or of any later version published by the Free
XSoftware Foundation.  If the Program does not specify a version number of
Xthe license, you may choose any version ever published by the Free Software
XFoundation.
X
X  8. If you wish to incorporate parts of the Program into other free
Xprograms whose distribution conditions are different, write to the author
Xto ask for permission.  For software which is copyrighted by the Free
XSoftware Foundation, write to the Free Software Foundation; we sometimes
Xmake exceptions for this.  Our decision will be guided by the two goals
Xof preserving the free status of all derivatives of our free software and
Xof promoting the sharing and reuse of software generally.
X
X			    NO WARRANTY
X
X  9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
XFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
XOTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
XPROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
XOR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
XMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
XTO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
XPROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
XREPAIR OR CORRECTION.
X
X  10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
XWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
XREDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
XINCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
XOUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
XTO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
XYOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
XPROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
XPOSSIBILITY OF SUCH DAMAGES.
X
X		     END OF TERMS AND CONDITIONS
X
X	Appendix: How to Apply These Terms to Your New Programs
X
X  If you develop a new program, and you want it to be of the greatest
Xpossible use to humanity, the best way to achieve this is to make it
Xfree software which everyone can redistribute and change under these
Xterms.
X
X  To do so, attach the following notices to the program.  It is safest to
Xattach them to the start of each source file to most effectively convey
Xthe exclusion of warranty; and each file should have at least the
X"copyright" line and a pointer to where the full notice is found.
X
X    <one line to give the program's name and a brief idea of what it does.>
X    Copyright (C) 19yy  <name of author>
X
X    This program is free software; you can redistribute it and/or modify
X    it under the terms of the GNU General Public License as published by
X    the Free Software Foundation; either version 1, or (at your option)
X    any later version.
X
X    This program is distributed in the hope that it will be useful,
X    but WITHOUT ANY WARRANTY; without even the implied warranty of
X    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
X    GNU General Public License for more details.
X
X    You should have received a copy of the GNU General Public License
X    along with this program; if not, write to the Free Software
X    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X
XAlso add information on how to contact you by electronic and paper mail.
X
XIf the program is interactive, make it output a short notice like this
Xwhen it starts in an interactive mode:
X
X    Gnomovision version 69, Copyright (C) 19xx name of author
X    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
X    This is free software, and you are welcome to redistribute it
X    under certain conditions; type `show c' for details.
X
XThe hypothetical commands `show w' and `show c' should show the
Xappropriate parts of the General Public License.  Of course, the
Xcommands you use may be called something other than `show w' and `show
Xc'; they could even be mouse-clicks or menu items--whatever suits your
Xprogram.
X
XYou should also get your employer (if you work as a programmer) or your
Xschool, if any, to sign a "copyright disclaimer" for the program, if
Xnecessary.  Here a sample; alter the names:
X
X  Yoyodyne, Inc., hereby disclaims all copyright interest in the
X  program `Gnomovision' (a program to direct compilers to make passes
X  at assemblers) written by James Hacker.
X
X  <signature of Ty Coon>, 1 April 1989
X  Ty Coon, President of Vice
X
XThat's all there is to it!
END_OF_COPYING
if test 12488 -ne `wc -c <COPYING`; then
    echo shar: \"COPYING\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f doc/multi-tasking.doc -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"doc/multi-tasking.doc\"
else
echo shar: Extracting \"doc/multi-tasking.doc\" \(13175 characters\)
sed "s/^X//" >doc/multi-tasking.doc <<'END_OF_doc/multi-tasking.doc'
XMULTI-TASKING(3)	     MULTI-TASKING FUNCTIONS 		MULTI-TASKING(3)
X
XNAME
X	multi-tasking - functions for concurrent programming
X
XSYNOPSIS
X	#include multi-tasking.f83
X
X	multi-tasking ( -- )
X
X	TASK ( -- )
X	+queue ( task -- queue) private
X	+status ( task -- status) private
X	+sp ( task -- sp) private
X	+s0 ( task -- s0) private
X	+ip ( task -- ip) private
X	+rp ( task -- rp) private
X	+r0 ( task -- r0) private
X	+fp ( task -- fp) private
X	+ep ( task -- ep) private
X
X	TASK-STATUS-CODES ( -- )
X	TERMINATED ( -- 0)
X	READY ( -- 1)
X	RUNNING ( -- 2)
X	IOWAITING ( -- 3)
X	WAITING ( -- 4)
X	DELAYED ( -- 5)
X
X	foreground ( -- task)
X	running ( -- task)
X
X	user ( offset -- )
X	task ( users parameters returns code -- task)
X
X	resume ( task -- )
X	schedule ( task -- )
X	detach ( -- )
X	terminate ( -- )
X
X	>terminate ( -- addr)
X
X	deactivate ( queue task -- ) 
X	activate ( task -- ) 
X
X	delay ( n -- )
X	join ( task -- ) 
X	who ( -- ) 
X
X	SEMAPHORE ( n -- )
X	+waiting ( semaphore -- waiting) private
X	+count ( semaphore -- count) private
X
X	mutex ( -- ) 
X	signal ( semaphore -- ) 
X	?wait ( semaphore -- flag) 
X	wait ( semaphore -- ) 
X	
X	COMMUNICATION-MODELS ( -- )
X	ONE-TO-ONE ( -- 0)
X	ONE-TO-MANY ( -- 1)
X	MANY-TO-ONE ( -- 2)
X
X	CHAN ( mode -- )
X	+sent ( chan -- sent) private
X	+received ( chan -- received) private
X	+data ( chan -- data) private
X	?avail ( chan -- flag)
X
X	send ( data chan -- ) 
X	receive ( chan -- data)  
X
X	RENDEZVOUS ( -- )
X  	+arg ( rendezvous -- arg) private
X  	+res ( rendezvous -- res) private
X
X	accept ( -- arg) immediate
X	accept.end ( res -- ) immediate
X	?awaiting ( -- boolean) immediate
X
X	task.type ( parameters returns -- )
X	+users ( task.type -- user) private
X	+parameters ( task.type -- parameters) private
X	+returns ( task.type -- returns) private
X	+body ( task.type -- body) private
X	bytes ( size -- )  
X	struct ( -- )
X	byte ( -- )
X	word ( -- )
X	long ( -- )
X	ptr ( -- )
X	enum ( -- )
X	task.body ( -- ) 
X	task.end ( -- )
X
X	field ( size -- ) private
X	make ( task.type -- task)
X	new ( -- task)
X
XDESCRIPTION
X	Kernel and forth level extension to allow concurrent programming
X	with tasks, semaphores, channels and rendezvous.
X
Xmulti-tasking ( -- )
X	Vocabulary containing the multi-tasking extensions to the Forth 83
X	Standard. These extensions are realized both as primitives and on
X	the forth level.
X
XTASK ( -- )
X	Definition of the instance structure of a task. Created by 
X	"task".
X
X+queue ( task -- queue) private
X	Field access of system queue of task instances.
X
X+status ( task -- status) private
X	Field access of task status. See "TASK-STATUS-CODES" for
X	possible codes. Stored as a enumerate value, enum.
X
X+sp ( task -- sp) private
X	Field access of task parameter stack pointer. Stored as a
X	pointer, ptr.
X
X+s0 ( task -- s0) private
X	Field access of task bottom of parameter stack pointer.
X	Stored as a pointer, ptr.
X
X+ip ( task -- ip) private
X	Field access of task instruction pointer. Stored as a
X	pointer, ptr.
X
X+rp ( task -- rp) private
X	Field access of task return stack pointer. Stored as a
X	pointer, ptr.
X
X+r0 ( task -- r0) private
X	Field access of task return stack bottom pointer. Stored as a
X	pointer, ptr.
X
X+fp ( task -- fp) private
X	Field access of task argument frame pointer. Stored as a
X	pointer, ptr.
X
X+ep ( task -- ep) private
X	Field access of task exception frame pointer. Stored as 
X	a pointer, ptr.
X
XTASK-STATUS-CODES ( -- )
X	Enumerate defining the possible task status codes.
X
XTERMINATED ( -- 0)
X	Task status code for terminated tasks.
X
XREADY ( -- 1)
X	Task status code for newly created tasks, ready for scheduling.
X
XRUNNING ( -- 2)
X	Task status code for running, scheduled, tasks.
X
XIOWAITING ( -- 3)
X	Task status code for task waiting for IO. The foreground task
X	is currently the only task allowed to perform io-operations,
X	as these are not reentrant.
X
XWAITING ( -- 4)
X	Task status code for task performing a generic wait operation.
X
XDELAYED ( -- 5)
X	Task status code for task performing "delay". Will resume 
X	RUNNING after the "delay" operation.
X
Xforeground ( -- task)
X	Variable containing a pointer to the foreground task.
X
Xrunning ( -- task)
X	Variable containing a pointer to the current running task.
X
Xuser ( offset -- )
X	Used in the following form to create a local, user, variable
X	within the task instance:
X		<offset> user <user-name>
X	The offset is a relative address from the task pointer.
X
Xtask ( users parameters returns code -- task)
X	Used to create a task instance. All parameters, except code,
X	are sizes in bytes. Code is a pointer to forth-level code.
X	Returns a pointer to a task.
X
Xresume ( task -- )
X	Activates the given task. The task must be a member of the
X	runnable tasks, i.e., scheduled and waiting for activation.
X
Xschedule ( task -- )
X	Schedules the given task and activates it immediately. 
X
Xdetach ( -- )
X	Deactivate the current running task and resumes the next
X	task in the queue over runnable tasks.
X
Xterminate ( -- )
X	Terminates the current running task and resumes the next task
X	in the runnable task queue.
X
X>terminate ( -- addr)
X	Constant containing a pointer to the terminate function. Used
X	by "task" to automatically terminate task which arrive at the
X	end of their task body, i.e., forth-level code section.
X
Xdeactivate ( queue task -- ) 
X	Removes a task from the queue of runnable task and inserts
X	it into the given queue. The next runnable task is resumed.
X
Xactivate ( task -- ) 
X	Inserts a task first in the queue of runnable task and resumed. 
X	The task is assumed to have be scheduled and deactivated. 
X
Xdelay ( n -- )
X	Delays a task a number of task switches. The delay is not
X	real-time but relative time. The task status is "DELAYED"
X	during the delay.
X
Xjoin ( task -- ) 
X	Delay a task until the task given as parameter terminates.
X	The task status is "WAITING" during the join delay.
X	
Xwho ( -- ) 
X	Displays the current state of the queue of runnable tasks.
X
XSEMAPHORE ( n -- )
X	Used as follows:
X		<initial-value> SEMAPHORE <semaphore-name>
X	to create and initiate a named semaphore.
X
X+waiting ( semaphore -- count) private
X	Field access to semaphore queue for waiting tasks.
X
X+count ( semaphore -- count) private
X	Field access to semaphore value.
X
Xmutex ( -- ) 
X	Used as follows:
X		mutex <semaphore-name>
X	to create a semaphore for mutual exclusion. Should not be
X	used within other structures as this definition is not a
X	structure definition but a code definition.
X
Xsignal ( semaphore -- ) 
X	If there is a waiting task on the semaphore this task is
X	resumed else the semaphore counter is incremented.
X
X?wait ( semaphore -- flag) 
X	Checks the semaphore counter to determine if a "wait"
X	operation will make a task wait. Returns true in this case.
X
Xwait ( semaphore -- ) 
X	Dequeues the task and places it into the semaphore waiting
X	queue if the semaphore counter is zero otherwise the counter
X	is decrements and the task continues. The task status is 
X	"WAITING" during the semaphore wait delay.
X	
XCOMMUNICATION-MODELS ( -- )
X	Enumerate type used to select the operation type of a channel.
X
XONE-TO-ONE ( -- 0)
X	The channel is to be operated in a one-to-one manner.
X
XONE-TO-MANY ( -- 1)
X	The channel is to be operated in a one-to-many manner. Several
X	receiving tasks are possible on the channel. Data sent on the 
X	channel is maintained from corruption.
X
XMANY-TO-ONE ( -- 2)
X	Selects the many-to-one communication mode of a channel. Several
X	sending tasks are allowed to communicate with a service task.
X
XCHAN ( mode -- )
X	Used as follows to create a channel:
X		<chan-mode> CHAN <chan-name>
X	The channel is represented by two synchronization semaphores
X	and a common data area. May be used for three major communication
X	styles between tasks.
X
X+sent ( chan -- sent) private
X	Field access to the sent synchronization semaphore.
X
X+received ( chan -- received) private
X	Field access to the received synchronization semaphore.
X
X+data ( chan -- data) private
X	Field access to the common data area. Used as holding place
X	for data sent until received. Stored as a number, long.
X
X?avail ( chan -- flag)
X	Check whether a receive operation will not block.
X
Xsend ( data chan -- ) 
X	Sends data on channel. Sender will wait until receiver has
X	performed "receive".
X
Xreceive ( chan -- data)  
X	Receives data from channel. Will wait until sender has
X	performed "send".
X
XRENDEZVOUS ( -- )
X	Used in the form:
X		RENDEZVOUS <rendezvous-name>
X	to create a rendezvous name. This name may then be used as
X	a function service by some task with "accept".
X		<rendezvous-name> ( arg -- res)
X	The function always takes one argument and always returns
X	one result value.
X
X+arg ( rendezvous -- arg) private
X	Structure field within a rendezvous which is the channel
X	for argument passing to the server task.
X
X+res ( rendezvous -- res) private
X	Structure field within a rendezvous which is the channel
X	for result passing from the server task to the client task.
X
Xaccept ( -- arg) immediate
X	Using in the form:
X		accept <rendezvous-name>
X		  <service-definition>
X		accept.end
X	to accept calls on the rendezvous. When a client task calls
X	the rendezvous the argment from client is passed to the 
X	server task that performed the accept.
X
Xaccept.end ( res -- ) immediate
X	Marks the end of an accept block in a server task. The result
X	is passed to the client task and both may continue in parallel.
X
X?awaiting ( -- boolean) immediate
X	Used in the form:
X		?awaiting <rendezvous-name>
X	in a server task to check if a client task is waiting for 
X	service.
X
Xtask.type ( parameters returns -- )
X	Used in the following form to start the definition of a task
X	type: 
X		<parameters> <returns> task.type <task-type-name>
X		  <user-variables>
X		task.body
X		  <task-body-definition>
X		task.end
X	The two parameters, parameters and returns, define the size
X	in bytes of these two areas within a task instance. Local
X	user area is defined by the user field names. 
X
X+users ( task.type -- user) private
X	Field access of number of bytes for user area of task type.
X	Stored as a number, long.
X
X+parameters ( task.type -- parameters) private
X	Field access of number of bytes for parameter stack of task type.
X	Stored as a number, long.
X
X+returns ( task.type -- returns) private
X	Field access of number of bytes for return stack of task type.
X	Stored as a number, long.
X
X+body ( task.type -- body) private
X	Field access to task type pointer to task body code. Stored
X	as a pointer, ptr.
X
Xmake ( task.type -- task)
X	Creates a anonymous task given a task type instance. Used in the
X	following form:
X		' <task-type> >body make
X	as command, and in definitions:
X		['] <task-type> >body make
X
Xnew ( -- task)
X	Used in following structure:
X		new <task-type>
X	to create a new task instance of a task type. Performs "make".
X
Xbytes ( size -- )  
X	Used in the following form to create named local structures
X	and data within task instances:
X		<number> bytes <user-field-name>
X	Should only be used within the layout section of a task type.
X
Xfield ( size -- ) private
X	Fix size field meta-word. Used to create primary set of field
X	type names, "byte", "word", "long", "ptr", and "enum". Many
X	only be used for definitions internal to "multi-tasking".
X
Xstruct ( -- )
X	Creates a named user variable of a structure size. Use as:
X		struct <struct-name> <user-name>
X
Xbyte ( -- )
X	Used as:
X		byte <user-name>
X	within a task type definitions. Creates a user variable access 
X	name to a byte.
X
Xword ( -- )
X	Used as:
X		word <user-name>
X	within a task type definitions. Creates a user variable access 
X	name to a word, two bytes.
X
Xlong ( -- )
X	Used as:
X		long <user-name>
X	within a task type definitions. Creates a user variable access 
X	name to a long, four bytes.
X
Xptr ( -- )
X	Used as:
X		ptr <user-name>
X	within a task type definitions. Creates a user variable access 
X	name to a pointer, four bytes.
X
Xenum ( -- )
X	Used as:
X		enum <user-name>
X	within a task type definitions. Creates a user variable access 
X	name to an enumerative, four bytes counter.
X
Xtask.body ( -- ) 
X	Used within a task type definition structure to indicate the
X	beginning of the task body part and the end of the user	variables. 
X
Xtask.end ( -- )
X	Ends a task type definition.
X
XSEE ALSO
X	enumerates(2), queues(1), structures(2)
X
XCOPYING
X	Copyright (C) 1989 Mikael R.K. Patel
X	Permission is granted to make and distribute verbatim copies
X	of this manual provided the copyright notice and this permission
X	notice are preserved on all copies.
X	Permission is granted to copy and distribute modified versions
X	of this manual under the conditions for verbatim copying, 
X	provided also that the section entitled "GNU General Public
X	License" is included exactly as in the original, and provided
X	that the entire resulting derived work is distributed under
X	the terms of a permission notice identical to this one.
X	Permission is granted to copy and distribute translations of
X	this manual into another language, under the above conditions
X	for modified versions, except that the section entitled "GNU
X	General Public License" may be included in a translation approved
X	by the author instead of in the original English.
X
XAUTHOR
X	Mikael R.K. Patel
X	Computer Aided Design Laboratory (CADLAB)
X	Department of Computer and Information Science
X	Linkoping University
X	S-581 83 LINKOPING
X	SWEDEN
X	Email: mip at ida.liu.se
END_OF_doc/multi-tasking.doc
if test 13175 -ne `wc -c <doc/multi-tasking.doc`; then
    echo shar: \"doc/multi-tasking.doc\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f io.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"io.c\"
else
echo shar: Extracting \"io.c\" \(10096 characters\)
sed "s/^X//" >io.c <<'END_OF_io.c'
X/*
X  C BASED FORTH-83 MULTI-TASKING IO MANAGEMENT
X
X  Copyright (c) 1989 by Mikael Patel
X
X  Computer Aided Design Laboratory (CADLAB)
X  Department of Computer and Information Science
X  Linkoping University
X  S-581 83 LINKOPING
X  SWEDEN
X
X  Email: mip at ida.liu.se
X  
X  Started on: 30 June 1988
X
X  Last updated on: 17 December 1989
X
X  Dependencies:
X       (cc) fcntl.h, errno.h, kernel.h, error.h, memory.h and io.h
X
X  Description:
X       Handles low level access to Operating System to allow asynchronous
X       input and multi-tasking of Forth level processes while waiting for
X       buffer filling. File names are saved so that files are not reloaded. 
X  
X  Copying:
X       This program is free software; you can redistribute it and/or modify
X       it under the terms of the GNU General Public License as published by
X       the Free Software Foundation; either version 1, or (at your option)
X       any later version.
X
X       This program is distributed in the hope that it will be useful,
X       but WITHOUT ANY WARRANTY; without even the implied warranty of
X       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
X       GNU General Public License for more details.
X
X       You should have received a copy of the GNU General Public License
X       along with this program; see the file COPYING.  If not, write to
X       the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
X
X*/
X
X
X#include <fcntl.h>
X#include <errno.h>
X#include "kernel.h"
X#include "memory.h"
X#include "error.h"
X#include "io.h"
X
X
X/* MAXIMUM FILE AND PATH NAME STRING SIZES */
X
X#define FILENAMESIZE 128
X#define PATHNAMESIZE 128
X
X
X/* FILE BUFFERS STACK AND STACK POINTER */
X
X#define FSTACKSIZE 32
X
XFILE_BUFFER *io_fstack[FSTACKSIZE];
Xint  io_fsp = -1;
X
X
X/* STACK OF LOADED FILE NAMES */
X
X#define INFILESSIZE 64
X
Xstatic char *infiles[INFILESSIZE];
Xstatic int  infsp = -1;
X
X
X/* STACK OF FILE SEARCH PATHS AND HOME ADDRESS */
X
X#define PATHSSIZE 64
X
Xstatic char *paths[PATHSSIZE];
Xstatic int  psp = -1;
X
Xstatic char *home;
X
X
X/* EXTERNAL DEFININED IO DISPATCH ROUTINE AND ENVIRONMENT ACCESS */
X
Xextern void io_dispatch();
Xextern char *getenv();
X
X
X/* IO MANAGEMENT DEFINITONS */
X
Xint io_path(pname, pos)
X    char *pname;		/* Pointer to path name */
X    int  pos;			/* Position to append */
X{
X    char pathname[PATHNAMESIZE];    
X    long plen = strlen(pname);
X    long i;
X
X    /* Check for null path. Dont add these */
X    if (plen == 0) return IO_NO_ERROR;
X
X    /* Check if the path name is an environment variable */
X    if (pname[0] == '$') {
X
X	/* Fetch the environment variables value */
X	char *paths = (char *) getenv((char *) pname + 1);
X
X	/* If paths are available recursivly add them to the path list */
X	if (paths) {
X	    while (*paths) {
X		char *p = pathname;
X
X		/* Parse list of paths; directories seperated by colon */
X		while (*paths && *paths != ':') *p++ = *paths++;
X		*p++ = '\0'; 
X
X		/* Append recursively */
X		(void) io_path(pathname, pos);
X
X		/* Access next path if available */
X		if (*paths) paths++;
X	    }
X	    return IO_NO_ERROR;
X	}
X	else
X	    return IO_UNKNOWN_PATH;
X    }
X
X    /* Check if the path contains a home directory character first */
X    if (pname[0] == '~' && pname[1] == '/') {
X	(void) strcpy(pathname, home);
X	(void) strcpy((char *) pathname + strlen(home), (char *) pname + 2);
X	pname = pathname;
X	plen = strlen(pathname);
X    }
X    
X    /* Check that the last character is a slash if not add it */
X    if (pname[plen - 1] != '/') {
X	pname[plen++] = '/';
X	pname[plen] = '\0';
X    }
X
X    /* Check if the path has already been defined */
X    for (i = 0; i <= psp; i++)
X	if (STREQ(paths[i], pname)) return IO_PATH_DEFINED;
X    
X    /* Check if space is available on path stack */
X    if (psp + 1 == PATHSSIZE) return IO_TOO_MANY_PATHS;
X
X    /* Make space for the new path */
X    psp = psp + 1;
X    
X    /* Check where the path should be appended */
X    if (pos == IO_PATH_FIRST) {
X	for (i = psp; i > 1; i--) paths[i] = paths[i - 1];
X	pos = 0;
X    }
X    else pos = psp;
X
X    /* Add path string att position given */
X    paths[pos] = strcpy((char *) malloc((unsigned) plen), pname);
X
X    return IO_NO_ERROR;
X}
X
Xvoid io_flush()
X{
X    /* Flush any waiting output */
X    (void) fflush(stdout);    
X
X    /* Close all open files if not end of input stream */
X    if (io_not_eof()) {
X
X	/* Close all files but lowest */
X	while (io_fsp > 0) (void) close(io_fstack[io_fsp--] -> fd);
X
X	/* Close lowest file on file stack if not tty */
X	if (!isatty(io_fstack[io_fsp] -> fd))
X	    (void) close(io_fstack[io_fsp--] -> fd);
X    }
X}
X
Xint io_infile(fname)
X    char *fname;		/* Pointer to file name to open as input */
X{
X    char filename[FILENAMESIZE];
X    long i, j;
X    long fd;
X    
X    /* Check for standard input as source */
X    if (fname == STDIN) {
X
X	/* Check if space is available on file stack */
X	if (io_fsp + 1 == FSTACKSIZE) return IO_TOO_MANY_FILES;
X
X	/* Push standard input as source onto the file buffer stack */
X	io_fsp = io_fsp + 1;
X	io_fstack[io_fsp] -> fd = STDIN;
X	io_fstack[io_fsp] -> bufp = 0;
X	io_fstack[io_fsp] -> cc = 0;
X	return IO_NO_ERROR;
X    }
X
X    /* Check if the file name contains a home directory character first */
X    if (fname[0] == '~' && fname[1] == '/') fname += 2;
X
X    /* Expand the file name using the path stack and try opening the file */
X    for (i = 0; i <= psp; i++) {
X
X	/* Build the new file name using a path */
X	(void) strcpy(filename, paths[i]);
X	(void) strcpy(filename + strlen(paths[i]), fname);
X
X	/* Check if this file has already been loaded */
X	for (j = 0; j <= infsp; j++)
X	    if (STREQ(infiles[j], filename)) return IO_FILE_INCLUDED;
X
X	/* Try opening the file */
X	fd = open(filename, O_RDONLY);
X
X	/* If no errors then save the file name and return file descriptor */
X	if (fd != -1) {
X
X	    /* Check if space is available on file stack */
X	    if (io_fsp + 1 == FSTACKSIZE) return IO_TOO_MANY_FILES;
X
X	    /* Push file onto the file buffer stack and use it as source */
X	    infsp = infsp + 1;
X	    infiles[infsp] = strcpy((char *) malloc((unsigned) strlen(filename) + 1), filename);
X	    io_fstack[++io_fsp] -> fd = fd;
X	    io_fstack[io_fsp] -> bufp = 0;
X	    io_fstack[io_fsp] -> cc = 0;
X	    return fd;
X	}
X    }
X
X    /* The file was not available so return error */
X    return IO_UNKNOWN_FILE;
X}
X
X
Xint io_fillbuf()
X{
X    long nonblocking;
X
X    /* Check io consistency and foreground task input only */
X    if (io_eof() || tp != foreground) error_fatal(0);
X    
X    /* Flush any waiting output if filling buffer from a terminal */
X    if (isatty(io_fstack[io_fsp] -> fd)) (void) fflush(stdout);
X
X    /* Check for multi-tasking input operation */
X    if (tp != ((TASK *) tp -> queue.succ)) {
X	(void) fcntl(io_fstack[io_fsp] -> fd, F_SETFL, FNDELAY); 
X	tp -> status = IOWAITING;
X	nonblocking = TRUE;
X    }
X    else
X	nonblocking = FALSE;
X	
X    /* Allow multi-tasking during waiting for input */
X    for (;;) {
X
X	/* Try reading a block from the current input stream */
X	if ((io_fstack[io_fsp] -> cc = read(io_fstack[io_fsp] -> fd,
X					    io_fstack[io_fsp] -> buf,
X					    BUFSIZE)) > 0) {
X
X	    /* Restore to non-blocking input from file and foreground */
X	    if (nonblocking) {
X		(void) fcntl(io_fstack[io_fsp] -> fd, F_SETFL, 0);
X		spush(foreground);
X		doresume();
X		tp -> status = RUNNING;
X	    }
X
X	    /* Initiate the buffer pointer and return the first character */
X	    io_fstack[io_fsp] -> bufp = 0;
X	    return io_getchar();
X	}
X
X	/* Did the read operation result in an end of file */
X	if (io_fstack[io_fsp] -> cc == 0 && errno != EWOULDBLOCK) {
X
X	    /* Set back the file mode to synchronous and close the file */
X	    if (nonblocking) {
X		(void) fcntl(io_fstack[io_fsp] -> fd, F_SETFL, 0);
X		spush(foreground);
X		doresume();
X		tp -> status = RUNNING;
X	    }
X	    (void) close(io_fstack[io_fsp--] -> fd); 
X	    
X	    /* Check if end of input source */
X	    if (io_eof()) return IO_EOF;
X
X	    /* Get character from previous file buffer */
X	    return io_getchar();
X	}
X
X	/* Run forth level tasks while waiting for input */
X	if (tp == foreground) dodetach(); else doinner();
X	
X	/* Check if the task for empty, i.e., only the foreground */
X	if (tp == foreground && tp == ((TASK *) tp -> queue.succ)) {
X	    (void) fcntl(io_fstack[io_fsp] -> fd, F_SETFL, 0); 
X	    nonblocking = FALSE;
X	}
X	
X	/* Allow user extension of the io wait loop */
X	io_dispatch();
X    }
X}
X
Xvoid io_skip(skpchr)
X    char skpchr;		/* Skip character */
X{
X    /* Skip all characters until skip termination character or end of file */
X    while (io_not_eof() && io_getchar() != skpchr);
X}
X
Xvoid io_scan(buf, brkchr)
X    char *buf;			/* Pointer to scan buffer */
X    char brkchr;		/* Break character */
X{
X    /* Initiate buffer as null string */
X    *buf = '\0';
X
X    /* Check for scanning until white space or special break character */
X    if (brkchr == ' ') {
X
X	/* While not white space or end of file */
X	while (io_not_eof() && !ISSPACE(*buf = io_getchar())) buf++;
X    }
X    else {
X
X	/* While not the break character or end of file */
X	while (io_not_eof() && (*buf = io_getchar()) != brkchr) buf++;
X    }
X    
X    /* End the string and return */
X    *buf = '\0';
X    return;
X}
X
Xvoid io_skipspace()
X{
X    /* Skip all white spaces */
X    while (io_not_eof() && ISSPACE(io_getchar()));
X
X    /* Step back the buffer pointer */
X    if (io_not_eof()) io_fstack[io_fsp] -> bufp -= 1;
X}
X
Xvoid io_initiate(banner)
X    char *banner;		/* Initiate application message */
X{
X    long i;
X
X    /* Print banner and add initial paths */
X    (void) printf(banner);
X    (void) io_path("$PWD", IO_PATH_LAST);
X    (void) io_path(home = (char *) getenv("HOME"), IO_PATH_LAST);
X    (void) io_path("$TILEPATH", IO_PATH_LAST);
X
X    /* Allocate file buffers */
X    for (i = 0; i < FSTACKSIZE; i++) {
X	io_fstack[i] = (FILE_BUFFER *) malloc((unsigned) sizeof(FILE_BUFFER));
X	if (io_fstack[i] == NIL) {
X	    (void) printf("io: can not allocate file buffers\n");
X	    exit(0);
X	}
X    }
X}    
X    
Xvoid io_finish()
X{
X    /* Flush any waiting output */
X    (void) fflush(stdout);    
X
X    /* Close all open files */
X    while (io_not_eof()) (void) close(io_fstack[io_fsp--] -> fd);
X}
X
END_OF_io.c
if test 10096 -ne `wc -c <io.c`; then
    echo shar: \"io.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f kernel.h -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"kernel.h\"
else
echo shar: Extracting \"kernel.h\" \(8038 characters\)
sed "s/^X//" >kernel.h <<'END_OF_kernel.h'
X/*
X  C BASED FORTH-83 MULTI-TASKING KERNEL DEFINITIONS
X
X  Copyright (c) 1989 by Mikael R.K. Patel
X
X*/
X
X
X/* INCLUDED SYSTEM FUNCTIONS */
X
X#include <string.h>
X
X
X/* MISC. */
X
X#define word short
X
X#define TRUE -1L
X#define FALSE 0L
X#define NIL 0L
X
X#define STREQ(s1, s2) ((*(char *) s1 == *(char *) s2) && \
X		       (*(char *) s1 + 1 == *(char *) s2 + 1) && \
X		       !(strcmp((char *) s1, (char *) s2)))
X
X
X/* QUEUE DEFINITION */
X
Xtypedef struct queue {
X    struct queue *succ, *pred;
X} QUEUE;
X
X
X/* TASK DEFINITION */
X
Xtypedef struct {
X    QUEUE queue;
X    long status;
X    long *sp;
X    long *s0;
X    long *ip;
X    long *rp;
X    long *r0;
X    long *fp;
X    long *ep;
X} TASK_HEADER;
X
Xtypedef struct {
X    QUEUE queue;
X    long status;
X    long *sp;
X    long *s0;
X    long *ip;
X    long *rp;
X    long *r0;
X    long *fp;
X    long *ep;
X    long users[1];
X} TASK;
X
X
X/* TASK STATUS FIELD VALUES: ENUMERATE */
X
X#define TERMINATED 0
X#define READY 1
X#define RUNNING 2
X#define IOWAITING 3
X#define WAITING 4
X#define DELAYED 5
X
X
X/* STACK MACROS */
X
X#define sinit sp = s0
X#define spop tos; tos = *sp++
X#define spush(e) { *(--sp) = tos; tos = (long) e; }
X#define snth(n) sp[n]
X#define sdrop(n) sp += n; tos = *sp++
X
X#define unary(op) (tos = op (tos))
X#define binary(op) (tos = *sp++ op (tos))
X#define ubinary(op) (tos = (unsigned long) *sp++ op (unsigned long) tos)
X#define relation(op) (tos = ((*sp++ op (tos)) ? TRUE : FALSE))
X#define urelation(op) (tos = ((unsigned long) *sp++ op (unsigned long) tos) ? TRUE : FALSE)
X#define compare(op) (tos = (((tos) op) ? TRUE : FALSE))
X
X#define rinit rp = r0
X#define rpop *rp++
X#define rpush(e) *(--rp) = (long) e
X#define rnth(n) rp[n]
X#define rdrop(n) rp += n    
X
X
X/* THREADING ALIGNMENT MACRO */
X
X#define align(p) p = (long *) ((long) ((char *) p + 3) & -4)
X
X
X/* THREADED BRANCH MACRO */
X
X#define skip ip++
X#define branch(to) ip = (long *) ((char *) ip + (to))
X#define jump(to) ip = (long *) (to)
X
X    
X/* VOCABULARY ENTRY DEFINITION, TYPES, AND MODES */
X
Xtypedef struct entry {
X    struct entry *link;
X    char *name;
X    long mode;
X    long code;
X    long parameter;
X} ENTRY;
X
X
X/* ENTRY MODE VALUES: SET */
X
X#define NORMAL 0
X#define IMMEDIATE 1
X#define EXECUTION 2
X#define COMPILATION 4
X#define HIDDEN 6
X#define PRIVATE 8
X
X
X/* ENTRY CODES */
X
X#define CODE 0
X#define COLON 1
X#define VARIABLE 2
X#define CONSTANT 3
X#define VOCABULARY 4
X#define CREATE 5
X#define USER 6
X#define LOCAL 7
X#define FORWARD 8
X#define FIELD 9
X#define EXCEPTION 10
X
X
X/* ENTRY GENERATORS */
X
X#define SUBR(x) ((long) (void (*) ()) (x))
X
X#define NORMAL_CODE(name, prev, pname, subr) \
X    static ENTRY name = {&prev, pname, NORMAL, CODE, SUBR(subr)};
X
X#define IMMEDIATE_CODE(name, prev, pname, subr) \
X    static ENTRY name = {&prev, pname, IMMEDIATE, CODE, SUBR(subr)};
X
X#define COMPILATION_CODE(name, prev, pname, subr) \
X    static ENTRY name = {&prev, pname, COMPILATION, CODE, SUBR(subr)};
X
X#define EXECUTION_CODE(name, prev, pname, subr) \
X    static ENTRY name = {&prev, pname, EXECUTION, CODE, SUBR(subr)};
X
X#define COMPILATION_IMMEDIATE_CODE(name, prev, pname, subr) \
X    static ENTRY name = \
X        {&prev, pname, COMPILATION + IMMEDIATE, CODE, SUBR(subr)};
X
X#define NORMAL_CONSTANT(name, prev, pname, val) \
X    static ENTRY name = {&prev, pname, NORMAL, CONSTANT, val};
X
X#define NORMAL_VARIABLE(name, prev, pname, val) \
X    static ENTRY name = {&prev, pname, NORMAL, VARIABLE, val};
X
X#define NORMAL_VOCABULARY(name, prev, pname, last) \
X    static ENTRY name = {&prev, pname, NORMAL, VOCABULARY, (long) &last};
X
X
X/* EXTERN FORWARD DECLARATIONS */
X
Xextern long verbose;
Xextern long quited;
Xextern long running;
Xextern long tasking;
X
Xextern TASK *tp;
Xextern TASK *foreground;
X
Xextern long tos;
Xextern long *sp;
Xextern long *s0;
X
Xextern long *ip;
Xextern long *rp;
Xextern long *r0;
X
Xextern long *fp;
Xextern long *ep;
X
Xextern long *dictionary;
Xextern long *dp;
X
Xextern ENTRY forth;
X
XTASK  *maketask();
XENTRY *makeentry();
X
Xvoid kernel_initiate();
Xvoid kernel_finish();
X
Xvoid doinner();
Xvoid docommand();
Xvoid docall();
Xvoid doappend();
Xvoid doparenbranch();
Xvoid doparenqbranch();
Xvoid doparendo();
Xvoid doparenqdo();
Xvoid doparenloop();
Xvoid doparenplusloop();
Xvoid doparenliteral();
Xvoid doparendotquote();
Xvoid doparenabortquote();
Xvoid doparensemicolon();
Xvoid doparendoes();
Xvoid dothread();
Xvoid dounthread();
Xvoid doforwardmark();
Xvoid dobackwardmark();
Xvoid doforwardresolve();
Xvoid dobackwardresolve();
Xvoid dounlinklocals();
Xvoid doparenlink()  ;
Xvoid doparenunlink()  ;
Xvoid doparenunlinksemicolon() ;
Xvoid doparenunlinkdoes();
Xvoid doparenlocal();
Xvoid doparenlocalstore();
Xvoid doparenlocalfetch();
Xvoid doassignlocal();
Xvoid dolocalreturn();
Xvoid docurlebracket();
Xvoid doparenquote();
Xvoid doquote();
Xvoid dostringlength();
Xvoid dostringcopy();
Xvoid dostringequal();
Xvoid dostringcat();
Xvoid dostringprint();
Xvoid domalloc();
Xvoid dorealloc();
Xvoid dofree();
Xvoid doqemptyqueue();
Xvoid dointoqueue();
Xvoid dooutqueue();
Xvoid douser();
Xvoid dotask();
Xvoid doresume();
Xvoid doschedule();
Xvoid dodetach();
Xvoid doterminate();
Xvoid donewexception();
Xvoid doparenexceptionsemicolon();
Xvoid doparenexceptionunlinksemicolon();
Xvoid doparenexception();
Xvoid doexception();
Xvoid doraise();
Xvoid doboolean();
Xvoid donot();
Xvoid doand();
Xvoid door();
Xvoid doxor();
Xvoid doqwithin();
Xvoid dodup();
Xvoid dodrop();
Xvoid doswap();
Xvoid doover();
Xvoid dorot();
Xvoid dopick();
Xvoid doroll();
Xvoid doqdup();
Xvoid dotor();
Xvoid dofromr();
Xvoid docopyr();
Xvoid dodepth();
Xvoid dodots();
Xvoid dolessthan();
Xvoid doequals();
Xvoid dogreaterthan();
Xvoid dozeroless();
Xvoid dozeroequals();
Xvoid dozerogreater();
Xvoid doulessthan();
Xvoid doplus();
Xvoid dominus();
Xvoid dooneplus();
Xvoid dooneminus();
Xvoid dotwoplus();
Xvoid dotwominus();
Xvoid dotwotimes();
Xvoid doleftshift();
Xvoid dotimes();
Xvoid doumtimes();
Xvoid doumdividemod();
Xvoid dotwodivide();
Xvoid dorightshift();
Xvoid dodivide();
Xvoid domod();
Xvoid dodividemod();
Xvoid dotimesdividemod();
Xvoid dotimesdivide();
Xvoid domin();
Xvoid domax();
Xvoid doabs();
Xvoid donegate();
Xvoid dofetch();
Xvoid dostore();
Xvoid dowfetch();
Xvoid dowstore();
Xvoid docfetch();
Xvoid docstore();
Xvoid doffetch();
Xvoid dofstore();
Xvoid dobfetch();
Xvoid dobstore();
Xvoid doplusstore();
Xvoid docmove();
Xvoid docmoveup();
Xvoid dofill();
Xvoid docount();
Xvoid dodashtrailing();
Xvoid dobinary();
Xvoid dooctal();
Xvoid dodecimal();
Xvoid dohex();
Xvoid doconvert();
Xvoid dolesssharp();
Xvoid dosharp();
Xvoid dosharps();
Xvoid dohold();
Xvoid dosign();
Xvoid dosharpgreater();
Xvoid doqnumber();
Xvoid dodo();
Xvoid doqdo();
Xvoid doloop();
Xvoid doplusloop();
Xvoid doleave();
Xvoid doi();
Xvoid doj();
Xvoid doif();
Xvoid doelse();
Xvoid dothen();
Xvoid docase();
Xvoid doof();
Xvoid doendof();
Xvoid doendcase();
Xvoid dobegin();
Xvoid dountil();
Xvoid dowhile();
Xvoid dorepeat();
Xvoid doagain();
Xvoid dorecurse();
Xvoid dotailrecurse();
Xvoid doexit();
Xvoid doexecute();
Xvoid dobye();
Xvoid dodot();
Xvoid doudot();
Xvoid doascii();
Xvoid dodotquote();
Xvoid dodotparen();
Xvoid docr();
Xvoid doemit();
Xvoid dotype();
Xvoid dospace();
Xvoid dospaces();
Xvoid dokey();
Xvoid doexpect();
Xvoid doforth83();
Xvoid dointerpret();
Xvoid doquit();
Xvoid doabort();
Xvoid doabortquote();
Xvoid dohere();
Xvoid dotobody();
Xvoid dodotname();
Xvoid dosharpif();
Xvoid dosharpelse();
Xvoid dosharpthen();
Xvoid dosharpifdef();
Xvoid dosharpifundef();
Xvoid dosharpinclude();
Xvoid dosharppath();
Xvoid doparen();
Xvoid dobackslash();
Xvoid docomma();
Xvoid doallot();
Xvoid dodoes();
Xvoid doimmediate();
Xvoid doexecution();
Xvoid docompilation();
Xvoid doprivate();
Xvoid dobracketcompile();
Xvoid docompile();
Xvoid doqcompile();
Xvoid docompiling();
Xvoid doliteral();
Xvoid doleftbracket();
Xvoid dorightbracket();
Xvoid doword();
Xvoid dolast();
Xvoid dodefinitions();
Xvoid doonly();
Xvoid dorestore();
Xvoid dotick();
Xvoid dobrackettick();
Xvoid dolookup() ;
Xvoid docollision();
Xvoid dofind();
Xvoid doforget();
Xvoid dowords();
Xvoid doentry();
Xvoid doforward();
Xvoid docolon();
Xvoid dosemicolon();
Xvoid docreate();
Xvoid dovariable();
Xvoid doconstant();
Xvoid dovocabulary();
Xvoid dofield();
X
END_OF_kernel.h
if test 8038 -ne `wc -c <kernel.h`; then
    echo shar: \"kernel.h\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f src/multi-tasking.f83 -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"src/multi-tasking.f83\"
else
echo shar: Extracting \"src/multi-tasking.f83\" \(8951 characters\)
sed "s/^X//" >src/multi-tasking.f83 <<'END_OF_src/multi-tasking.f83'
X\
X\  MULTI-TASKING DEFINITIONS
X\
X\  Copyright (c) 1989 by Mikael R.K. Patel
X\
X\  Computer Aided Design Laboratory (CADLAB)
X\  Department of Computer and Information Science
X\  Linkoping University
X\  S-581 83 LINKOPING
X\  SWEDEN
X\
X\  Email: mip at ida.liu.se
X\
X\  Started on: 30 June 1988
X\
X\  Last updated on: 6 December 1989
X\
X\  Dependencies:
X\       (forth) enumerates, structures, queues
X\
X\  Description:
X\       Allows definition of tasks, semaphores and channels. Follows the
X\       basic models of concurrent programming primitives. 
X\
X\  Copying:
X\       This program is free software; you can redistribute it and\or modify
X\       it under the terms of the GNU General Public License as published by
X\       the Free Software Foundation; either version 1, or (at your option)
X\       any later version.
X\
X\       This program is distributed in the hope that it will be useful,
X\       but WITHOUT ANY WARRANTY; without even the implied warranty of
X\       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
X\       GNU General Public License for more details.
X\
X\       You should have received a copy of the GNU General Public License
X\       along with this program; see the file COPYING.  If not, write to
X\       the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
X
X.( Loading Multi-tasking definitions...) cr
X
X#include enumerates.f83
X#include structures.f83
X#include queues.f83
X
Xqueues structures multi-tasking definitions
X
X( Task structure and status codes)
X
Xstruct.type TASK ( -- )
X  struct QUEUE +queue private		( System administration of tasks)
X  enum +status private			( Status code field)
X  ptr  +sp private			( Parameter stack pointer)
X  ptr  +s0 private			( Parameter stack bottom pointer)
X  ptr  +ip private			( Instruction pointer)
X  ptr  +rp private      		( Return stack pointer)
X  ptr  +r0 private			( Return stack bottom pointer)
X  ptr  +fp private			( Argument frame stack pointer)
X  ptr  +ep private			( Exception frame pointer)
Xstruct.end
X
Xenumerates
X
Xenum.type TASK-STATUS-CODES
X  enum TERMINATED			( Terminated status code)
X  enum READY				( Ready for "schedule")
X  enum RUNNING				( Scheduled and running)
X  enum IOWAITING			( Waiting for in- or output)
X  enum WAITING				( Generic waiting)
X  enum DELAYED				( In delay function call)
Xenum.end
X  
Xmulti-tasking
X
X( Task inquiry and manipulation functions)
X
X: deactivate ( queue task -- ) 
X  running @ succ >r			( Access the next runnable task)
X  dup out				( Remove this task from the queue)
X  swap into				( And insert into queue of waiting)
X  r> resume ;				( The next task)
X
X: activate ( task -- ) 
X  running @ succ into			( And insert it after the current task)
X  detach ;				( And restart it)
X
X: delay ( n -- )
X  DELAYED running @ +status !		( Indicate that the task is delayed)
X  0 do detach loop 			( Delay a task a number of switches)
X  RUNNING running @ +status ! ;		( Restore running state)
X
X: join ( task -- ) 
X  WAITING running @ +status !		( Indicate that the task is waiting)
X  begin					( Wait for task to terminate)
X    dup +status @ 			( Check status. While not zero)
X  while					( and thus not terminate)
X    detach				( Switch tasks)
X  repeat drop				( Drop task parameter)
X  RUNNING running @ +status ! ;		( Restore running state)
X
X: who ( -- ) 
X  ." task#(s): "			( Print header and list of tasks)
X  running @ print cr ;			( addresses)
X
X( Dijkstra's Semaphore definition)
X
Xstruct.type SEMAPHORE ( n -- )
X  struct QUEUE +waiting private		( Queue of waiting tasks)
X  long +count private			( Current counter value)
Xstruct.init ( n semaphore -- )
X  dup +waiting as QUEUE initiate	( Initiate semephore queue)
X  +count !				( Initiate semaphore counter)
Xstruct.end
X
X: mutex ( -- ) 
X  1 SEMAPHORE ;				( Mutual exclusion semaphore)
X
X: signal ( semaphore -- ) 
X  dup +waiting ?empty			( Check if the waiting queue is empty)
X  if 1 swap +count +! 			( Increment counter)
X  else
X    +waiting succ dup out		( Remove the first waiting task)
X    activate				( And reactivate the task)
X  then ;
X
X: ?wait ( semaphore -- flag) 
X  +count @ 0= ;				( Check if a wait will delay the task)
X
X: wait ( semaphore -- ) 
X  dup ?wait				( Does the task have to wait)
X  if WAITING running @ +status !	( Indicate that the task is waiting)
X    +waiting running @ deactivate	( Deactivate to the waiting queue)
X    RUNNING running @ +status ! 	( Restore running state)
X  else
X    -1 swap +count +!			( Decrement the counter)
X  then ;
X
X( Extension of Hoare's Channels)
X
Xenum.type COMMUNICATION-MODES
X  enum ONE-TO-ONE			( Task to task communication)
X  enum ONE-TO-MANY			( One task to several tasks)
X  enum MANY-TO-ONE			( Serveral task to one task)
Xenum.end
X
Xstruct.type CHAN ( mode -- )
X  long +data private			( Data past from sender to receiver)
X  long +mode private			( Communication mode)
X  struct SEMAPHORE +sent private	( Semaphore for sender)
X  struct SEMAPHORE +received private	( Semaphore for receiver)
Xstruct.init ( mode chan -- )
X  swap over +mode !			( Set up channel mode)
X  0 over +sent as SEMAPHORE initiate	( Initiate semaphore fields)
X  0 swap +received as SEMAPHORE initiate ( as synchronize semphores)
Xstruct.end
X
X: ?avail ( chan -- flag) 
X  dup +mode @ MANY-TO-ONE =		( Check channel mode)
X  if +received ?wait not		( Check if receiver is available)
X  else +sent ?wait not then ;		( Check if sender is available)
X
X: send ( data chan -- ) 
X  dup +mode @ MANY-TO-ONE =		( Check mode first)
X  if dup +received wait			( Wait for a receiver)
X     swap over +data !			( Assign data field)
X     +sent signal			( And signal the receiver)
X  else
X     swap over +data ! 			( Assign data field of channel)
X     dup +sent signal 			( Signal that data is available)
X     +received wait 			( And wait for receiver to fetch)
X  then ;
X
X: receive ( chan -- data)  
X  dup +mode @ MANY-TO-ONE =		( Check mode first)
X  if dup +received signal		( Signal a receiver is ready)
X     dup +sent wait			( Wait for sender)
X     +data @				( Fetch sent data from channel)
X  else
X     dup +sent wait 			( Wait for sender to send data)
X     dup +data @ 			( Fetch data from channel)
X     swap +received signal		( And acknowledge to sender)
X  then ;
X     
X( Message passing; rendezvous)
X
Xstruct.type RENDEZVOUS ( -- )
X  struct CHAN +arg private		( Channel for argument sending)
X  struct CHAN +res private		( Channel for result receiving)
Xstruct.init ( rendezvous -- )
X  ONE-TO-ONE over +arg as CHAN initiate	( Initiate argument channel)
X  ONE-TO-ONE swap +res as CHAN initiate	( Initiate result channel)
Xstruct.does ( arg rendezvous -- res)
X  swap over +arg send			( Send the argument)
X  +res receive				( and receive the result)
Xstruct.end
X
X: accept ( -- rendezvous arg)
X  ' >body [compile] literal		( Access the rendezvous structure)
X  ?compile dup				( Receive the argument to this task)
X  ?compile +arg
X  ?compile receive ; immediate
X
X: accept.end ( rendezvous res -- )
X  ?compile swap				( Send the result to the sender)
X  ?compile +res
X  ?compile send ; immediate
X
X: ?awaiting ( -- boolean)
X  ' >body [compile] literal		( Access the rendezvous structure)
X  ?compile +arg				( Check if an argument is available)
X  ?compile ?avail ; immediate
X
X( High Level Task definition with user variables)
X
Xforward make ( task.type -- task)
X
Xstruct.type task.type ( parameters returns -- )
X  long +users private			( Size of user area in bytes)
X  long +parameters private		( Size of parameter stack)
X  long +returns	private			( Size of return stack)
X  ptr  +body private			( Pointer to task body code)
Xstruct.init ( parameters returns task.type -- task.type users0)
X  dup >r +returns ! 			( Assign given fields)
X  r@ +parameters ! 			( And prepare for definition of)
X  r> sizeof TASK			( user variable fields for tasks)
Xstruct.does ( task -- )
X  make dup schedule constant		( Make a task, start it)
Xstruct.end				( And give it a name)
X
X: make ( task.type -- task)
X  dup >r +users @ 			( Fetch task size parameters)
X  r@ +parameters @ 			( And pointer to task body)
X  r@ +returns @ 			( And create a task instance)
X  r> +body @ task ;
X
X: new ( -- task)
X  ' >body [compile] literal		( Requires symbol after to be a task)
X  ?compile make 			( type. Makes a task instance and)
X  ?compile dup				( schedules it. Return pointer to)
X  ?compile schedule ; immediate		( create instance)
X
X: bytes ( users1 size -- users2)  
X  over user + ;				( Create a user variable and update)
X
X: field ( size -- )
X  create , 				( Save size of user variable type)
X  does> @ bytes ; private		( Fetch size and create field name)
X
X: struct ( -- )
X  [compile] sizeof bytes ;		( Fetch size of structure and create)
X
X1 field byte ( -- )
X2 field word ( -- )
X4 field long ( -- )
X4 field ptr ( -- )
X4 field enum ( -- )
X
X: task.body ( task.type users3 -- ) 
X  align over +users ! 			( Align and assign user area size)
X  here swap +body !  			( Assign pointer to task body code)
X  ] ;					( And start compiling)
X
X: task.end ( -- )
X  [compile] ; ; immediate compilation 	( Stop compiling)
X
Xforth only
X
X
END_OF_src/multi-tasking.f83
if test 8951 -ne `wc -c <src/multi-tasking.f83`; then
    echo shar: \"src/multi-tasking.f83\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of archive 4 \(of 7\).
cp /dev/null ark4isdone
MISSING=""
for I in 1 2 3 4 5 6 7 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 7 archives.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0



More information about the Alt.sources mailing list