[alt.sources] TILE Forth Release 2.0, package 4 of 6

news@majestix.ida.liu.se (News Subsystem) (06/29/90)

--
Mikael R.K. Patel
Researcher and Lecturer
Computer Aided Design Laboratory (CADLAB)
Department of Computer and Information Science
Linkoping University, S-581 83  LINKOPING, SWEDEN

Phone: +46 13281821
Telex: 8155076 LIUIDA S			Telefax: +46 13142231
Internet: mip@ida.liu.se		UUCP: {uunet,mcsun,...}!liuida!mip
Bitnet: MIP@SELIUIDA			SUNET: LIUIDA::MIP

mip@IDA.LiU.SE (Mikael Patel) (07/17/90)

#! /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 6)."
# Contents:  COPYING lib/multi-tasking.f83 man/man1/tile.1 src/io.c
#   src/kernel.h
# Wrapped by mip@mina on Fri Jun 29 16:49:11 1990
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 lib/multi-tasking.f83 -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"lib/multi-tasking.f83\"
else
echo shar: Extracting \"lib/multi-tasking.f83\" \(10269 characters\)
sed "s/^X//" >lib/multi-tasking.f83 <<'END_OF_lib/multi-tasking.f83'
X\
X\  MULTI-TASKING DEFINITIONS
X\
X\  Copyright (c) 1988-1990 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@ida.liu.se
X\
X\  Started on: 30 June 1988
X\
X\  Last updated on: 27 June 1990
X\
X\  Dependencies:
X\       (forth) forth, enumerates, structures, blocks, queues
X\
X\  Description:
X\       Allows definition of tasks, condition queues, semaphores, channels,
X\       and rendezvous. Follows the basic models of concurrent programming
X\       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 blocks.f83
X#include queues.f83
X
Xblocks queues 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: .task ( task -- )
X  dup foreground @ =			( Check for foreground task)
X  if ." foreground#" else ." task#" then
X  dup . cr				( Print task fields)
X  ." queue: " dup +queue .queue cr	( The task queue pointers)
X  ." status: "dup +status @ . cr	( The task status field)
X  ." sp: " dup +sp @ . cr		( The task stack pointer)
X  ." s0: " dup +s0 @ . cr		( The task stack bottom pointer)
X  ." ip: " dup +ip @ . cr		( The task instruction pointer)
X  ." rp: " dup +rp @ . cr		( The task return stack pointer)
X  ." r0: " dup +r0 @ . cr		( The task return stack bottom pointer)
X  ." fp: " dup +fp @ . cr		( The task argument frame pointer)
X  ." ep: " +ep @ .			( The task exception frame pointer)
X;
X
X: deactivate ( queue task -- ) 
X  WAITING over +status !		( Mark as waiting)
X  running @ succ >r			( Access the next runnable task)
X  dup dequeue				( Remove this task from the queue)
X  swap enqueue				( And insert into queue of waiting)
X  r> resume				( The next task)
X;					
X
X: activate ( task -- ) 
X  RUNNING over +status !		( Restore running state)
X  running @ succ enqueue		( And insert it after the current task)
X  detach 				( And restart it)
X;
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
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
X: who ( -- ) 
X  ." task#: " running @			( Print header and list of tasks)
X  block[ ( task -- ) . ]; map-queue
X;
X
X: ps ( -- )
X  ." task status:" cr			( Print internal information about)
X  running @				( all available tasks)
X  block[ ( task -- )
X    .task
X  ]; map-queue
X;
X
X( Condition Queue Variables)
X
Xstruct.type CONDITION ( -- )
X  struct QUEUE +waiting private		( Queue of waiting tasks)
Xstruct.init ( condition -- )
X  +waiting as QUEUE initiate		( Initiate condition queue)
Xstruct.end
X
X: await ( condition -- )
X  +waiting running @ deactivate 	( Deactivate the current task)
X;
X
X: cause ( condition -- )
X  +waiting dup ?empty-queue		( Check for empty queue)
X  if drop				( Drop and return)
X  else					( Else activate the first waiting)
X    +waiting succ dup dequeue activate	( task in the condition queue)
X  then
X;
X
X( Dijkstra's Semaphore definition)
X
Xstruct.type SEMAPHORE ( n -- )
X  struct CONDITION +not.zero private	( Condition Queue: Not zero)
X  long +count private			( Current counter value)
Xstruct.init ( n semaphore -- )
X  dup +not.zero as CONDITION initiate	( Initiate semaphore condition)
X  +count !				( Initiate semaphore counter)
Xstruct.end
X
X: mutex ( -- )
X  1 SEMAPHORE 				( Mutual exclusion semaphore)
X;
X
X: signal ( semaphore -- ) 
X  dup +not.zero +waiting ?empty-queue	( Check if the waiting queue is empty)
X  if 1 swap +count +! 			( Increment counter)
X  else
X    +not.zero cause			( Cause not zero condition)
X  then
X;
X
X: ?wait ( semaphore -- flag) 
X  +count @ 0= 				( Check if a wait will delay the task)
X;
X
X: wait ( semaphore -- ) 
X  dup ?wait				( Does the task have to wait)
X  if +not.zero await			( Await not zero counter)
X  else
X    -1 swap +count +!			( Decrement the counter)
X  then
X;
X
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  tuck +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
X: send ( data chan -- ) 
X  dup +mode @ MANY-TO-ONE =		( Check mode first)
X  if dup +received wait			( Wait for a receiver)
X    tuck +data !			( Assign data field)
X    +sent signal			( And signal the receiver)
X  else
X    tuck +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
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     
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  tuck +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 receive
X; immediate
X
X: accept.end ( rendezvous res -- )
X  ?compile swap				( Send the result to the sender)
X  ?compile +res
X  ?compile send
X; immediate
X
X: ?awaiting ( -- boolean)
X  ' >body [compile] literal		( Access the rendezvous structure)
X  ?compile ?avail
X; 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
X: new-task ( -- task)
X  [compile] as				( 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
X; immediate
X
X: bytes ( users1 size -- users2)  
X  over user + 				( Create a user variable and update)
X;
X
X: field ( size -- )
X  create , 				( Save size of user variable type)
Xdoes> @ bytes				( Fetch size and create field name)
X; private
X
X: struct ( -- )
X  [compile] sizeof bytes		( Fetch size of structure and create)
X;
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 sizeof TASK - over +users !	( Align and assign user area size)
X  here swap +body !  			( Assign pointer to task body code)
X  ] 					( And start compiling)
X;
X
X: task.end ( -- )
X  [compile] ;				( Stop compiling)
X; immediate compilation
X
Xforth only
X
X
END_OF_lib/multi-tasking.f83
if test 10269 -ne `wc -c <lib/multi-tasking.f83`; then
    echo shar: \"lib/multi-tasking.f83\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f man/man1/tile.1 -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"man/man1/tile.1\"
else
echo shar: Extracting \"man/man1/tile.1\" \(6854 characters\)
sed "s/^X//" >man/man1/tile.1 <<'END_OF_man/man1/tile.1'
X.TH TILE 1 "June 29, 1990" "Version 3.26"
X.SH NAME
Xtile \- c based forth-83 standard compiler and programming environment
X.SH SYNOPSIS
X.B forth
X.RB "[\|" \-dpru
X.IR size "\|]"
X.RI "[\|" file " .\|.\|.\|]"
X.RB "[\|" \-a
X.IR argument " .\|.\|.\|]"
X.br
X.B forth
X.RB "[\|" \-dpru 
X.IR size "\|]"
X.RI "[\|" file " .\|.\|.\|]"
X.RB "[\|" \-s
X.IR start-symbol "\|]"
X.RI "[\|" argument " .\|.\|.\|]"
X.SH DESCRIPTION
X.I forth
Xuses a command syntax much like a compiler. The 
X.I file
Xarguments are loaded before the interaction top loop is started. A
X.I start\-symbol
Xmay also be given as an argument thus allowing
X.I forth
Xto act as a `compile-and-go' compiler of applications. Any extra 
Xoptions or parameters passed to 
X.I forth 
Xmay be accessed by the application. As extensions of the Forth-83 Standard
X.I forth
Xsupports floating point numbers, strings, multi-tasking, exceptions, 
Xprivate definitions, argument binding and local variables and much more. 
XWritten in C the kernel may be used as a general purpose environment 
Xfor interactive testing and development of C-code.
X.LP
XTo provide an interactive programming environment for developing programs
X.I forth
Xmay be run as a sub-process to GNU Emacs in a specialized
X.I forth\-mode.
XSource code may be edited and directly tested by passing either
Xa paragraph of code or a whole buffer to 
X.I forth
Xfrom Emacs. The 
X.I forth\-mode
Xalso supports documentation retrieval and automatic indentation of
Xforth code, comments and definitions.
X.LP
XAn environment variable is used to specify file search paths and
Xsupporting management of libraries of source code.
X.I forth
Xcompiles faster than most compilers link with approx. 70.000 lines per
Xminute on a SUN-3/60 (and over 210.000 on a SUN-SPARCstation 1).
XCode is only saved in source form. 
XLoading all available library code takes less than a second.
X.SH OPTIONS
X.TP 
X.BI \-d "dictionary-size "
XSize of dictionary in bytes. Default allocation is 1024K bytes.
X.TP
X.BI \-p "parameters-stack-size "
XSize of foreground process parameter stack in cells (32-bits). 
XDefault allocation is 256 cells.
X.TP
X.BI \-r "return-stack-size "
XSize of foreground process return stack in cells (32-bits). 
XDefault allocation is 256 cells.
X.TP
X.BI \-u "user-area-size "
XSize of foreground process user area in bytes.
XDefault allocation is 1024 bytes.
X.TP
X.BI \-a " argument .\|.\|."
XAllows access of the rest of the arguments. The first arguments is the string
X.I forth\. 
X.TP
X.BI \-s " start-symbol "
XDefines the symbol to be used instead of the normal interaction top-loop. 
XThe
X.I start\-symbol
Xbecomes the first argument and any further arguments may be accessed by the
Xapplication. The library contains some examples of argument fetching functions.
X.SH LIBRARIES
XThe
X.I tile
Xenvironment has currently five directories with C kernel source, forth-83 
Xsource library, test and example code, manuals and documentation. The directory
X.I src
Xcontains all the C-level code and the GNU emacs programming environment.
XThe directory
X.I lib
Xcontains Forth-83 source code modules, consisting of a number of
Xdata modelling, and debugging tools, and high level multi-tasking 
Xconstructs such as semaphores, channels, rendezvous and task types. 
XDocumentation of the source code and the kernel are found in the 
Xdirectory
X.I man
Xand in the directory
X.I doc.
XThese are use for handling manual commands or documentation search in
Xthe programming environment (in GNU emacs). Test programs for each 
Xforth-83 source library code may be found in the directory
X.I tst.
X.SH FILES
X.PD 0
X.TP 20
X.B file.f83
XForth-83 source input file
X.TP
X.B file.tst
XForth-83 source test file
X.TP
X.B file.3
XForth-83 source manual pages
X.TP
X.B file.doc
XForth-83 source documentation file
X.TP
X.B kernel.c..h..v
Xmulti-tasking c based Forth-83 kernel and extension vocabularies
X.TP
X.B error.c..h
Xerror management package
X.TP
X.B io.c..h
Xmulti-tasking input package
X.TP
X.B memory.c..h
Xmemory management package
X.TP
X.B forth.c
Xthis application
X.TP
X.B forth.el
XGNU Emacs forth-mode source
X.TP
X.B tile.1
Xthis manual
X.TP
X.B Makefile
Xputs the forth application together
X.PD
X.SH ENVIRONMENT
X.TP 20
X.B TILE
XPath for the tile directory structure. A normal setting for a single
Xuser is `$HOME/tile'.
X.TP
X.B TILEPATH
XSearch path for library source files. A normal setting is 
X`$TILE/lib:$TILE/tst' which will allow the file include
Xfunction in 
X.I forth
Xto locate library source files in the current directory ($PWD), the
Xstandard library, and the test code library. 
X.I forth
Xalso looks for files at your home directory ($HOME).
X.TP
X.B MANPATH
XSearch path for manual source files. Used by
X.I man
Xfor access of manual pages. Setting this environment variable to
X`$TILE/man:/usr/share/man' will allow you to read the 
X.I forth 
Xmanual pages.
X.SH GNU EMACS FORTH MODE
XThe GNU Emacs forth-mode supports interactive programming, automatic 
Xindentation of source code, and documentation search of the
X.I forth
Xkernel and library within Emacs. To allow automatic loading of the
Xmode your
X.I .emacs
Xfile should contain the following definitions;
X.LP
X.br
X  (set-variable 'load-path
X                (append load-path
X                        '(nil "~/tile")))
X.br
X  (setq forth-help-load-path '(nil "~/tile/doc"))
X.br
X  (setq auto-mode-alist
X.br
X        (append '(("\\\\.tst$" . forth-mode)
X.br
X		  	  ("\\\\.f83$" . forth-mode))
X.br
X			  auto-mode-alist))
X.br
X  (autoload 'forth-mode "forth")
X.LP
XFurther documentation about the 
X.I forth\-mode
Xmay be found by giving the command `M-x describe-mode' in Emacs. 
X.SH BUGS
XBugs should be reported to mip@ida.liu.se. Bugs tend actually to be
Xfixed if they can be isolated, so it is in your interest to report them
Xin such a way that they can be easily reproduced according to
Xget newer version.
X.SH COPYING
XCopyright (C) 1989-90 Mikael R.K. Patel
X.br
XPermission is granted to make and distribute verbatim copies
Xof this manual provided the copyright notice and this permission
Xnotice are preserved on all copies.
X.br
XPermission is granted to copy and distribute modified versions
Xof this manual under the conditions for verbatim copying, 
Xprovided also that the section entitled "GNU General Public
XLicense" is included exactly as in the original, and provided
Xthat the entire resulting derived work is distributed under
Xthe terms of a permission notice identical to this one.
X.br
XPermission is granted to copy and distribute translations of
Xthis manual into another language, under the above conditions
Xfor modified versions, except that the section entitled "GNU
XGeneral Public License" may be included in a translation approved
Xby the author instead of in the original English.
X.SH AUTHORS
XMikael R.K. Patel
X.br
XComputer Aided Design Laboratory (CADLAB)
X.br
XDepartment of Computer and Information Science
X.br
XLinkoping University
X.br
XS-581 83 LINKOPING
X.br
XSWEDEN
X.br
XEmail: mip@ida.liu.se
END_OF_man/man1/tile.1
if test 6854 -ne `wc -c <man/man1/tile.1`; then
    echo shar: \"man/man1/tile.1\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f src/io.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"src/io.c\"
else
echo shar: Extracting \"src/io.c\" \(10415 characters\)
sed "s/^X//" >src/io.c <<'END_OF_src/io.c'
X/*
X  C BASED FORTH-83 MULTI-TASKING IO MANAGEMENT
X
X  Copyright (c) 1988-1990 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@ida.liu.se
X  
X  Started on: 30 June 1988
X
X  Last updated on: 26 June 1990
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 "error.h"
X#include "memory.h"
X#include "io.h"
X
X
X/* EXTERNAL DEFINED IO DISPATCH ROUTINE, ENVIRONMENT ACCESS AND ERROR CODE */
X
Xextern VOID io_dispatch();
Xextern CSTR getenv();
Xextern INT  errno;
X
X
X/* MAXIMUM FILE AND PATH NAME STRING SIZES */
X
X#define FILENAMESIZE 128
X#define PATHNAMESIZE 128
X
X
X/* INFILE BUFFERS STACK AND STACK POINTER */
X
X#define INFSTACKSIZE 32
X
XINFILE_BUFFER io_infstack[INFSTACKSIZE];
XINT io_infsp = -1;
X
X
X/* OUTFILE AND ERROR FILE VARIABLES */
X
XFILE *io_outf;
XFILE *io_errf;
X
X
X/* STACK OF NAMES OF LOADED FILE */
X
X#define INFILESSIZE 64
X
Xstatic CSTR infiles[INFILESSIZE];
Xstatic INT infsp = -1;
X
X
X/* STACK OF FILE SEARCH PATHS */
X
X#define PATHSSIZE 32
X
Xstatic CSTR paths[PATHSSIZE];
Xstatic INT psp = -1;
X
X
X/* IO MANAGEMENT DEFINITONS */
X
XINT io_path(pname, pos)
X    CSTR pname;			/* Pointer to path name */
X    INT pos;			/* Position to append */
X{
X    CHAR pathname[PATHNAMESIZE];    
X    INT plen = strlen(pname);
X    INT 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 that the last character is a slash if not add it */
X    if (pname[plen - 1] != DIRSEPCHAR) {
X	pname[plen++] = DIRSEPCHAR;
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 > 0; 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 + 1), 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_infsp > 0) (VOID) close(io_infstack[io_infsp--] -> fd);
X
X	/* Close lowest file on file stack if not tty */
X	if (!isatty(io_infstack[io_infsp] -> fd))
X	    (VOID) close(io_infstack[io_infsp--] -> fd);
X    }
X}
X
XINT io_infile(fname)
X    CSTR fname;			/* Pointer to file name to open as input */
X{
X    CHAR filename[FILENAMESIZE];
X    INT i, j;
X    INT 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_infsp + 1 == INFSTACKSIZE) return IO_TOO_MANY_FILES;
X
X	/* Push standard input as source onto the file buffer stack */
X	io_infsp = io_infsp + 1;
X	io_infstack[io_infsp] -> fd = STDIN;
X	io_infstack[io_infsp] -> bufp = 0;
X	io_infstack[io_infsp] -> cc = 0;
X	io_infstack[io_infsp] -> fn = NIL;
X	io_infstack[io_infsp] -> ln = 1;
X	return IO_NO_ERROR;
X    }
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_infsp + 1 == INFSTACKSIZE) 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_infstack[++io_infsp] -> fd = fd;
X	    io_infstack[io_infsp] -> bufp = 0;
X	    io_infstack[io_infsp] -> cc = 0;
X	    io_infstack[io_infsp] -> fn = infiles[infsp];
X	    io_infstack[io_infsp] -> ln = 1;
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    BOOL 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_infstack[io_infsp] -> fd)) (VOID) fflush(stdout);
X
X    /* Check for multi-tasking input operation */
X    if (tp != ((TASK) tp -> queue.succ)) {
X	(VOID) fcntl(io_infstack[io_infsp] -> 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_infstack[io_infsp] -> cc = read(io_infstack[io_infsp] -> fd,
X					    io_infstack[io_infsp] -> buf,
X					    BUFSIZE)) > 0) {
X
X	    /* Restore to non-blocking input from file and foreground */
X	    if (nonblocking) {
X		(VOID) fcntl(io_infstack[io_infsp] -> fd, F_SETFL, 0);
X		spush(foreground, TASK);
X		doresume();
X		tp -> status = RUNNING;
X	    }
X
X	    /* Initiate the buffer pointer and return the first character */
X	    io_infstack[io_infsp] -> bufp = 0;
X	    return io_getchar();
X	}
X
X	/* Did the read operation result in an end of file */
X	if (io_infstack[io_infsp] -> cc == 0 && errno != EWOULDBLOCK) {
X
X	    /* Set back the file mode to synchronous and close the file */
X	    if (nonblocking) {
X		(VOID) fcntl(io_infstack[io_infsp] -> fd, F_SETFL, 0);
X		spush(foreground, TASK);
X		doresume();
X		tp -> status = RUNNING;
X	    }
X	    (VOID) close(io_infstack[io_infsp--] -> 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_infstack[io_infsp] -> 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    CHAR c;
X
X    /* Skip all characters until skip termination character or end of file */
X    while (io_not_eof()) {
X	c = io_getchar();
X	if (c == '\n') io_newline();
X	if (c == skpchr) return;
X    }
X}
X
XVOID io_scan(buf, brkchr)
X    CSTR buf;			/* Pointer to scan buffer */
X    CHAR brkchr;		/* Break character */
X{
X    CHAR c;
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()) {
X	    c = io_getchar();
X	    if (c == '\n') io_newline();
X	    if (ISSPACE(c)) break;
X	    *buf++ = c;
X	}
X    }
X    else {
X
X	/* While not the break character or end of file */
X	while (io_not_eof()) {
X	    c = io_getchar();
X	    if (c == '\n') io_newline();
X	    if (c == brkchr) break;
X	    *buf++ = c;
X	}
X    }
X    
X    /* End the string and return */
X    *buf = '\0';
X    return;
X}
X
XVOID io_skipspace()
X{
X    CHAR c;
X    
X    /* Skip all white spaces */
X    while (io_not_eof()) {
X	c = io_getchar();
X	if (c == '\n') io_newline();
X	if (!ISSPACE(c)) break;
X    }
X    
X    /* Step back the buffer pointer */
X    if (io_not_eof()) io_infstack[io_infsp] -> bufp -= 1;
X}
X
XVOID io_initiate(banner)
X    CSTR banner;		/* Initiate application message */
X{
X    INT i;
X
X    /* Assign output and error file */
X    io_outf = stdout;
X    io_errf = stderr;
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", IO_PATH_LAST);
X    (VOID) io_path("$TILEPATH", IO_PATH_LAST);
X
X    /* Allocate file buffers */
X    for (i = 0; i < INFSTACKSIZE; i++) {
X	io_infstack[i] = (INFILE_BUFFER) malloc((unsigned) sizeof(file_buffer));
X	if (io_infstack[i] == NIL) {
X	    (VOID) fprintf(io_errf, "io: cannot allocate file buffers\n");
X	    exit(0);
X	}
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_infstack[io_infsp--] -> fd);
X}
X
END_OF_src/io.c
if test 10415 -ne `wc -c <src/io.c`; then
    echo shar: \"src/io.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f src/kernel.h -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"src/kernel.h\"
else
echo shar: Extracting \"src/kernel.h\" \(11715 characters\)
sed "s/^X//" >src/kernel.h <<'END_OF_src/kernel.h'
X/*
X  C BASED FORTH-83 MULTI-TASKING KERNEL DEFINITIONS
X
X  Copyright (c) 1988-1990 by Mikael R.K. Patel
X
X*/
X
X
X/* INCLUDED SYSTEM FUNCTIONS */
X
X#include <strings.h>
X
X
X/* TYPING SYSTEM AND MISC. STRING MACROS */
X
X#define VOID void
X
Xtypedef char*  PTR8;
Xtypedef short* PTR16;
Xtypedef long*  PTR32;
X
Xtypedef VOID (*SUBR)();
X
X#define NIL 0
X
Xtypedef long BOOL;
X
X#define TRUE  ((BOOL) -1)
X#define FALSE ((BOOL)  0)
X
Xtypedef unsigned       NUM;
Xtypedef unsigned char  NUM8;
Xtypedef unsigned short NUM16;
Xtypedef unsigned long  NUM32;
X
Xtypedef int   INT;
Xtypedef char  INT8;
Xtypedef short INT16;
Xtypedef long  INT32;
X
Xtypedef float  FLOAT32;
Xtypedef double FLOAT64;
X
Xtypedef char  CHAR;
Xtypedef char* CSTR;
Xtypedef char* PSTR;
X
X#define STREQ(s1, s2) ((*(CSTR) s1 == *(CSTR) s2) && \
X		       (*(CSTR) s1 + 1 == *(CSTR) s2 + 1) && \
X		       !(strcmp((CSTR) s1, (CSTR) s2)))
X
X
X/* QUEUE DEFINITION */
X
Xtypedef struct _queue {
X    struct _queue *succ, *pred;
X} queue, *QUEUE;
X
X
X/* TASK DEFINITION */
X
Xtypedef struct {
X    queue queue;
X    INT32 status;
X    PTR32 sp;
X    PTR32 s0;
X    PTR32 ip;
X    PTR32 rp;
X    PTR32 r0;
X    PTR32 fp;
X    PTR32 ep;
X} task_header;
X
Xtypedef struct {
X    queue queue;
X    INT32 status;
X    PTR32 sp;
X    PTR32 s0;
X    PTR32 ip;
X    PTR32 rp;
X    PTR32 r0;
X    PTR32 fp;
X    PTR32 ep;
X    INT32 users[1];
X} task, *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/* VOCABULARY ENTRY DEFINITION, TYPES, AND MODES */
X
Xtypedef struct _entry {
X    struct _entry *link;
X    CSTR  name;
X    INT32 mode;
X    INT32 code;
X    INT32 parameter;
X} entry, *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 CODE VALUES: ENUMERATES */
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 VISIBILITY MACRO */
X
X#define visible(e, v) \
X    (!(((e -> mode & COMPILATION) && (!state.parameter)) || \
X       ((e -> mode & EXECUTION) && (state.parameter))  || \
X       ((e -> mode & PRIVATE) && (v != current))))
X
X
X/* NORMAL ENTRY GENERATORS */
X
X#define NORMAL_CONSTANT(v, l, n, p) \
X    static entry v = \
X       {(ENTRY) &l, n, NORMAL, CONSTANT, p};
X
X#define NORMAL_VARIABLE(v, l, n, p) \
X    static entry v = \
X       {(ENTRY) &l, n, NORMAL, VARIABLE, p};
X
X
X/* VOCABULARY ENTRY DEFINITION */
X
Xtypedef struct {
X    ENTRY link;
X    CSTR  name;
X    INT32 mode;
X    INT32 code;
X    ENTRY last;
X    ENTRY recognizer;
X} vocabulary_entry, *VOCABULARY_ENTRY;
X
X#define NORMAL_VOCABULARY(v, l, n, p, r) \
X    static vocabulary_entry v = \
X       {(ENTRY) &l, n, NORMAL, VOCABULARY, (ENTRY) p, (ENTRY) r};
X
X
X/* CODE ENTRY DEFINITION */
X
Xtypedef struct {
X    ENTRY link;
X    CSTR name;
X    INT32 mode;
X    INT32 code;
X    SUBR subr;
X} code_entry, *CODE_ENTRY;
X
X
X#define NORMAL_CODE(v, l, n, s) \
X    static code_entry v = \
X       {(ENTRY) &l, n, NORMAL, CODE, s};
X
X#define IMMEDIATE_CODE(v, l, n, s) \
X    static code_entry v = \
X       {(ENTRY) &l, n, IMMEDIATE, CODE, s};
X
X#define COMPILATION_CODE(v, l, n, s) \
X    static code_entry v = \
X       {(ENTRY) &l, n, COMPILATION, CODE, s};
X
X#define EXECUTION_CODE(v, l, n, s) \
X    static code_entry v = \
X       {(ENTRY) &l, n, EXECUTION, CODE, s};
X
X#define COMPILATION_IMMEDIATE_CODE(v, l, n, s) \
X    static code_entry v = \
X       {(ENTRY) &l, n, COMPILATION + IMMEDIATE, CODE, s};
X
X
X/* UNIVERSAL VALUE */
X
Xtypedef union {
X    BOOL             BOOL;
X    NUM32            NUM32;
X    INT32            INT32;
X    FLOAT32          FLOAT32;
X    CSTR             CSTR;
X    PTR8             PTR8;
X    PTR16            PTR16;
X    PTR32            PTR32;
X    SUBR             SUBR;
X    QUEUE            QUEUE;
X    TASK             TASK;
X    ENTRY            ENTRY;
X    CODE_ENTRY       CODE_ENTRY;
X    VOCABULARY_ENTRY VOCABULARY_ENTRY;
X} UNIV, *PTR;
X
X
X/* STACK MACROS */
X
X#define sinit() sp = s0
X#define spop(t) tos.t; tos = *sp++
X#define spush(e, t) *(--sp) = tos; tos.t = e
X#define snth(n) sp[n]
X#define sdrop() tos = *sp++
X#define sndrop(n) sp += (n); tos = *sp++
X#define snip() sp++
X#define sdup() *(--sp) = tos
X#define sover() { register UNIV t; t = *sp; *(--sp) = tos; tos = t; }
X#define stuck() { register UNIV t; t = *sp; *sp = tos; *(--sp) = t; }
X#define sswap() { register UNIV t; t = tos; tos = sp[0]; sp[0] = t; }
X#define srot()  { register UNIV t; t = tos; tos = sp[1]; sp[1] = sp[0]; sp[0] = t; }
X#define sdashrot() { register UNIV t; t = tos; tos = sp[0]; sp[0] = sp[1]; sp[1] = t; }
X
X#define coerce(f, t) tos.t = (t) tos.f
X#define unary(o, t) tos.t = o tos.t
X#define binary(o, t) tos.t = sp++ -> t o tos.t
X#define compare(o, t) tos.BOOL = (tos.t o ? TRUE : FALSE)
X#define relation(o, t) tos.INT32 = (sp++ -> t o tos.t ? TRUE : FALSE)
X
X#define rinit() rp = r0
X#define rpop() *rp++
X#define rpush(e) *(--rp) = (INT32) e
X#define rnth(n) rp[n]
X#define rndrop(n) rp += n    
X
X
X/* THREADING ALIGNMENT MACRO */
X
X#define align(p) p = (PTR32) ((INT32) ((PTR8) p + 3) & -4)
X
X
X/* THREADED BRANCH, RETURN MACRO */
X
X#define fskip() ip++
X#define fbranch(d) ip = (PTR32) ((PTR8) ip + (d))
X#define fjump(a) ip = (PTR32) (a)
X#define fsemicolon() fjump(rpop())
X#define fdoes() current -> last -> code = (INT32) ip; fsemicolon()
X
X
X/* ARGUMENT AND LOCAL VARIABLE FRAME MACRO */
X
X#define flink() \
X{ \
X    spush(fp, PTR32); \
X    fp = (PTR32) sp + *ip++; \
X    sp = sp - *ip++; \
X    rpush(sp); \
X} 
X
X#define funlink() \
X{ \
X    register PTR32 t; \
X    register PTR32 s; \
X    t = (PTR32) rpop(); \
X    if (t == (PTR32) sp) { \
X	sp = (PTR) fp; \
X	fp = tos.PTR32; \
X	sdrop(); \
X    } \
X    else { \
X	s = fp; \
X	fp = (PTR32) *--t; \
X	while (t > (PTR32) sp) *--s = *--t; \
X	sp = (PTR) s; \
X    } \
X}    
X
X#define fcatch() \
X{ \
X    PTR32 body; \
X    body = spop(PTR32); \
X    rpush(tos.INT32); \
X    rpush(sp); \
X    rpush(ip); \
X    rpush(fp); \
X    rpush(ep); \
X    ep = rp; \
X    fjump(body); \
X}
X
X#define fthrow() \
X{ \
X    ep = (PTR32) rpop(); \
X    rndrop(4); \
X    fsemicolon() ; \
X}
X    
X/* EXTERN FORWARD DECLARATIONS */
X
Xextern INT32 verbose;
Xextern INT32 quited;
Xextern INT32 running;
Xextern INT32 tasking;
X
Xextern TASK tp;
Xextern TASK foreground;
X
Xextern UNIV tos;
Xextern PTR  sp;
Xextern PTR  s0;
X
Xextern PTR32 ip;
Xextern PTR32 rp;
Xextern PTR32 r0;
X
Xextern PTR32 fp;
Xextern PTR32 ep;
X
Xextern PTR32 dictionary;
Xextern PTR32 dp;
X
Xextern vocabulary_entry forth;
X
XTASK  make_task();
XENTRY make_entry();
X
XVOID kernel_initiate();
XVOID kernel_finish();
X
XVOID doinner();
XVOID docommand();
XVOID docall();
XVOID doappend();
X
X  
X/* COMPILER EXTENSIONS */
X
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();
X
X
X/* LOCAL VARIABLES AND ARGUMENT BINDING */
X
XVOID dounlinklocals();
XVOID doparenlink()  ;
XVOID doparenunlink()  ;
XVOID doparenunlinksemicolon() ;
XVOID doparenunlinkdoes();
XVOID doparenlocal();
XVOID doparenlocalstore();
XVOID doparenlocalfetch();
XVOID doassignlocal();
XVOID dolocalreturn();
XVOID docurlebracket();
X
X
X/* NULL TERMINATED STRING */
X
XVOID doparenquote();
XVOID doquote();
XVOID doslength();
XVOID dosdup();
XVOID dosequal();
XVOID doscompare();
XVOID doscat();
XVOID dosprint();
X
X
X/* FLOATING POINT NUMBERS */
X
XVOID doitof();
XVOID doftoi();
XVOID dofplus();
XVOID dofminus();
XVOID doftimes();
XVOID dofdivide();
XVOID dofonedivide();
XVOID dofnegate();
XVOID dofdot();
XVOID doqfloat();
X
X
X/* MEMORY MANAGEMENT */
X
XVOID domalloc();
XVOID dorealloc();
XVOID dofree();
X
X
X/* DOUBLE LINKED LISTS */
X
XVOID doqemptyqueue();
XVOID doenqueue();
XVOID dodequeue();
X
X
X/* MULTI-TASKING EXTENSIONS */
X
XVOID douser();
XVOID dotask();
XVOID dofork();
XVOID doresume();
XVOID doschedule();
XVOID dodetach();
XVOID doterminate();
X
X
X/* SIGNAL AND EXCEPTION MANAGEMENT */
X
XVOID donewexception();
XVOID doparenexceptionsemicolon();
XVOID doparenexceptionunlinksemicolon();
XVOID doparenexception();
XVOID doexception();
XVOID doraise();
X
X
X/* KERNEL VOCABULARY */
X
XVOID doboolean();
XVOID donot();
XVOID doand();
XVOID door();
XVOID doxor();
XVOID doqwithin();
X
XVOID dodepth();
XVOID dodrop();
XVOID donip();
XVOID doswap();
XVOID dorot();
XVOID dodashrot();
XVOID doroll();
XVOID doqdup();
XVOID dodup();
XVOID doover();
XVOID dotuck();
X
XVOID dotor();
XVOID dofromr();
XVOID docopyr();
X
XVOID dotwotor();
XVOID dotwofromr();
XVOID dotwodrop();
XVOID dotwoswap();
XVOID dotworot();
XVOID dotwodup();
XVOID dotwoover();
X
XVOID dolessthan();
XVOID doequals();
XVOID dogreaterthan();
XVOID dozeroless();
XVOID dozeroequals();
XVOID dozerogreater();
XVOID doulessthan();
X
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();
X
XVOID dofetch();
XVOID dostore();
XVOID dowfetch();
XVOID dowstore();
XVOID docfetch();
XVOID docstore();
XVOID doffetch();
XVOID dolessffetch();
XVOID dofstore();
XVOID dobfetch();
XVOID dobstore();
XVOID dotwostore();
XVOID dotwofetch();
XVOID doplusstore();
X
XVOID docmove();
XVOID docmoveup();
XVOID dofill();
XVOID docount();
XVOID dobounds();
XVOID dodashtrailing();
XVOID dodashmatch();
X
XVOID dobinary();
XVOID dooctal();
XVOID dodecimal();
XVOID dohex();
XVOID doconvert();
XVOID dolesssharp();
XVOID dosharp();
XVOID dosharps();
XVOID dohold();
XVOID dosign();
XVOID dosharpgreater();
XVOID doqnumber();
X
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();
X
XVOID dodot();
XVOID dodotr();
XVOID doudot();
XVOID doudotr();
XVOID doascii();
XVOID dodotquote();
XVOID dodotparen();
XVOID dodots();
XVOID docr();
XVOID doemit();
XVOID dotype();
XVOID dospace();
XVOID dospaces();
X
XVOID dokey();
XVOID doexpect();
XVOID doline();
XVOID dosource();
X
XVOID doforth83();
XVOID dointerpret();
XVOID doquit();
XVOID doabort();
XVOID doabortquote();
X
XVOID dohere();
XVOID dotobody();
XVOID dodotname();
XVOID docells();
XVOID docellplus();
XVOID dosharpif();
XVOID dosharpelse();
XVOID dosharpthen();
XVOID dosharpifdef();
XVOID dosharpifundef();
XVOID dosharpinclude();
XVOID dosharppath();
XVOID doparen();
XVOID dobackslash();
X
XVOID docomma();
XVOID doallot();
XVOID doalign();
XVOID dodoes();
XVOID doimmediate();
XVOID doexecution();
XVOID docompilation();
XVOID doprivate();
XVOID dorecognizer();
XVOID dobracketcompile();
XVOID docompile();
XVOID doqcompile();
XVOID docompiling();
XVOID doliteral();
XVOID doleftbracket();
XVOID dorightbracket();
XVOID doword();
X
XVOID dolast();
XVOID dodefinitions();
XVOID doonly();
XVOID dorestore();
XVOID dotick();
XVOID dobrackettick();
XVOID dolookup() ;
XVOID dofind();
XVOID dorecognize();
XVOID doforget();
XVOID dowords();
XVOID doentry();
XVOID doforward();
XVOID docolon();
XVOID dosemicolon();
XVOID docreate();
XVOID dovariable();
XVOID doconstant();
XVOID dovocabulary();
XVOID dofield();
X
X#ifdef PROFILE
XVOID docollision();
X#endif
END_OF_src/kernel.h
if test 11715 -ne `wc -c <src/kernel.h`; then
    echo shar: \"src/kernel.h\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of archive 4 \(of 6\).
cp /dev/null ark4isdone
MISSING=""
for I in 1 2 3 4 5 6 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 6 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