[ 
https://issues.apache.org/jira/browse/LUCY-24?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Marvin Humphrey updated LUCY-24:
--------------------------------

    Attachment: 401-c_block.t
                CBlock.pm
                parser_add_cblock.diff

Boilerplater files are ultimately processed and translated to C header files;
adding support for embedding C code directly within these files spares us
from having to implement a much more sophisticated parser and elaborate
language.  

For instance, one of the first files I commit after Boilerplater is finished
will be NumberUtils.bp, which will contain numerous inline functions.  We use
Boilerplater code to declare and document these functions, then embed the
C "static inline" function bodies between tags.

{code:none}
/** Provide various number-related utilies.
 *
 * Provide utilities for dealing with endian issues, sub-byte-width arrays,
 * compressed integers, and so on.
 */
inert class Lucy0::Util::NumberUtils cnick NumUtil { 

    /** Encode an unsigned 32-bit integer as 4 bytes in the buffer provided,
     * using big-endian byte order.
     */
    inert inline void
    encode_bigend_u32(u32_t value, void *dest);

    /* ... */
}

__C__

static CHY_INLINE void
lucy0_NumUtil_encode_bigend_u32(chy_u32_t value, void *dest_ptr)
{
    chy_u8_t *dest = *(chy_u8_t**)dest_ptr;
#ifdef CHY_BIG_END
    memcpy(dest, &value, sizeof(chy_u32_t));
#else /* little endian */
    chy_u8_t *source = (chy_u8_t*)&value;
    dest[0] = source[3];
    dest[1] = source[2];
    dest[2] = source[1];
    dest[3] = source[0];
#endif /* CHY_BIG_END (and little endian) */
}

/* ... */

__END_C__

{code}

Embedding C like this is much more elegant than relegating it to auxiliary
header files and coming up with a mechanism to pound-include them; the only
only other alternative would be to write a full-blown C parser, and we ain't
gonna go there.


> Boilerplater::CBlock
> --------------------
>
>                 Key: LUCY-24
>                 URL: https://issues.apache.org/jira/browse/LUCY-24
>             Project: Lucy
>          Issue Type: Sub-task
>          Components: Boilerplater
>            Reporter: Marvin Humphrey
>            Assignee: Marvin Humphrey
>         Attachments: 401-c_block.t, CBlock.pm, parser_add_cblock.diff
>
>
> Add support for embedding chunks of raw C code within .bp files.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to