Select Git revision
Forked from
card10 / firmware
Source project has a limited visibility.
compile.c 126.82 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 "scope.h"
#include "runtime0.h"
#include "emit.h"
#include "emitglue.h"
#include "obj.h"
#include "compile.h"
#include "runtime.h"
#include "intdivmod.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__))
#define EMIT_OPT_NONE (0)
#define EMIT_OPT_BYTE_CODE (1)
#define EMIT_OPT_NATIVE_PYTHON (2)
#define EMIT_OPT_VIPER (3)
#define EMIT_OPT_ASM_THUMB (4)
typedef struct _compiler_t {
qstr source_file;
bool is_repl;
pass_kind_t pass;
bool had_error; // try to keep compiler clean from nlr
int next_label;
int break_label;
int continue_label;
int break_continue_except_level;
int cur_except_level; // increased for SETUP_EXCEPT, SETUP_FINALLY; decreased for POP_BLOCK, POP_EXCEPT
int n_arg_keyword;
bool have_star_arg;
bool have_dbl_star_arg;
bool have_bare_star;
int param_pass;
int param_pass_num_dict_params;
int param_pass_num_default_params;
bool func_arg_is_super; // used to compile special case of super() function call
scope_t *scope_head;
scope_t *scope_cur;