version 1.12, 1998/06/17 16:55:15
|
version 1.13, 1998/07/05 20:50:03
|
Line 18 Programming style note:
|
Line 18 Programming style note:
|
@ifinfo |
@ifinfo |
This file documents Gforth @value{VERSION} |
This file documents Gforth @value{VERSION} |
|
|
Copyright @copyright{} 1995-1997 Free Software Foundation, Inc. |
Copyright @copyright{} 1995-1998 Free Software Foundation, Inc. |
|
|
Permission is granted to make and distribute verbatim copies of |
Permission is granted to make and distribute verbatim copies of |
this manual provided the copyright notice and this permission notice |
this manual provided the copyright notice and this permission notice |
Line 61 Copyright @copyright{} 1995-1997 Free So
|
Line 61 Copyright @copyright{} 1995-1997 Free So
|
@comment The following two commands start the copyright page. |
@comment The following two commands start the copyright page. |
@page |
@page |
@vskip 0pt plus 1filll |
@vskip 0pt plus 1filll |
Copyright @copyright{} 1995--1997 Free Software Foundation, Inc. |
Copyright @copyright{} 1995--1998 Free Software Foundation, Inc. |
|
|
@comment !! Published by ... or You can get a copy of this manual ... |
@comment !! Published by ... or You can get a copy of this manual ... |
|
|
Line 103 personal machines. This manual correspon
|
Line 103 personal machines. This manual correspon
|
* Emacs and Gforth:: The Gforth Mode |
* Emacs and Gforth:: The Gforth Mode |
* Image Files:: @code{.fi} files contain compiled code |
* Image Files:: @code{.fi} files contain compiled code |
* Engine:: The inner interpreter and the primitives |
* Engine:: The inner interpreter and the primitives |
|
* Cross Compiler:: The Cross Compiler |
* Bugs:: How to report them |
* Bugs:: How to report them |
* Origin:: Authors and ancestors of Gforth |
* Origin:: Authors and ancestors of Gforth |
* Word Index:: An item for each Forth word |
* Word Index:: An item for each Forth word |
Line 339 Primitives
|
Line 340 Primitives
|
* Automatic Generation:: |
* Automatic Generation:: |
* TOS Optimization:: |
* TOS Optimization:: |
* Produced code:: |
* Produced code:: |
|
|
|
System Libraries |
|
|
|
* Binding to System Library:: |
|
|
|
Cross Compiler |
|
|
|
* Using the Cross Compiler:: |
|
* How the Cross Compiler Works:: |
|
|
@end menu |
@end menu |
|
|
@node License, Goals, Top, Top |
@node License, Goals, Top, Top |
Line 4098 operation @code{draw}. We can perform t
|
Line 4109 operation @code{draw}. We can perform t
|
@end example |
@end example |
|
|
where @code{t-rex} is an object or object pointer, created with e.g. |
where @code{t-rex} is an object or object pointer, created with e.g. |
@code{graphical : trex}. |
@code{graphical : t-rex}. |
|
|
@cindex abstract class |
@cindex abstract class |
How do we create a graphical object? With the present definitions, |
How do we create a graphical object? With the present definitions, |
Line 4265 doc---oof-class;
|
Line 4276 doc---oof-class;
|
|
|
@end itemize |
@end itemize |
|
|
|
@c ------------------------------------------------------------- |
@node Class Implementation, , Class Declaration, OOF |
@node Class Implementation, , Class Declaration, OOF |
@subsubsection Class Implementation |
@subsubsection Class Implementation |
@cindex class implementation |
@cindex class implementation |
|
|
@node Mini-OOF, , OOF, Object-oriented Forth |
@c ------------------------------------------------------------- |
|
@node Mini-OOF, , OOF, Object-oriented Forth |
@subsection Mini-OOF |
@subsection Mini-OOF |
@cindex mini-oof |
@cindex mini-oof |
|
|
Gforth's third object oriented Forth package is a 12-liner. It uses a |
Gforth's third object oriented Forth package is a 12-liner. It uses a |
bit of a mixture of the @file{object.fs} and the @file{oof.fs} syntax, |
bit of a mixture of the @file{object.fs} and the @file{oof.fs} syntax, |
and reduces to the bare minimum of features. |
and reduces to the bare minimum of features. This is based on a posting |
|
of Bernd Paysan in comp.arch. |
|
|
|
@menu |
|
* Mini-OOF Usage:: |
|
* Mini-OOF Example:: |
|
@end menu |
|
|
|
@c ------------------------------------------------------------- |
|
@node Mini-OOF Usage, Mini-OOF Example, , Mini-OOF |
|
@subsubsection Usage |
|
@cindex mini-oof usage |
|
|
|
Basically, there are seven words, to define a method, a variable, a |
|
class; to end a class, to define a method, to allocate an object, to |
|
resolve binding, and the base class (which allocates one cell for the |
|
object pointer). |
|
|
|
doc-method |
|
|
|
Defines a method |
|
|
|
doc-var |
|
|
|
Defines a variable with size bytes |
|
|
|
doc-class |
|
|
|
Starts the definition of a sub-class |
|
|
|
doc-end-class |
|
|
|
Ends the definition of a class |
|
|
|
doc-defines |
|
|
|
Binds the xt to the method name in the class |
|
|
|
doc-new |
|
|
|
Creates a new incarnation of the class |
|
|
|
doc-:: |
|
|
|
Compiles the method name of the class (not immediate!) |
|
|
|
doc-object |
|
|
|
Is the base class of all objects |
|
|
|
@c ------------------------------------------------------------- |
|
@node Mini-OOF Example, , Mini-OOF Usage, Mini-OOF |
|
@subsubsection Mini-OOF Example |
|
@cindex mini-oof example |
|
|
|
A short example shows how to use this package. |
|
|
|
@example |
|
object class |
|
method init |
|
method draw |
|
end-class graphical |
|
@end example |
|
|
|
This code defines a class @code{graphical} with an |
|
operation @code{draw}. We can perform the operation |
|
@code{draw} on any @code{graphical} object, e.g.: |
|
|
|
@example |
|
100 100 t-rex draw |
|
@end example |
|
|
|
where @code{t-rex} is an object or object pointer, created with e.g. |
|
@code{graphical new Constant t-rex}. |
|
|
|
For concrete graphical objects, we define child classes of the |
|
class @code{graphical}, e.g.: |
|
|
@example |
@example |
: method ( m v -- m' v ) Create over , swap cell+ swap |
graphical class |
DOES> ( ... o -- ... ) @ over @ + @ execute ; |
cell var circle-radius |
: var ( m v size -- m v' ) Create over , + |
end-class circle \ "graphical" is the parent class |
DOES> ( o -- addr ) @ + ; |
|
: class ( class -- class methods vars ) dup 2@ ; |
:noname ( x y -- ) |
: end-class ( class methods vars -- ) |
circle-radius @@ draw-circle ; circle defines draw |
Create here >r , dup , 2 cells ?DO ['] noop , cell +LOOP |
:noname ( r -- ) |
cell+ dup cell+ swap @ 2 - cells r> 2 cells + swap move ; |
circle-radius ! ; circle defines init |
: defines ( xt class -- ) ' >body @ + ! ; |
@end example |
: new ( class -- o ) here over @ allot swap over ! ; |
|
: :: ( class "name" -- ) ' >body @ + @ compile, ; |
There is no implicit init method, so we have to define one. The creation |
Create object 1 cells , 2 cells , |
code of the object now has to call init explicitely. |
|
|
|
@example |
|
circle new Constant my-circle |
|
50 my-circle init |
|
@end example |
|
|
|
It is also possible to add a function to create named objects with |
|
automatic call of @code{init}, given that all objects have @code{init} |
|
on the same place |
|
|
|
@example |
|
: new: ( .. o "name" -- ) |
|
new dup Constant init ; |
|
80 circle new: large-circle |
|
@end example |
|
|
|
We can draw this new circle at (100,100) |
|
with |
|
|
|
@example |
|
100 100 my-circle draw |
@end example |
@end example |
|
|
@c ------------------------------------------------------------- |
@c ------------------------------------------------------------- |
Line 6613 arguments as files to be loaded and stri
|
Line 6723 arguments as files to be loaded and stri
|
@code{'cold} should remove the arguments it has used in this case. |
@code{'cold} should remove the arguments it has used in this case. |
|
|
@c ****************************************************************** |
@c ****************************************************************** |
@node Engine, Bugs, Image Files, Top |
@node Engine, Binding to System Library, Image Files, Top |
@chapter Engine |
@chapter Engine |
@cindex engine |
@cindex engine |
@cindex virtual machine |
@cindex virtual machine |
Line 7113 newer version of these measurements at
|
Line 7223 newer version of these measurements at
|
@url{http://www.complang.tuwien.ac.at/forth/performance.html}. You can |
@url{http://www.complang.tuwien.ac.at/forth/performance.html}. You can |
find numbers for Gforth on various machines in @file{Benchres}. |
find numbers for Gforth on various machines in @file{Benchres}. |
|
|
@node Bugs, Origin, Engine, Top |
@node Binding to System Library, Cross Compiler, Engine, Top |
|
@section Binding to System Library |
|
|
|
@node Cross Compiler, Bugs, Binding to System Library, Top |
|
@section Cross Compiler |
|
|
|
Cross Compiler |
|
|
|
@menu |
|
* Using the Cross Compiler:: |
|
* How the Cross Compiler Works:: |
|
@end menu |
|
|
|
@node Using the Cross Compiler, , How the Cross Compiler Works, Cross Compiler |
|
@subsection Using the Cross Compiler |
|
|
|
@node How the Cross Compiler Works, Using the Cross Compiler, , Cross Compiler |
|
@subsection How the Cross Compiler Works |
|
|
|
@node Bugs, Origin, Cross Compiler, Top |
@chapter Bugs |
@chapter Bugs |
@cindex bug reporting |
@cindex bug reporting |
|
|