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

objenumerate.c

Blame
  • compile.c 137.62 KiB
    #include <stdbool.h>
    #include <stdint.h>
    #include <stdio.h>
    #include <string.h>
    #include <assert.h>
    #include <math.h>
    
    #include "misc.h"
    #include "mpconfig.h"
    #include "qstr.h"
    #include "lexer.h"
    #include "parse.h"
    #include "runtime0.h"
    #include "obj.h"
    #include "emitglue.h"
    #include "scope.h"
    #include "emit.h"
    #include "compile.h"
    #include "runtime.h"
    #include "builtin.h"
    #include "smallint.h"
    
    // TODO need to mangle __attr names
    
    #define MICROPY_EMIT_NATIVE (MICROPY_EMIT_X64 || MICROPY_EMIT_THUMB)
    
    typedef enum {
        PN_none = 0,
    #define DEF_RULE(rule, comp, kind, ...) PN_##rule,
    #include "grammar.h"
    #undef DEF_RULE
        PN_maximum_number_of,
    } pn_kind_t;
    
    #define EMIT(fun) (comp->emit_method_table->fun(comp->emit))
    #define EMIT_ARG(fun, ...) (comp->emit_method_table->fun(comp->emit, __VA_ARGS__))
    #define EMIT_INLINE_ASM(fun) (comp->emit_inline_asm_method_table->fun(comp->emit_inline_asm))
    #define EMIT_INLINE_ASM_ARG(fun, ...) (comp->emit_inline_asm_method_table->fun(comp->emit_inline_asm, __VA_ARGS__))
    
    typedef struct _compiler_t {
        qstr source_file;
        uint8_t is_repl;
        uint8_t pass; // holds enum type pass_kind_t
        uint8_t had_error; // try to keep compiler clean from nlr
        uint8_t func_arg_is_super; // used to compile special case of super() function call
    
        uint next_label;
    
        uint break_label;
        uint continue_label;
        int break_continue_except_level;
        uint16_t cur_except_level; // increased for SETUP_EXCEPT, SETUP_FINALLY; decreased for POP_BLOCK, POP_EXCEPT
    
        uint8_t have_star;
        uint16_t num_dict_params;
        uint16_t num_default_params;
    
        scope_t *scope_head;
        scope_t *scope_cur;
    
        emit_t *emit;                                   // current emitter
        const emit_method_table_t *emit_method_table;   // current emit method table
    
        emit_inline_asm_t *emit_inline_asm;                                   // current emitter for inline asm
        const emit_inline_asm_method_table_t *emit_inline_asm_method_table;   // current emit method table for inline asm
    } compiler_t;
    
    STATIC void compile_syntax_error(compiler_t *comp, mp_parse_node_t pn, const char *msg) {
        // TODO store the error message to a variable in compiler_t instead of printing it
        if (MP_PARSE_NODE_IS_STRUCT(pn)) {