@@ -7,39 +7,65 @@ namespace cmcpp
77{
88 const bool DETERMINISTIC_PROFILE = false ;
99
10- void trap_if (const CallContext &cx, bool condition, const char *message = nullptr ) noexcept (false );
10+ inline void trap_if (const CallContext &cx, bool condition, const char *message = nullptr ) noexcept (false )
11+ {
12+ if (condition)
13+ {
14+ cx.trap (message);
15+ }
16+ }
17+
18+ inline bool_t convert_int_to_bool (uint8_t i)
19+ {
20+ return i > 0 ;
21+ }
1122
12- bool_t convert_int_to_bool (uint8_t i);
23+ inline char_t convert_i32_to_char (const CallContext &cx, int32_t i)
24+ {
25+ trap_if (cx, i >= 0x110000 );
26+ trap_if (cx, 0xD800 <= i && i <= 0xDFFF );
27+ return i;
28+ }
29+
30+ inline int32_t char_to_i32 (const CallContext &cx, const char_t &v)
31+ {
32+ uint32_t retVal = v;
33+ trap_if (cx, retVal >= 0x110000 );
34+ trap_if (cx, 0xD800 <= retVal && retVal <= 0xDFFF );
35+ return retVal;
36+ }
1337
14- char_t convert_i32_to_char (const CallContext &cx, int32_t i);
15- int32_t char_to_i32 (const CallContext &cx, const char_t &v);
38+ inline int32_t wrap_i64_to_i32 (int64_t x)
39+ {
40+ if (x < std::numeric_limits<int32_t >::lowest () || x > std::numeric_limits<int32_t >::max ())
41+ {
42+ return std::numeric_limits<int32_t >::lowest ();
43+ }
44+ return static_cast <int32_t >(x);
45+ }
1646
1747 class CoreValueIter
1848 {
1949 mutable WasmValVector::const_iterator it;
2050 WasmValVector::const_iterator end;
2151
2252 public:
23- CoreValueIter (const WasmValVector &v);
53+ CoreValueIter (const WasmValVector &v) : it(v.begin()), end(v.end())
54+ {
55+ }
2456
2557 template <FlatValue T>
2658 T next () const
2759 {
2860 return std::get<T>(next (WasmValTrait<T>::type));
2961 }
30- virtual WasmVal next (const WasmValType &t) const ;
62+ virtual WasmVal next (const WasmValType &t) const
63+ {
64+ assert (it != end);
65+ return *it++;
66+ }
3167 };
3268
33- class CoerceValueIter : public CoreValueIter
34- {
35- const CoreValueIter &vi;
36- WasmValTypeVector &flat_types;
37-
38- public:
39- CoerceValueIter (const CoreValueIter &vi, WasmValTypeVector &flat_types);
40-
41- virtual WasmVal next (const WasmValType &t) const override ;
42- };
4369}
4470
4571#endif
0 commit comments