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

Re: Error in CREATE DOES>

From: Elizabeth D Rather <erather_at_forth.com>
Date: Mon, 23 Aug 2004 10:56:27 -0700

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
----------------------------------------------------------------------
Received on Mon Aug 23 2004 - 10:51:07 PDT

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