Skip to content
Snippets Groups Projects
Select Git revision
  • 86d57a6574b56e85fd63719e3840349eceaaf2b7
  • master default protected
  • feat/run-py
  • feat/py-trng
  • rahix/freertos10
  • ch3/leds-api
  • ch3/genapi-refactor
  • ch3/dual-core
  • dualcore
9 results

BufferAllocation_1.c

Blame
  • Forked from card10 / firmware
    Source project has a limited visibility.
    persistentcode.c 12.47 KiB
    /*
     * This file is part of the MicroPython project, http://micropython.org/
     *
     * The MIT License (MIT)
     *
     * Copyright (c) 2013-2016 Damien P. George
     *
     * Permission is hereby granted, free of charge, to any person obtaining a copy
     * of this software and associated documentation files (the "Software"), to deal
     * in the Software without restriction, including without limitation the rights
     * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     * copies of the Software, and to permit persons to whom the Software is
     * furnished to do so, subject to the following conditions:
     *
     * The above copyright notice and this permission notice shall be included in
     * all copies or substantial portions of the Software.
     *
     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
     * THE SOFTWARE.
     */
    
    #include <stdint.h>
    #include <stdio.h>
    #include <string.h>
    #include <assert.h>
    
    #include "py/reader.h"
    #include "py/emitglue.h"
    #include "py/persistentcode.h"
    #include "py/bc.h"
    
    #if MICROPY_PERSISTENT_CODE_LOAD || MICROPY_PERSISTENT_CODE_SAVE
    
    #include "py/smallint.h"
    
    // The feature flags byte encodes the compile-time config options that
    // affect the generate bytecode.
    #define MPY_FEATURE_FLAGS ( \
        ((MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE) << 0) \
        | ((MICROPY_PY_BUILTINS_STR_UNICODE) << 1) \
        )
    // This is a version of the flags that can be configured at runtime.
    #define MPY_FEATURE_FLAGS_DYNAMIC ( \
        ((MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE_DYNAMIC) << 0) \
        | ((MICROPY_PY_BUILTINS_STR_UNICODE_DYNAMIC) << 1) \
        )
    
    #if MICROPY_PERSISTENT_CODE_LOAD || (MICROPY_PERSISTENT_CODE_SAVE && !MICROPY_DYNAMIC_COMPILER)
    // The bytecode will depend on the number of bits in a small-int, and
    // this function computes that (could make it a fixed constant, but it
    // would need to be defined in mpconfigport.h).
    STATIC int mp_small_int_bits(void) {
        mp_int_t i = MP_SMALL_INT_MAX;
        int n = 1;
        while (i != 0) {
            i >>= 1;
            ++n;
        }
        return n;
    }
    #endif
    
    typedef struct _bytecode_prelude_t {
        uint n_state;
        uint n_exc_stack;