Skip to content
Snippets Groups Projects
Select Git revision
  • 2e84e69a4c24c3cfc38b61a966b358e9f2ca33f4
  • master default protected
  • backslash
  • nickname-match-configs
  • genofire/leds_rgb_get_state
  • genofire/rockets-state
  • genofire/ble-follow-py
  • plaetzchen/ios-workaround
  • blinkisync-as-preload
  • genofire/haule-ble-fs-deactive
  • schneider/max30001-pycardium
  • schneider/max30001-epicaridum
  • schneider/max30001
  • schneider/stream-locks
  • ios-workarounds
  • schneider/fundamental-test
  • schneider/ble-buffers
  • schneider/maxim-sdk-update
  • ch3/splashscreen
  • koalo/bhi160-works-but-dirty
  • koalo/wip/i2c-for-python
  • v1.9
  • v1.8
  • v1.7
  • v1.6
  • v1.5
  • v1.4
  • v1.3
  • v1.2
  • v1.1
  • v1.0
  • release-1
  • bootloader-v1
  • v0.0
34 results

meson.build

Blame
  • Forked from card10 / firmware
    Source project has a limited visibility.
    objarray.c 8.70 KiB
    #include <stdlib.h>
    #include <stdint.h>
    #include <string.h>
    #include <stdarg.h>
    #include <assert.h>
    
    #include "nlr.h"
    #include "misc.h"
    #include "mpconfig.h"
    #include "qstr.h"
    #include "obj.h"
    #include "map.h"
    #include "runtime0.h"
    #include "runtime.h"
    
    // Use special typecode to differentiate repr() of bytearray vs array.array('B')
    // (underlyingly they're same).
    #define BYTEARRAY_TYPECODE 0
    
    typedef struct _mp_obj_array_t {
        mp_obj_base_t base;
        struct {
            machine_uint_t typecode : 8;
            // free is number of unused elements after len used elements
            // alloc size = len + free
            machine_uint_t free : (8 * sizeof(machine_uint_t) - 8);
        };
        machine_uint_t len; // in elements
        void *items;
    } mp_obj_array_t;
    
    static mp_obj_t array_iterator_new(mp_obj_t array_in);
    static mp_obj_array_t *array_new(char typecode, uint n);
    static mp_obj_t array_append(mp_obj_t self_in, mp_obj_t arg);
    
    /******************************************************************************/
    /* array                                                                       */
    
    static machine_int_t array_get_el_size(char typecode) {
        // This assumes that unsigned and signed types are of the same type,
        // which is invariant for [u]intN_t.
        switch (typecode) {
            case BYTEARRAY_TYPECODE:
            case 'b':
            case 'B':
                return sizeof(int8_t);
            case 'h':
            case 'H':
                return sizeof(int16_t);
            case 'i':
            case 'I':
                return sizeof(int32_t);
            case 'l':
            case 'L':
                return sizeof(int32_t);
        }
        return -1;
    }
    
    static machine_int_t array_get_el(mp_obj_array_t *o, int index) {
        machine_int_t val = 0;
        switch (o->typecode) {
            case 'b':
                val = ((int8_t*)o->items)[index];
                break;
            case BYTEARRAY_TYPECODE:
            case 'B':
                val = ((uint8_t*)o->items)[index];
                break;
            case 'h':