home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
EFFO
/
pd6.lzh
/
SRC
/
README
< prev
next >
Wrap
Text File
|
1989-12-21
|
13KB
|
345 lines
THREADED INTERPRETIVE LANGUAGE ENVIRONMENT (TILE)
November 30, 1989
Mikael R.K. Patel
Computer Aided Design Laboratory (CADLAB)
Department of Computer and Information Science
Linkoping University
S-581 83 LINKOPING
SWEDEN
Email: mip@ida.liu.se
1. INTRODUCTION
TILE Forth is a Forth-83 implementation written in C. Thus allowing it to
be easily moved between different computers compared to traditional Forth
implementations in assembler.
TILE Forth is organized in a set of modules to allow the kernel to be used
as a general threading engine for C. Also environment dependencies such
as memory allocation, error handling and input/output are separated to
increase flexibility.
The kernel supports the Standard Forth-83 Word Set except for blocks
which are not used. The kernel is extended with the following; argument
binding and local variables, queue management, low level compiler words,
null terminated string functions, exceptions and multi-tasking. The TILE
Forth environment also contains a set of source files for high level multi-
tasking, data structuring and a number of programming tools.
To allow interaction and incremental program development TILE Forth
contains a programming environment. This environment helps with
program structuring, i.e., pretty printing, documentation search, and
program development. Each vocabulary in the kernel and the source files
is described by a documentation and test file. This style of programming
is emphasized throughout the environment.
So far TILE Forth has been ported and tested to over twenty locations
without any major problems except where C compilers do not allow sub-
routine pointers in data structures.
Most Forth implementations are done in assembly to be able to
utilize the underlying architecture as optimal as possible. TILE Forth
goes an other direction. The main idea behind TILE Forth is to achieve
a portable forth implementation for workstations and medium size
computer systems so that new groups of programmers may be exposed
to the flavor of an extensible language such as Forth. The forth
application is just an example of how to use the kernel.
The organization of TILE Forth is selected so that, in principle, any
C-level procedure may become available on the interactive and
incremental forth level. Other models of implementation of a threaded
interpreter in C are possible but are not as flexible.
TILE Forth is divided into three major parts, the kernel, io-, error-,
and memory management packages, and the application example, TILE Forth
itself.
TILE Forth extends the Forth 83 required standard with many of the
concepts from modern programming language such as argument binding,
and local variable frame, multi-tasking, exception management etc.
Writing a Forth in C gives some possibilities that normally are
not available when performing the same task in assembler. TILE Forth
has been profiled using the available tools in Unix. This information
has been used to optimize the compiler so that it achieves a compilation
speed of over 100.000 lines per minute on a Sun-4.
Currently code is only saved in source form and applications are
typically compile-and-go.
Comparing with the traditional benchmark such as the classical sieves
calculation is difficult because of difference in speed between
workstations and personal computers. The Byte sieves benchmark is
reported to typically run in 16 seconds on a DTC forth implementation.
This benchmark will run in 27 seconds in TILE forth on a SUN-3/60.
This is the total time for starting forth, compiling and executing the
benchmark.
Comparing to, for instance, other interpretive languages such as
Lisp, where one of the classical benchmarks is calculation of the
Fibonacci function, the performance increase is almost two magnitudes.
2. EXTENSIONS
What is new in the forth vocabulary? First of all is the overall
organization of words. Vocabularies, casting and entry caching is
used to make word search faster, but also to make programs written
in TILE Forth more portable to other forth dialects. If a vocabulary
other than forth is used the target system much realize these. The
casting operator in the forth top loop, interpret, allow selection
of words from vocabularies without changing the search order thus
operator overloading may be achieved. In general, the top loop
recognizes a casting operation as a parenthesized vocabulary name
prefix. An example; selecting string concatenation without changing
the search order just write:
(string) +
As Forth lack tools for description of data structures TILE Forth
contains a fairly large library of tools. These are described more
in detail in the next section.
When writing a forth function with many arguments stack shuffling
becomes a real pain. Argument binding and local variables are nice
ways out of these situations. Also for the new-comer to Forth
this gives some support. Even the stack function may be rewritten:
: 2swap { a b c d } c d a b ;
: 2drop { a b } ;
An other extension in TILE Forth are exception handing with multiple
exception handling code block. The syntactical structure is very
close to that of Ada, i.e., any colon definition may contain an error
handling section. Should an error occur during the execution of the
function the stack status is restore to the situation at call
and the last exception block is executed. Error situations may be
indicated user an exception raise function. Low level errors, such as
zero division, are transformed to exceptions in TILE Forth.
: div ( x y -- z)
/
exception> ( x y exception -- )
true abort" div: zero division attempted"
;
Last some of the less significant extension are forward declaration
of entries, hidden or private entries, and extra entry modes. Three
new entry modes have been added to the classical forth model (immediate).
These allow hiding of entries in different situations.
The first two marks the last defined words visibility according to
an interpreter state. These two modifiers are called "compilation"
and "execution" and are used as "immediate". A word like "if" is
"compilation immediate" meaning it is visible when compiling and then
always executed.
compiler forth definitions
: if ( -- ) compile (?branch) >mark ; compilation immediate
The "private" modifier is somewhat different. If concerns the
visibility across vocabularies. If a word is marked as "private"
the word is only visible when the vocabulary in which it is defined
in is "current". This means that if the vocabulary is not "current"
and in the search chain "context" the word is not visible. This
is very close to the concept of hidden in modules and packages in Modula-2
and Ada.
4 field +name ( entry -- name) private
The above definition will only be visible in the vocabulary it was
defined. This is useful to isolate implementation dependencies and reduce
the name space.
3. SOURCE LIBRARY
The TILE Forth programming environment contains a number of tools to make
programming in Forth a bit easier. If you have GNU Emacs, TILE Forth
may run in a specialized forth-mode. This mode supports automatic
program indentation (pretty printing), documentation search, interactive and
incremental program development.
To aid program development there is also a source code library with
documentation (glossary), and test and example code. Most of the source
code are data modeling tools. In principle, from bit field definition to
object oriented structures are available. The source code library also
contains debugging tools for tracing, break-point'ing and profiling of
programs.
The first level of data modeling tools are three modules for describing;
1) bit fields, 2) structures (records), and 3) aggregates of data (vectors,
stacks, buffers, etc).
The next level of tools are some tools for high level syntactic sugar
for multi-tasking concepts (semaphores, channels, etc), finite state
machines (FSM), and anonymous code block (blocks).
The source library will be extended during the coming releases (see
the release plan, file: RELEASES).
4. PROGRAMMING STYLE
A source code module has, in general, the following structure; First
section includes any modules needed (theses are only loaded once).
Second follows global definitions for the module. Normally this is
a vocabulary for the module. Third comes the search chain to be used
throughout the module. It is important not to change the search order
as 1) it becomes difficult for a reader to understand to code, 2)
any change in the search chain flushes the internal lookup cache
in TILE Forth.
.( Loading the Library...) cr
#include someLibrary.f83
( Global data and definitions)
vocabulary theLibrary
someLibrary theLibrary definitions
( Local data and definitions)
: someDefinitions ( -- ) ... ;
: somePrivateDefinitions ( -- ) ... ; private
forth only
To create lexical level within the same vocabulary the word "restore" may
be used. It stores the vocabulary pointer to the given entry and thus
hides the words defined after this entry. The word "restore" has much the
same action as "forget" but without putting back the dictionary pointer (dp).
Each module should also be documented according to the template documentation
file. This format allows the documentation function to work properly.
5. SOURCE FILES
The TILE Forth source is broken down into the following files:
tile
The TILE Forth source code and documentation library.
tile.1
Manual for "man" under Unix.
README
This short documentation of TILE.
COPYING
The GNU General Public License.
RELEASES
The current plan of source code releases.
PORTING
Some help on how to port TILE Forth and typical problems
Makefile
Allows a number of compilation styles for debugging, profiling, sharing
etc. New machines and conditional compilation symbols are added here.
forth.c
The main program using the multi-tasking kernel. Also gives access to
program arguments and start symbol.
forth.el
Forth Mode for GNU Emacs. Allows interactive program development in
EMACS and documentation search.
kernel.c..h
The multi-tasking Forth kernel.
error.c..h
The signal and error handling package of TILE Forth.
io.c..h
The input and output management package of TILE Forth.
memory.c..h
Memory allocation package of TILE Forth.
src
The Forth source library with data description, high level tasking and
other tools.
tst
Test file for each Forth source code file and a set of benchmarks.
doc
Documentation and glossary for each source code file and kernel
vocabularies.
The documentation follow the C style and the glossary structure is used
by the Forth Mode search function.
6. CONFIGURATION
TILE forth is targeted for 32-bit machines and no special aid is available
to allow it to be compiled for other bit-widths. The configuration is
maintained by a "make" files.
The configuration file allows a number of different modes to support
typical program development phases (on C level) such as debugging,
profiling, optimization and packaging. Please see the information in
these files.
7. COPYING
This software is offered as shareware. You may use it freely, but
if you do use it and find it useful, you are encouraged to send the
author a contribution for the next project (an object oriented threaded
interpreter -- `the flexibility of Smalltalk to the speed of Forth').
For further information about copying see the file COPYING and the
header in each source code file.
8. NOTE
Due to the 32-bit implementation in C a number of Forth definitions are
not confirmed. Below is a short list of words that might give problems
when porting Forth code to this environment:
* The Block Word Set is not supported. Source code is saved as text files.
* All stacks and words size are 32-bit. Thus special care must be taken
with memory allocation and access.
* Lowercase and uppercase are distinguished, and all forth words are
lowercase.
* A word in TILE is allowed arbitrary length as the name is stored as
as a null terminated string.
* Input such as key performs a traditional read operation to the
operation system thus will echo the characters.
* Variables should not allocate extra memory. "create" should be used.
ACKNOWLEDGMENTS
First of all I wish to express my gratitude to Goran Rydqvist for helped
me out with the first version of the kernel and who implemented the
forth-mode for GNU Emacs.
Second a special thanks to the beta test group who gave me valuable
feedback. Especially Mitch Bradley, Bob Giovannucci Jr., Moises Lejter,
and Brooks David Smith.
Thank you all.