programming tools for Windows applications development
  Home  |   SwiftForth Archive  |   SwiftX Archive  |

Re: Swoop Proposal

From: Azedia of DOLFINA <dolfina_at_dolfina.org>
Date: Fri, 19 Apr 2002 19:15:51 -0700

BTW

Is the SWOOP.f only for the Pro version? And, is it working for other SF
versions beyond the 2.2.2.5? Is it safe to use?

jodell

> As I mentioned in my last post I've placed a new version of SWOOP on the
> FAQ. I promised some additional documentation. Because, it's much
easier
> to look at with HTML formatting I've included it as an attachment.
>
> I'd appreciate any feedback regarding my suggestions.
>
> Thanks,
>
> Gene
>
>
> -- HTML Attachment decoded to text by Listar --
> -- File: SWOOP.htm
>
> SWOOP
>
>
>
> SWOOP PROPOSAL
>
> I've posted a new proposed version of SWOOP on the FAQ. This document
> describes the proposed changes.
>
> SWOOP is a quite sophisticated version of Forth based objects. In spite of
> the numerous features present in SWOOP I am having difficulty converting
old
> code to SWOOP. This proposed version will go a long way to correcting
that.
> In addition I think that all SwiftForth users will find these proposed
> changes logical and desirable. Hopefully, if enough users express an
> interestthen Forth Inc. will incorporate them into a new version of
> SwiftForth.
>
> SWOOP COMMANDS
>
> My proposed changes to swoop add only a few new words, but a number of
words
> take on new functionality.
>
> DEFINE: <name> ( --) ( Start an defining word.)
>
> Creates a colon definition that can be executed within the class
> description.Can not reference the object variables.
>
> &#9;DEFINE: myWord .. ;
>
> Executing a DEFINE: word outside of the class definition is at present
> undefined.
>
> NOTE: Words defined with define are self recursive! Thus:
>
> DEFINE: FOREVER FOREVER ;
>
> Will loop forever. Tail recursion is not recognized as a special case.
>
> : <name> ( --) ( Start a normal class method.)
>
> Defines normal colon definitions. The new version can also be compiled as
> in:
>
> &#9;DEFINE: MY: : ;
>
> ; ( --) ( End a word.)
>
> This is used normally. The change is that the member is assigned the
current
> group behavior defined in 'group. By waiting until the end of the word to
> assign the group the CREATE DOES> (for example) can set the group
correctly.
>
>
> IMMEDIATE ( --) ( Change behavior of previous def.)
>
> Works the same as the normal forth IMMEDIATE. IMMEDIATE words will execute
> their run time behaviors even during compiling. IMMEDIATE can be compiled.
>
> CREATE ( --) ( Add a new member.)
>
> CREATE works the same as it's forth counterpart. However, be aware that it
> isreturning an address in the MEMBER structure, and will be the same
> regardless of the object.
>
> CREATE DOES> ( --) ( Compile a specialized method)
>
> This word pair works the same as expected. At compile time the xt of the
> codefoollowing DOES> is actually stored as a literal just prior to the
DOES>
> code. At run time, when the new word is being created, it is first
assigned
> as a CREATE behavior. When the DOES> is executed the newly created member
is
> changed. The xt of the definition following DOES> is stored in the member
> structure, and the behavior is changed. When the new member finally gets
> executed, the new xt is fetched from the member structure and that is what
> finally executes.
>
> &#9;DEFINE: SCALE CREATE , DOES> @ Y @ * ;
>
> &#9;4 SCALE 4*
>
> CLASS-VARIABLE <name> ( class variable )
>
> It is occasionally convenient to have a variable shared by all of the
> instances of a class. A file handle for example.
>
> &#9;CLASS LOGGER
>
> &#9;&#9;CLASS-VARIABLE FH
>
> &#9;&#9;: OPEN FH @ 0= IF .. FH ! THEN ;
>
> In this example one could have multiple instances of the LOGGER class, but
> all would use the same file handle.
>
> n SHARE: <name> ( --) ( Named class variable n bytes.)
>
> Similar to the SWOOP word BUFFER:. Creates n bytes of class storage.
>
> SWOOP EXAMPLES
>
> Defining words and recursion.
>
> This example shows the use of DEFINE: to create a recursive definition.
>
> CLASS FACTS
>
> VARIABLE X
>
> DEFINE: FACT ( n-n ) ( Recursive factorial )
>
> DUP 2 <IF DROP 1 ELSE
>
> DUP 1- FACT * THEN ;
>
> : STORE X ! ;
>
> : FACTORIAL X @ FACT ;
>
> END-CLASS
>
> FACTS BUILDS A
>
> 4 A STORE
>
> A FACTORIAL .
>
> Notes:
>
> Within the definition of FACT there is no reference to X. DEFINES can not
> refer to the object variables.
>
> We cannot refer to FACT after the END-CLASS.
>
> CREATE DOES>
>
> This example shows the use of DEFINE: with CREATE DOES>
>
> CLASS CONVERTER
>
> VARIABLE X
>
> DEFINE: STORES
>
> CREATE , ,
>
> DOES> 2@ */ X ! ;
>
> 100 1 STORES INCHES
>
> 1200 1 STORES FEET
>
> 10000 254 STORES CM
>
> 1000000 254 STORES METERS
>
> DEFINE: FETCHES
>
> CREATE , ,
>
> DOES> X @ SWAP 2@ */ ;
>
> 1 100 FETCHES @INCHES
>
> 1 1200 FETCHES @FEET
>
> 254 10000 FETCHES @CM
>
> 254 1000000 FETCHES @METERS
>
> END-CLASS
>
> CONVERTER BUILDS A
>
> 1 A FEET
>
> A @CM .
>
>
>
> IMMEDIATE
>
> It is sometimes convenient to extend the normal compiler. You might want
to
> add some debugging words:
>
> CLASS FOO
>
> VARIABLE X
>
> : START CR ." X STARTS=" X ? ;
>
> : END ." ENDS " X ? ;
>
> : MY: : POSTPONE START ;
>
> : MY; POSTPONE END POSTPONE ; ; IMMEDIATE
>
> MY: STORE ( n )
>
> X ! MY;
>
> MY: ++ X ++ MY;
>
> MY: -- -1 X +! MY;
>
> END-CLASS
>
> FOO BUILDS BAR
>
> 25 BAR STORE
>
> BAR ++
>
> BAR --
>
>
>
> CLASS-VARIABLE
>
> A good example of using a class variable would be a counter of the number
of
> objects of a certain class
>
> CLASS MICE
>
> CLASS-VARIABLE POP
>
> VARIABLE C
>
> : CONSTRUCT ( -)
>
> C @ 12345 - IF POP ++ 12345 C ! THEN ;
>
> : DESTROY
>
> C @ 12345 = IF POP -- 0 C ! THEN ;
>
> : HOW-MANY ." THERE ARE " POP ? ." MICE " ;
>
> END-CLASS
>
> MICE BUILDS MICKEY
>
> MICKEY CONSTRUCT
>
>
>
> MICE BUILDS MINNEY
>
> MINNEY CONSTRUCT
>
> MICE BUILDS JOE
>
> JOE CONSTRUCT
>
> JOE HOW-MANY
>
> NOTE:
>
> For reasons I don't understand the CONSTRUCT function is only called with
> local objects, and has to be explicitly invoked with named objects. I
> suspectthis is an oversight. But I hesitate to change it without Rick's
> approval.
>
>
>
> Extending SWOOP
>
> By extending SWOOP I mean adding new kinds of compiler behaviors. A good
> example of this is adding the CLASS VARIABLES. My proposed SWOOP makes
this
> process more consistent.
>
> Every member of a class has 4 behaviors associated with it. When ever a
> member is referenced SWOOP executes the associated behavior based on the
> current compilation state.
>
> There are four compilation states determined by the state variables STATE
> andCSTATE.
>
> SWOOP is either compiling or running, and the member is being referenced
> within it's class definition or not. I call these states: RUN, COMPILE,
CRUN
> and CCOMPILE.
>
> Groups
>
> A group collects these 4 behaviors and gives this collection a name. When
> themember entry is created it is assigned a group. The group assignment
can
> be changed and is changed while a member is being compiled. After a member
> iscompiled the group is not changed again.
>
> Creating a new group
>
> For purposes of demonstration I'll go through adding the CLASS VARIABLES
to
> SWOOP. A CLASS VARIABLE will extend the member entry by one CELL, and
return
> the address of that cell at run time. We first set up the forth vocabulary
> for SWOOP extension.
>
> PACKAGE OOP
>
> PRIVATE
>
> Run time
>
> For the run time behavior we want to ignore the object, but return the
> address in the member table. The 'data parameter is passed from swoop and
is
> the address of the data parameter in the member table.
>
> : RUN-CVAR ( object 'data -- )
>
> NIP CELL+ ;
>
> Compile time
>
> At compile time SWOOP only passes the 'data parameter. Our class variable
> needs to compile this address into memory.
>
> : COMPILE-CVAR ( 'data -- )
>
> CELL+ POSTPONE LITERAL END-REFERENCE ;
>
> Class Run time
>
> Although this is extremely unlikely, we can reference a class variable
> duringclass definition. Specifically if we need to initialize it to some
> value.
>
> : CRUN-CVAR ( object 'data -- )
>
> NIP CELL+ ;
>
>
>
> Class Compile Time
>
> Compiling within a class is the same as outside of the class. This is
> generally not true. For example a colon defintion referenced inside it's
> class does not push the object stack, while a member referenced outside of
> the class defintion always pushes the object.
>
> : CCOMPILE-CVAR ( 'data -- )
>
> CELL+ POSTPONE LITERAL END-REFERENCE ;
>
>
>
> Group
>
> Now we create our new group. Executing the name of a group causes the
group
> xt to be stored in 'group.
>
> GROUP A-CVAR SAME-AS IS-UNDEFINED
>
> >COMPILE-XT <WILL-BE COMPILE-CVAR
>
> >RUNTIME-XT <WILL-BE RUN-CVAR
>
> >CCOMPILE-XT <WILL-BE CCOMPILE-CVAR
>
> >CRUNTIME-XT <WILL-BE CRUN-CVAR
>
> Create the defining word.
>
> Now we create the actual new SWOOP command. MEMBER is a standard SWOOP
word
> that takes a member name from the input stream and adds it to the member
> list, the member handle is left on the stack. NEW-GROUP-MEMBER is my
> proposednew word that takes the member handle, and a member data entry (in
> this case the length), and adds a member entry in the current group.
>
> PUBLIC
>
> GET-CURRENT ( *) CC-WORDS SET-CURRENT
>
> : CLASS-VARIABLE ( <name> -- )
>
> CELL
>
> MEMBER OVER A-CVAR ( member-xt data) NEW-GROUP-MEMBER
>
> /ALLOT ;
>
> GET-CURRENT CC-WORDS <>THROW ( *) SET-CURRENT
>
> END-PACKAGE
>
> Notes on SWOOP changes
>
> CLASS
>
> There was a small change to the class definition. It is now in the same
> format as an object, and I've added a new field called >OOF for future
use.
> The reason I changed it was I wanted to eliminate THIS, particularly at
run
> time. I planned on SELF pointing to the class structure while a class was
> being defined. I had to back out most of these changes because they broke
> existing swoop code.
>
> GROUP
>
> A group is simply a list. 'GROUP points to the group that the member being
> compiled should be assigned to.
>
> IS-UNDEFINED
>
> This is the undefined yet group. It throws an error if a member of this
> groupis referenced.
>
> A-COLON
>
> The typical colon definition.
>
> A-DATA
>
> A data reference is an offset into the curent object. The offset is in the
> member data entry.
>
> A-OBJECT
>
> The data reference is an object instance in the current object, the member
> entry has the class and displacement. In my opinion I think this should be
> changed. I believe the class should be stored in the object not the member
> table.
>
> A-DEFER
>
> A deferred word is very similar to a colon definition, accept that the xt
is
> stored in the member table.
>
> A-DEFINE
>
> A defined word is similar to a colon definition except that CRUN is legal.
>
> A-CDATA
>
> A-DEFINED
>
> A member that was created by a CREATE DOES> expression. In this case the
xt
> is placed on the stack at run time.
>
> A-IMMEDIATE
>
> An immediate member is a colon definition that essentially has no compile
> behaviors.
>
> A-CONSTANT
>
> Very similar to a class variable except that the constant is the member
> data.
>
> A-CVAR
>
> Class variable already discussed.
>
> A-CREATE
>
> The member was created by CREATE, It leaves the address immediately after
> themember data on the stack. Note that if CREATE is followed by DOES> then
> the members group is changed.
>
> A-OBJECT[]
>
> An array member. I'm not especially happy with the way arrays are handled.
> Beaware that an array of objects has a different internal representation
as
> an array in an object.
>
>
>
> Members
>
> Some new words were changed or added for member entry and group
maintenance.
>
>
> NEW-GROUP-MEMBER
>
> Uses the contents of 'GROUP, and the MEMBER Handle (xt), and member data
on
> the stack and creates the member entry. A member entry looks like:
>
> | group-xt | link | member handle | runtime-xt | data | ...
>
> This is similar to the original SWOOP but I replaced the compile-xt with
the
> new group-xt. In reality the runtime-xt is now redundant, but when I
removed
> it other swoop extensions failed so I left it in. Hopefully, if Forth Inc.
> adopts my proposed SWOOP they will fix this. When a member is created it's
> address is stored in >MEMBER.
>
> RE-GROUP-MEMBER
>
> Uses the contents of 'GROUP to change the member entry pointed at by
> >MEMBER.
>
> NEW-MEMBER
>
> Compatibility word for old SWOOP extentions. It constructs an unnamed
group
> table and then calls NEW-GROUP-MEMBER.
>
> MEMBER-DATA!
>
> Changes the contents of the member data entry.
>
> HIDE-MEMBER
>
> I couldn't figure out how to SMUDGE a member entry so this word actually
> removes it from the linked list. It stores the list address in UNLINK so
it
> can restore it later.
>
> EXPOSE-MEMBER
>
> Uses the contents of UNLINK to restore (-SMUDGE) the last member entered
on
> the member table.
>
>
>
> Binding
>
> The SWOOP words that determine what to do when a member is referenced were
> changed to be GROUP aware.
>
> LATE-BINDING
>
> This was not changed so that the code version still works. It ought to be
> changed to be group aware.
>
> CLATE-BINDING
>
> A new word called if in the CLASS RUN state.
>
> EARLY-BINDING
>
> Original COMPILE state behavior. Changed to be GROUP aware.
>
> CEARLY-BINDING
>
> A new word that is group aware and is called when compiling in a class
> definition.
>
> Build
>
> One of my problems with SWOOP is that there is no initialization word
called
> every time an object is instantiated. This is particularly a problem in
> arrays.
>
> BROADCAST[]
>
> Experimental word that will broadcast a message to all object instances in
> anobject. It is array aware.
>
> BUILDER
>
> BUILD-OBJECT
>
> An experimental word that broadcasts the BUILDER message to all object
> instances contained in the current object.
>
>
>
>
>
>
>
>
>
> User Variables
>
> CSTATE
>
> \ 0|Class being compiled
>
> OPAQUE
>
>
>
> 'GROUP
>
> XT of current group during colon def
>
> >MEMBER
>
> Address of last member entry defined.
>
> MYLINK
>
> If <>0 then Current def is being hidden
>
> >MEMBER-MSG
>
> Message being broadcast.
>
>
>
> Desirable future changes
>
> The following lists things that I'd like to see or add to SWOOP. Some of
> themwould break existing code and would almost have to be done by Forth
Inc.
> This is just my opinion based on the problems I'm experiencing converting
my
> code from Object Oriented Forth (OOF) to SWOOP.
>
> Objects need class
>
> Not having the class XT in an object instance causes a number of problems.
> First, there is the overhead associated with pushing the class through
THIS
> every reference at run time. Since THIS is rarely actually needed (the
class
> was handled at compile time) this is a considerable overhead that could be
> eliminated.
>
> In addition it makes sending a message to an array of objects somewhat
> difficult as one has to manipulate a lost of class xt's all the time.
>
> Remove runtime xt from member.
>
> Since the runtime xt is now in the group, the entry in the memer table is
> redundant. Again, when I attempted to do this it broke existing code, so I
> think that Forth Inc. needs to do this.
>
> Containers
>
> A container is an object the "contains" another object whose class is not
> known at compile time. I hope to add this in my own SWOOP extension. Using
a
> new type of array mechanism.
>
> User based objects
>
> If doing a lot of multitasking, particularly in a server environment you
> needto be able to have USER table based objects.
>
> Class based objects
>
> A class based object would reside in the member table and be shared by all
> objects in that class.
>
> Why doesn't BUILD call CONSTRUCT?
>
> I'd like to see a uniform object constructor where a method is called
> whenever an instance of the class exists. Either it should be a simple
> deferred method or a more sophisticated version like CONSTRUCT or my
> experimental BUILDER. Currently, SWOOP calls the CONSTRUCT method for all
> objects and instances of objects in LOCAL objects only. But surprisingly
> thisis not array aware so you can not rely on it if you're objects contain
> arrays. I can live with almost any type of constructor as long as it's
> consistent.
>
> ----------------------------------------------------------------------
> sftalk_at_forth.com The SwiftForth programming discussion email list
> To unsubscribe, send subject "unsubscribe sftalk" to listar_at_forth.com
> For help with listar commands, send subject "help" to listar_at_forth.com
> Archives are located at http://www.forth.com/sftalk -- check them out!
> Search the archives! Visit http://www.forth.com/search for details.

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.346 / Virus Database: 194 - Release Date: 4/10/2002
----------------------------------------------------------------------
sftalk_at_forth.com      The SwiftForth programming discussion email list
To unsubscribe,  send subject "unsubscribe sftalk" to listar_at_forth.com
For help with listar commands, send subject "help" to listar_at_forth.com
Archives are located at http://www.forth.com/sftalk -- check them out!
Search the archives!    Visit http://www.forth.com/search for details.
Received on Fri Apr 19 2002 - 19:17:29 PDT

This archive was generated by hypermail 2.2.0 : Fri Nov 21 2008 - 03:04:23 PST