version 1.78, 2000/08/22 18:15:38
|
version 1.79, 2000/08/23 21:03:52
|
Line 7728 doc-get-order
|
Line 7728 doc-get-order
|
doc---gforthman-set-order |
doc---gforthman-set-order |
doc-wordlist |
doc-wordlist |
doc-table |
doc-table |
doc-push-order |
doc->order |
doc-previous |
doc-previous |
doc-also |
doc-also |
doc---gforthman-forth |
doc---gforthman-forth |
Line 7982 set-current
|
Line 7982 set-current
|
You can see what definitions are in the environment word list like this: |
You can see what definitions are in the environment word list like this: |
|
|
@example |
@example |
environment-wordlist push-order words previous |
environment-wordlist >order words previous |
@end example |
@end example |
|
|
|
|
Line 10400 doc---objects-class
|
Line 10400 doc---objects-class
|
doc---objects-class->map |
doc---objects-class->map |
doc---objects-class-inst-size |
doc---objects-class-inst-size |
doc---objects-class-override! |
doc---objects-class-override! |
|
doc---objects-class-previous |
|
doc---objects-class>order |
doc---objects-construct |
doc---objects-construct |
doc---objects-current' |
doc---objects-current' |
doc---objects-[current] |
doc---objects-[current] |
doc---objects-current-interface |
doc---objects-current-interface |
doc---objects-dict-new |
doc---objects-dict-new |
doc---objects-drop-order |
|
doc---objects-end-class |
doc---objects-end-class |
doc---objects-end-class-noname |
doc---objects-end-class-noname |
doc---objects-end-interface |
doc---objects-end-interface |
Line 10429 doc---objects-[parent]
|
Line 10430 doc---objects-[parent]
|
doc---objects-print |
doc---objects-print |
doc---objects-protected |
doc---objects-protected |
doc---objects-public |
doc---objects-public |
@c !! push-order conflicts |
|
doc---objects-push-order |
|
doc---objects-selector |
doc---objects-selector |
doc---objects-this |
doc---objects-this |
doc---objects-<to-inst> |
doc---objects-<to-inst> |
Line 10733 doc---oof-class;
|
Line 10732 doc---oof-class;
|
@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 |
mixture of the @file{object.fs} and the @file{oof.fs} syntax, |
mixture of the @file{objects.fs} and the @file{oof.fs} syntax, |
and reduces to the bare minimum of features. This is based on a posting |
and reduces to the bare minimum of features. This is based on a posting |
of Bernd Paysan in comp.lang.forth. |
of Bernd Paysan in comp.lang.forth. |
|
|
Line 10839 Object-oriented systems with late bindin
|
Line 10838 Object-oriented systems with late bindin
|
table, which contains the methods as function pointers. The vtable |
table, which contains the methods as function pointers. The vtable |
may also contain other information. |
may also contain other information. |
|
|
So first, let's declare methods: |
So first, let's declare selectors: |
|
|
@example |
@example |
: method ( m v -- m' v ) Create over , swap cell+ swap |
: method ( m v "name" -- m' v ) Create over , swap cell+ swap |
DOES> ( ... o -- ... ) @@ over @@ + @@ execute ; |
DOES> ( ... o -- ... ) @@ over @@ + @@ execute ; |
@end example |
@end example |
|
|
During method declaration, the number of methods and instance |
During selector declaration, the number of selectors and instance |
variables is on the stack (in address units). @code{method} creates |
variables is on the stack (in address units). @code{method} creates one |
one method and increments the method number. To execute a method, it |
selector and increments the selector number. To execute a selector, it |
takes the object, fetches the vtable pointer, adds the offset, and |
takes the object, fetches the vtable pointer, adds the offset, and |
executes the @i{xt} stored there. Each method takes the object it is |
executes the method @i{xt} stored there. Each selector takes the object |
invoked from as top of stack parameter. The method itself should |
it is invoked with as top of stack parameter; it passes the parameters |
|
(including the object) unchanged to the appropriate method which should |
consume that object. |
consume that object. |
|
|
Now, we also have to declare instance variables |
Now, we also have to declare instance variables |
|
|
@example |
@example |
: var ( m v size -- m v' ) Create over , + |
: var ( m v size "name" -- m v' ) Create over , + |
DOES> ( o -- addr ) @@ + ; |
DOES> ( o -- addr ) @@ + ; |
@end example |
@end example |
|
|
Line 10872 We need a starting point (the base objec
|
Line 10872 We need a starting point (the base objec
|
|
|
@example |
@example |
Create object 1 cells , 2 cells , |
Create object 1 cells , 2 cells , |
: class ( class -- class methods vars ) dup 2@@ ; |
: class ( class -- class selectors vars ) dup 2@@ ; |
@end example |
@end example |
|
|
For inheritance, the vtable of the parent object has to be |
For inheritance, the vtable of the parent object has to be |
Line 10880 copied when a new, derived class is decl
|
Line 10880 copied when a new, derived class is decl
|
methods of the parent class, which can be overridden, though. |
methods of the parent class, which can be overridden, though. |
|
|
@example |
@example |
: end-class ( class methods vars -- ) |
: end-class ( class selectors vars "name" -- ) |
Create here >r , dup , 2 cells ?DO ['] noop , 1 cells +LOOP |
Create here >r , dup , 2 cells ?DO ['] noop , 1 cells +LOOP |
cell+ dup cell+ r> rot @@ 2 cells /string move ; |
cell+ dup cell+ r> rot @@ 2 cells /string move ; |
@end example |
@end example |
Line 10892 copies the xts from the parent vtable.
|
Line 10892 copies the xts from the parent vtable.
|
We still have no way to define new methods, let's do that now: |
We still have no way to define new methods, let's do that now: |
|
|
@example |
@example |
: defines ( xt class -- ) ' >body @@ + ! ; |
: defines ( xt class "name" -- ) ' >body @@ + ! ; |
@end example |
@end example |
|
|
To allocate a new object, we need a word, too: |
To allocate a new object, we need a word, too: |
Line 10940 Now, implement the two methods, @code{dr
|
Line 10940 Now, implement the two methods, @code{dr
|
|
|
@noindent |
@noindent |
To demonstrate inheritance, we define a class @code{bold-button}, with no |
To demonstrate inheritance, we define a class @code{bold-button}, with no |
new data and no new methods: |
new data and no new selectors: |
|
|
@example |
@example |
button class |
button class |
Line 10960 for @code{button}:
|
Line 10960 for @code{button}:
|
@end example |
@end example |
|
|
@noindent |
@noindent |
Finally, create two objects and apply methods: |
Finally, create two objects and apply selectors: |
|
|
@example |
@example |
button new Constant foo |
button new Constant foo |
Line 11001 to pass objects on the stack.
|
Line 11001 to pass objects on the stack.
|
|
|
@item |
@item |
It requires that the selector parses the input stream (at |
It requires that the selector parses the input stream (at |
compile time); this leads to reduced extensibility and to bugs that are+ |
compile time); this leads to reduced extensibility and to bugs that are |
hard to find. |
hard to find. |
|
|
@item |
@item |
It allows using every selector to every object; |
It allows using every selector on every object; this eliminates the |
this eliminates the need for classes, but makes it harder to create |
need for interfaces, but makes it harder to create efficient |
efficient implementations. |
implementations. |
@end itemize |
@end itemize |
|
|
@cindex Pountain's object-oriented model |
@cindex Pountain's object-oriented model |
Line 11018 binding. Instead, it focuses on features
|
Line 11018 binding. Instead, it focuses on features
|
overloading that are characteristic of modular languages like Ada (83). |
overloading that are characteristic of modular languages like Ada (83). |
|
|
@cindex Zsoter's object-oriented model |
@cindex Zsoter's object-oriented model |
In @cite{Does late binding have to be slow?} (Forth Dimensions 18(1) |
In @uref{http://www.forth.org/oopf.html, Does late binding have to be |
1996, pages 31-35) Andras Zsoter describes a model that makes heavy use |
slow?} (Forth Dimensions 18(1) 1996, pages 31-35) Andras Zsoter |
of an active object (like @code{this} in @file{objects.fs}): The active |
describes a model that makes heavy use of an active object (like |
object is not only used for accessing all fields, but also specifies the |
@code{this} in @file{objects.fs}): The active object is not only used |
receiving object of every selector invocation; you have to change the |
for accessing all fields, but also specifies the receiving object of |
active object explicitly with @code{@{ ... @}}, whereas in |
every selector invocation; you have to change the active object |
@file{objects.fs} it changes more or less implicitly at @code{m: |
explicitly with @code{@{ ... @}}, whereas in @file{objects.fs} it |
... ;m}. Such a change at the method entry point is unnecessary with the |
changes more or less implicitly at @code{m: ... ;m}. Such a change at |
Zsoter's model, because the receiving object is the active object |
the method entry point is unnecessary with Zsoter's model, because the |
already. On the other hand, the explicit change is absolutely necessary |
receiving object is the active object already. On the other hand, the |
in that model, because otherwise no one could ever change the active |
explicit change is absolutely necessary in that model, because otherwise |
object. An ANS Forth implementation of this model is available at |
no one could ever change the active object. An ANS Forth implementation |
@uref{http://www.forth.org/fig/oopf.html}. |
of this model is available through |
|
@uref{http://www.forth.org/oopf.html}. |
|
|
@cindex @file{oof.fs}, differences to other models |
@cindex @file{oof.fs}, differences to other models |
The @file{oof.fs} model combines information hiding and overloading |
The @file{oof.fs} model combines information hiding and overloading |
Line 11768 doc-getenv
|
Line 11769 doc-getenv
|
@section Keeping track of Time |
@section Keeping track of Time |
@cindex time-related words |
@cindex time-related words |
|
|
Gforth implements time-related operations by making calls to the C |
|
library function, @code{gettimeofday}. |
|
|
|
doc-ms |
doc-ms |
doc-time&date |
doc-time&date |
|
doc-utime |
|
doc-cputime |
|
|
|
|
@c ------------------------------------------------------------- |
@c ------------------------------------------------------------- |
Line 11810 in file included from ./yyy.fs:1
|
Line 11809 in file included from ./yyy.fs:1
|
./xxx.fs:4: Invalid memory address |
./xxx.fs:4: Invalid memory address |
bar |
bar |
^^^ |
^^^ |
|
Backtrace: |
$400E664C @@ |
$400E664C @@ |
$400E6664 foo |
$400E6664 foo |
@end example |
@end example |
Line 11857 case.
|
Line 11857 case.
|
@cindex @code{gforth-fast}, difference from @code{gforth} |
@cindex @code{gforth-fast}, difference from @code{gforth} |
@cindex backtraces with @code{gforth-fast} |
@cindex backtraces with @code{gforth-fast} |
@cindex return stack dump with @code{gforth-fast} |
@cindex return stack dump with @code{gforth-fast} |
@code{gforth} is able to do a return stack dump for throws generated |
@code{Gforth} is able to do a return stack dump for throws generated |
from primitives (e.g., invalid memory address, stack empty etc.); |
from primitives (e.g., invalid memory address, stack empty etc.); |
@code{gforth-fast} is only able to do a return stack dump from a |
@code{gforth-fast} is only able to do a return stack dump from a |
directly called @code{throw} (including @code{abort} etc.). This is the |
directly called @code{throw} (including @code{abort} etc.). This is the |
Line 12067 If @code{WORD} is called with the space
|
Line 12067 If @code{WORD} is called with the space
|
white-space characters (as identified by the C macro @code{isspace()}) |
white-space characters (as identified by the C macro @code{isspace()}) |
are delimiters. @code{PARSE}, on the other hand, treats space like other |
are delimiters. @code{PARSE}, on the other hand, treats space like other |
delimiters. @code{SWORD} treats space like @code{WORD}, but behaves |
delimiters. @code{SWORD} treats space like @code{WORD}, but behaves |
like @code{PARSE} otherwise. @code{(NAME)}, which is used by the outer |
like @code{PARSE} otherwise. @code{Name}, which is used by the outer |
interpreter (aka text interpreter) by default, treats all white-space |
interpreter (aka text interpreter) by default, treats all white-space |
characters as delimiters. |
characters as delimiters. |
|
|
Line 12110 lines. One of these characters is typica
|
Line 12110 lines. One of these characters is typica
|
@cindex maximum size of a counted string |
@cindex maximum size of a counted string |
@cindex counted string, maximum size |
@cindex counted string, maximum size |
@code{s" /counted-string" environment? drop .}. Currently 255 characters |
@code{s" /counted-string" environment? drop .}. Currently 255 characters |
on all ports, but this may change. |
on all platforms, but this may change. |
|
|
@item maximum size of a parsed string: |
@item maximum size of a parsed string: |
@cindex maximum size of a parsed string |
@cindex maximum size of a parsed string |
Line 12147 What are we expected to document here?
|
Line 12147 What are we expected to document here?
|
@cindex number of bits in one address unit |
@cindex number of bits in one address unit |
@cindex address unit, size in bits |
@cindex address unit, size in bits |
@code{s" address-units-bits" environment? drop .}. 8 in all current |
@code{s" address-units-bits" environment? drop .}. 8 in all current |
ports. |
platforms. |
|
|
@item number representation and arithmetic: |
@item number representation and arithmetic: |
@cindex number representation and arithmetic |
@cindex number representation and arithmetic |
Processor-dependent. Binary two's complement on all current ports. |
Processor-dependent. Binary two's complement on all current platforms. |
|
|
@item ranges for integer types: |
@item ranges for integer types: |
@cindex ranges for integer types |
@cindex ranges for integer types |
Line 12182 string.
|
Line 12182 string.
|
|
|
@item size of one character in address units: |
@item size of one character in address units: |
@cindex char size |
@cindex char size |
@code{1 chars .}. 1 on all current ports. |
@code{1 chars .}. 1 on all current platforms. |
|
|
@item size of the keyboard terminal buffer: |
@item size of the keyboard terminal buffer: |
@cindex size of the keyboard terminal buffer |
@cindex size of the keyboard terminal buffer |