Details

    • Type: Sub-task Sub-task
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Clownfish
    • Labels:
      None

      Description

      Add support for embedding chunks of raw C code within .bp files.

      1. parser_add_cblock.diff
        0.6 kB
        Marvin Humphrey
      2. CBlock.pm
        1 kB
        Marvin Humphrey
      3. 401-c_block.t
        0.6 kB
        Marvin Humphrey

        Activity

        Hide
        Marvin Humphrey added a comment -

        Committed as r807453.

        Show
        Marvin Humphrey added a comment - Committed as r807453.
        Hide
        Marvin Humphrey added a comment -

        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.

        /** 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__
        
        

        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.

        Show
        Marvin Humphrey added a comment - 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. /** 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__ 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.

          People

          • Assignee:
            Marvin Humphrey
            Reporter:
            Marvin Humphrey
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development