Numworks Epsilon  1.4.1
Graphing Calculator Operating System
vm.c File Reference
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "py/emitglue.h"
#include "py/objtype.h"
#include "py/runtime.h"
#include "py/bc0.h"
#include "py/bc.h"

Go to the source code of this file.

Macros

#define TRACE(ip)
 
#define DECODE_UINT
 
#define DECODE_ULABEL   size_t ulab = (ip[0] | (ip[1] << 8)); ip += 2
 
#define DECODE_SLABEL   size_t slab = (ip[0] | (ip[1] << 8)) - 0x8000; ip += 2
 
#define DECODE_QSTR
 
#define DECODE_PTR
 
#define DECODE_OBJ
 
#define PUSH(val)   *++sp = (val)
 
#define POP()   (*sp--)
 
#define TOP()   (*sp)
 
#define SET_TOP(val)   *sp = (val)
 
#define CLEAR_SYS_EXC_INFO()
 
#define PUSH_EXC_BLOCK(with_or_finally)
 
#define POP_EXC_BLOCK()
 
#define SELECTIVE_EXC_IP   (0)
 
#define MARK_EXC_IP_SELECTIVE()
 
#define MARK_EXC_IP_GLOBAL()   { code_state->ip = ip; } /* stores ip pointing to last opcode */
 
#define DISPATCH()   break
 
#define DISPATCH_WITH_PEND_EXC_CHECK()   goto pending_exception_check
 
#define ENTRY(op)   case op
 
#define ENTRY_DEFAULT   default
 
#define RAISE(o)   do { nlr_pop(); nlr.ret_val = MP_OBJ_TO_PTR(o); goto exception_handler; } while (0)
 
#define EXC_MATCH(exc, type)   mp_obj_exception_match(exc, type)
 
#define GENERATOR_EXIT_IF_NEEDED(t)   if (t != MP_OBJ_NULL && EXC_MATCH(t, MP_OBJ_FROM_PTR(&mp_type_GeneratorExit))) { RAISE(t); }
 

Enumerations

enum  mp_unwind_reason_t { UNWIND_RETURN = 1, UNWIND_JUMP }
 

Functions

mp_vm_return_kind_t mp_execute_bytecode (mp_code_state_t *code_state, volatile mp_obj_t inject_exc)
 

Macro Definition Documentation

◆ CLEAR_SYS_EXC_INFO

#define CLEAR_SYS_EXC_INFO ( )

Definition at line 104 of file vm.c.

◆ DECODE_OBJ

#define DECODE_OBJ
Value:
ip = (byte*)MP_ALIGN(ip, sizeof(mp_obj_t)); \
mp_obj_t obj = *(mp_obj_t*)ip; \
ip += sizeof(mp_obj_t)
#define MP_ALIGN(ptr, alignment)
Definition: misc.h:109
unsigned char byte
Definition: misc.h:37
uint64_t mp_obj_t
Definition: obj.h:39

Definition at line 89 of file vm.c.

◆ DECODE_PTR

#define DECODE_PTR
Value:
ip = (byte*)MP_ALIGN(ip, sizeof(void*)); \
void *ptr = *(void**)ip; \
ip += sizeof(void*)
#define MP_ALIGN(ptr, alignment)
Definition: misc.h:109
unsigned char byte
Definition: misc.h:37

Definition at line 85 of file vm.c.

◆ DECODE_QSTR

#define DECODE_QSTR
Value:
qstr qst = 0; \
do { \
qst = (qst << 7) + (*ip & 0x7f); \
} while ((*ip++ & 0x80) != 0)
size_t qstr
Definition: qstr.h:48

Definition at line 81 of file vm.c.

◆ DECODE_SLABEL

#define DECODE_SLABEL   size_t slab = (ip[0] | (ip[1] << 8)) - 0x8000; ip += 2

Definition at line 65 of file vm.c.

◆ DECODE_UINT

#define DECODE_UINT
Value:
mp_uint_t unum = 0; \
do { \
unum = (unum << 7) + (*ip & 0x7f); \
} while ((*ip++ & 0x80) != 0)
uintptr_t mp_uint_t
Definition: mpconfigport.h:74

Definition at line 59 of file vm.c.

◆ DECODE_ULABEL

#define DECODE_ULABEL   size_t ulab = (ip[0] | (ip[1] << 8)); ip += 2

Definition at line 64 of file vm.c.

◆ DISPATCH

#define DISPATCH ( )    break

◆ DISPATCH_WITH_PEND_EXC_CHECK

#define DISPATCH_WITH_PEND_EXC_CHECK ( )    goto pending_exception_check

◆ ENTRY

#define ENTRY (   op)    case op

◆ ENTRY_DEFAULT

#define ENTRY_DEFAULT   default

◆ EXC_MATCH

#define EXC_MATCH (   exc,
  type 
)    mp_obj_exception_match(exc, type)

◆ GENERATOR_EXIT_IF_NEEDED

#define GENERATOR_EXIT_IF_NEEDED (   t)    if (t != MP_OBJ_NULL && EXC_MATCH(t, MP_OBJ_FROM_PTR(&mp_type_GeneratorExit))) { RAISE(t); }

◆ MARK_EXC_IP_GLOBAL

#define MARK_EXC_IP_GLOBAL ( )    { code_state->ip = ip; } /* stores ip pointing to last opcode */

◆ MARK_EXC_IP_SELECTIVE

#define MARK_EXC_IP_SELECTIVE ( )

◆ POP

#define POP ( )    (*sp--)

Definition at line 97 of file vm.c.

◆ POP_EXC_BLOCK

#define POP_EXC_BLOCK ( )
Value:
currently_in_except_block = MP_TAGPTR_TAG0(exc_sp->val_sp); /* restore previous state */ \
exc_sp--; /* pop back to previous exception handler */ \
CLEAR_SYS_EXC_INFO() /* just clear sys.exc_info(), not compliant, but it shouldn't be used in 1st place */
#define MP_TAGPTR_TAG0(x)
Definition: bc.h:106

Definition at line 116 of file vm.c.

◆ PUSH

#define PUSH (   val)    *++sp = (val)

Definition at line 96 of file vm.c.

◆ PUSH_EXC_BLOCK

#define PUSH_EXC_BLOCK (   with_or_finally)
Value:
do { \
DECODE_ULABEL; /* except labels are always forward */ \
++exc_sp; \
exc_sp->handler = ip + ulab; \
exc_sp->val_sp = MP_TAGPTR_MAKE(sp, ((with_or_finally) << 1) | currently_in_except_block); \
exc_sp->prev_exc = NULL; \
currently_in_except_block = 0; /* in a try block now */ \
} while (0)
#define NULL
Definition: stddef.h:4
#define MP_TAGPTR_MAKE(ptr, tag)
Definition: bc.h:108

Definition at line 107 of file vm.c.

◆ RAISE

#define RAISE (   o)    do { nlr_pop(); nlr.ret_val = MP_OBJ_TO_PTR(o); goto exception_handler; } while (0)

◆ SELECTIVE_EXC_IP

#define SELECTIVE_EXC_IP   (0)

◆ SET_TOP

#define SET_TOP (   val)    *sp = (val)

Definition at line 99 of file vm.c.

◆ TOP

#define TOP ( )    (*sp)

Definition at line 98 of file vm.c.

◆ TRACE

#define TRACE (   ip)

Definition at line 41 of file vm.c.

Enumeration Type Documentation

◆ mp_unwind_reason_t

Enumerator
UNWIND_RETURN 
UNWIND_JUMP 

Definition at line 54 of file vm.c.

Function Documentation

◆ mp_execute_bytecode()

mp_vm_return_kind_t mp_execute_bytecode ( mp_code_state_t code_state,
volatile mp_obj_t  inject_exc 
)

Definition at line 127 of file vm.c.