Select Git revision
bootstrap.sh
Forked from
card10 / firmware
Source project has a limited visibility.
runtime.c 37.69 KiB
// in principle, rt_xxx functions are called only by vm/native/viper and make assumptions about args
// mp_xxx functions are safer and can be called by anyone
// note that rt_assign_xxx are called only from emit*, and maybe we can rename them to reflect this
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "nlr.h"
#include "misc.h"
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "runtime0.h"
#include "runtime.h"
#include "map.h"
#include "builtin.h"
#include "objarray.h"
#include "bc.h"
#if 0 // print debugging info
#define DEBUG_PRINT (1)
#define WRITE_CODE (1)
#define DEBUG_printf(args...) printf(args)
#define DEBUG_OP_printf(args...) printf(args)
#else // don't print debugging info
#define DEBUG_printf(args...) (void)0
#define DEBUG_OP_printf(args...) (void)0
#endif
// locals and globals need to be pointers because they can be the same in outer module scope
static mp_map_t *map_locals;
static mp_map_t *map_globals;
static mp_map_t map_builtins;
static mp_map_t map_loaded_modules; // TODO: expose as sys.modules
typedef enum {
MP_CODE_NONE,
MP_CODE_BYTE,
MP_CODE_NATIVE,
MP_CODE_INLINE_ASM,
} mp_code_kind_t;
typedef struct _mp_code_t {
struct {
mp_code_kind_t kind : 8;
bool is_generator : 1;
};
struct {
uint n_args : 16;
uint n_state : 16;
};
union {
struct {
byte *code;
uint len;
} u_byte;
struct {
mp_fun_t fun;
} u_native;
struct {
void *fun;
} u_inline_asm;
};
} mp_code_t;
static uint next_unique_code_id;
static machine_uint_t unique_codes_alloc = 0;