i32 len;
};
+#define OVM_TYPE_NONE 0x00
+#define OVM_TYPE_I8 0x01
+#define OVM_TYPE_I16 0x02
+#define OVM_TYPE_I32 0x03
+#define OVM_TYPE_I64 0x04
+#define OVM_TYPE_F32 0x05
+#define OVM_TYPE_F64 0x06
+#define OVM_TYPE_V128 0x07
+
+struct ovm_value_t {
+ ovm_valtype_t type;
+ union {
+ i8 i8;
+ i16 i16;
+ i32 i32;
+ i64 i64;
+ u8 u8;
+ u16 u16;
+ u32 u32;
+ u64 u64;
+ f32 f32;
+ f64 f64;
+ };
+};
+
+
//
// Represents a program that is runnable by the
// VM. It can be constructed incrementally as needed.
// native functions linked.
bh_arr(ovm_external_func_t) external_funcs;
+ //
+ // Temporary value used in computations. Should not be used otherwise.
+ ovm_value_t __tmp_value;
+
debug_thread_state_t *debug;
};
// with an "infinite" value number (register) count.
//
-#define OVM_TYPE_NONE 0x00
-#define OVM_TYPE_I8 0x01
-#define OVM_TYPE_I16 0x02
-#define OVM_TYPE_I32 0x03
-#define OVM_TYPE_I64 0x04
-#define OVM_TYPE_F32 0x05
-#define OVM_TYPE_F64 0x06
-#define OVM_TYPE_V128 0x07
-
-struct ovm_value_t {
- ovm_valtype_t type;
- union {
- i8 i8;
- i16 i16;
- i32 i32;
- i64 i64;
- u8 u8;
- u16 u16;
- u32 u32;
- u64 u64;
- f32 f32;
- f64 f64;
- };
-};
-
struct ovm_instr_t {
u32 full_instr;
//
// Function calling
-static inline void ovm__func_setup_stack_frame(ovm_state_t *state, ovm_func_t *func, i32 result_number) {
+static void ovm__func_setup_stack_frame(ovm_state_t *state, ovm_func_t *func, i32 result_number) {
//
// Push a stack frame
ovm_stack_frame_t frame;
}
}
-static inline ovm_stack_frame_t ovm__func_teardown_stack_frame(ovm_state_t *state) {
+static ovm_stack_frame_t ovm__func_teardown_stack_frame(ovm_state_t *state) {
ovm_stack_frame_t frame = bh_arr_pop(state->stack_frames);
bh_arr_fastdeleten(state->numbered_values, frame.value_number_count);
return -a;
}
-static inline void __ovm_trigger_exception(ovm_state_t *state) {
+static void __ovm_trigger_exception(ovm_state_t *state) {
if (state->debug) {
state->debug->state = debug_state_pausing;
state->debug->pause_reason = debug_pause_exception;
}
}
-static inline void __ovm_debug_hook(ovm_engine_t *engine, ovm_state_t *state) {
+static void __ovm_debug_hook(ovm_engine_t *engine, ovm_state_t *state) {
if (!state->debug) return;
if (state->debug->run_count == 0) {
memcpy(&VAL(0), &state->params[extra_params], func->param_count * sizeof(ovm_value_t)); \
state->pc = func->start_instr; \
} else { \
- ovm_value_t result = {0}; \
ovm_external_func_t external_func = state->external_funcs[func->external_func_idx]; \
- external_func.native_func(external_func.userdata, &state->params[extra_params], &result); \
+ external_func.native_func(external_func.userdata, &state->params[extra_params], &state->__tmp_value); \
\
ovm__func_teardown_stack_frame(state); \
\
if (instr->r >= 0) { \
- VAL(instr->r) = result; \
+ VAL(instr->r) = state->__tmp_value; \
} \
}
#define OVM_CVT(n1, n2, stype, dtype, otype, ctype) \
OVMI_INSTR_EXEC(ovmi_exec_cvt_##n1##_##n2) { \
- ovm_value_t tmp_val; \
- tmp_val.dtype = (ctype) VAL(instr->a).stype; \
- tmp_val.type = otype; \
- VAL(instr->r) = tmp_val; \
+ state->__tmp_value.dtype = (ctype) VAL(instr->a).stype; \
+ state->__tmp_value.type = otype; \
+ VAL(instr->r) = state->__tmp_value; \
NEXT_OP; \
}