Skip to content
Snippets Groups Projects
Select Git revision
  • f51f22dd42b16c48b18d36d874ceaaa0840ae10b
  • wip-bootstrap default
  • dualcore
  • ch3/leds
  • ch3/time
  • master
6 results

emitnative.c

Blame
  • emitnative.c 95.21 KiB
    /*
     * This file is part of the Micro Python project, http://micropython.org/
     *
     * The MIT License (MIT)
     *
     * Copyright (c) 2013, 2014 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.
     */
    
    // Essentially normal Python has 1 type: Python objects
    // Viper has more than 1 type, and is just a more complicated (a superset of) Python.
    // If you declare everything in Viper as a Python object (ie omit type decls) then
    // it should in principle be exactly the same as Python native.
    // Having types means having more opcodes, like binary_op_nat_nat, binary_op_nat_obj etc.
    // In practice we won't have a VM but rather do this in asm which is actually very minimal.
    
    // Because it breaks strict Python equivalence it should be a completely separate
    // decorator.  It breaks equivalence because overflow on integers wraps around.
    // It shouldn't break equivalence if you don't use the new types, but since the
    // type decls might be used in normal Python for other reasons, it's probably safest,
    // cleanest and clearest to make it a separate decorator.
    
    // Actually, it does break equivalence because integers default to native integers,
    // not Python objects.
    
    // for x in l[0:8]: can be compiled into a native loop if l has pointer type
    
    #include <stdio.h>
    #include <string.h>
    #include <assert.h>
    
    #include "py/nlr.h"
    #include "py/emit.h"
    #include "py/bc.h"
    
    #if 0 // print debugging info
    #define DEBUG_PRINT (1)
    #define DEBUG_printf DEBUG_printf
    #else // don't print debugging info
    #define DEBUG_printf(...) (void)0
    #endif
    
    // wrapper around everything in this file
    #if (MICROPY_EMIT_X64 && N_X64) \
        || (MICROPY_EMIT_X86 && N_X86) \
        || (MICROPY_EMIT_THUMB && N_THUMB) \
        || (MICROPY_EMIT_ARM && N_ARM) \
        || (MICROPY_EMIT_XTENSA && N_XTENSA) \
    
    // this is defined so that the assembler exports generic assembler API macros
    #define GENERIC_ASM_API (1)
    
    #if N_X64