embedded systems developers tools, cross compilers
  Home  |   SwiftX Archive  |   SwiftForth Archive  |

Re: Error in CREATE DOES>

From: Nestor D. Closa <intec_at_satlink.com>
Date: Mon, 23 Aug 2004 15:30:23 -0300

Sorry Elizabeth, I committed a mistake.
This is the complete code taken from
http://forth.sourceforge.net/word/structure/index.html

: STRUCTURE ( "name" -- xx offset )
    CREATE
      HERE ( leave the address of the following sizeof-comma )
      0 DUP , ( initial size is zero and left on the stack )
    DOES> ( has the address of the sizeof-comma )
      CREATE ( make a variable )
      @ ALLOT ( and make the variable that long )
;

: ENDSTRUCTURE ( xx offset -- )
    SWAP ! ( store the last endoffset into the sizeof-comma )
;

: SIZEOF ( "name" -- size )
    ' >BODY @ ( get the sizeof ... some implementations need also >DOES )
    STATE @ IF [COMPILE] LITERAL THEN
; IMMEDIATE

: NEWFIELD ( offset field_size "name" -- offset' )
    CREATE
      OVER , ( store the current end_offset )
      + ( increase the end_offset by the field_size )
    DOES>
      @ + ( add the memorized offset of the field)
;

Regards,
Nestor Closa

----- Original Message -----
From: "Elizabeth D Rather" <erather_at_forth.com>
To: <swiftx_at_forth.com>
Sent: Monday, August 23, 2004 2:56 PM
Subject: [swiftx] Re: Error in CREATE DOES>

> Since you don't show a stack effect or any other documentation, it's
unclear
> what you're intending to happen here, but I see several peculiar things.
>
> First, the stack effect of your defining part appears to be ( -- addr
addr )
> return two copies of HERE. Second, it's a little unusual to have a CREATE
> in the instance part of a DOES>. It appears as though you're intending to
> define a field in your struct and allocate some space for it, but I don't
> know where the size information is supposed to come from since you're
always
> compiling a zero in the defining part (which is what would be fetched by
the
> @).
>
> Here's a version of STRUCT used in Open Firmware:
>
> \ Structs
> 0 constant struct
> : field ( n1 size -- n2 ) create over , +
> does> ( a1 -- a2 ) @ + ;
>
> Here's an example:
> struct ( scsi registers)
> 0c field >cmd-adr \ Up to 12 command bytes
> 4 field >cmd-len \ Length of command block
> 4 field >data-adr \ Base address of DMA data area
> 4 field >data-len \ Length of data area
> 1 field >host-selectid \ Host's selection ID
> 1 field >target-selectid \ Target's selection ID
> 1 field >input? \ 1 for output, 0 for input
> 1 field >message-out \ Outgoing message byte
> [ more fields ]
> constant /scsi-regs \ Size of register structure
>
> The word struct initializes the process, leaving a 0 on the stack. This
> will be incremented by the size of each field definition, so that at the
end
> the total size of the structure is left on the stack, where it is used as
> the argument for the constant. The structure itself has no name; it acts
as
> a template that may be applied to a data buffer, register bank (as above)
or
> other addressable region.
>
> Hope this helps.
>
> Cheers,
> Elizabeth
>
> > -----Original Message-----
> > From: swiftx-bounce_at_forth.com [mailto:swiftx-bounce_at_forth.com]On Behalf
> > Of Nestor D. Closa
> > Sent: Monday, August 23, 2004 8:40 AM
> > To: swiftx_at_forth.com
> > Subject: [swiftx] Error in CREATE DOES>
> >
> >
> > Why does the CREATE in the DOES> give error?
> > INTERPRETER
> >
> > : STRUCT
> > CREATE
> > HERE DUP 0 ,
> > DOES>
> > CREATE
> > @ ALLOT ;
> >
> > TARGET
> >
> > Regards,
> > Nestor Closa
> > ----------------------------------------------------------------------
> > swiftx_at_forth.com The SwiftX programming discussion email list
> > To unsubscribe, send subject "unsubscribe" to swiftx-request_at_forth.com
> > For list command help, send subject "help" to swiftx-request_at_forth.com
> > Message archives are located at http://www.forth.com/archive/swiftx
> > ----------------------------------------------------------------------
> > This list is a forum for SwiftX users. For product support and bug
> > reports, please send email to support_at_forth.com
> > ----------------------------------------------------------------------
> >
> >
>
> ----------------------------------------------------------------------
> swiftx_at_forth.com The SwiftX programming discussion email list
> To unsubscribe, send subject "unsubscribe" to swiftx-request_at_forth.com
> For list command help, send subject "help" to swiftx-request_at_forth.com
> Message archives are located at http://www.forth.com/archive/swiftx
> ----------------------------------------------------------------------
> This list is a forum for SwiftX users. For product support and bug
> reports, please send email to support_at_forth.com
> ----------------------------------------------------------------------
>
>

----------------------------------------------------------------------
swiftx_at_forth.com The SwiftX programming discussion email list
To unsubscribe, send subject "unsubscribe" to swiftx-request_at_forth.com
For list command help, send subject "help" to swiftx-request_at_forth.com
Message archives are located at http://www.forth.com/archive/swiftx
----------------------------------------------------------------------
This list is a forum for SwiftX users. For product support and bug
reports, please send email to support_at_forth.com
----------------------------------------------------------------------
Received on Mon Aug 23 2004 - 11:29:54 PDT

This archive was generated by hypermail 2.2.0 : Mon Dec 01 2008 - 03:04:49 PST