44#include " context.hpp"
55#include " util.hpp"
66
7- #include < cstring>
8- #include < iostream>
9- #include < cassert>
10-
117namespace cmcpp
128{
139 namespace integer
@@ -53,35 +49,43 @@ namespace cmcpp
5349 }
5450 }
5551
52+ // Boolean ------------------------------------------------------------------
5653 template <Boolean T>
5754 inline void store (LiftLowerContext &cx, const T &v, uint32_t ptr)
5855 {
5956 integer::store<T>(cx, v, ptr);
6057 }
58+ template <Boolean T>
59+ inline WasmValVector lower_flat (LiftLowerContext &cx, const T &v)
60+ {
61+ using WasmValType = WasmValTypeTrait<ValTrait<T>::flat_types[0 ]>::type;
62+ return {static_cast <WasmValType>(v)};
63+ }
6164
62- template <Char T>
63- inline void store (LiftLowerContext &cx, const T &v , uint32_t ptr)
65+ template <Boolean T>
66+ inline T load ( const LiftLowerContext &cx , uint32_t ptr)
6467 {
65- integer::store<T >(cx, char_to_i32 (cx, v), ptr);
68+ return convert_int_to_bool ( integer::load< uint8_t >(cx, ptr) );
6669 }
6770
68- template <Integer T>
69- inline void store ( LiftLowerContext &cx, const T &v, uint32_t ptr )
71+ template <Boolean T>
72+ inline T lift_flat ( const LiftLowerContext &cx, const CoreValueIter &vi )
7073 {
71- integer::store<T>(cx, v, ptr );
74+ return convert_int_to_bool (vi. next < int32_t >() );
7275 }
7376
74- template <SignedInteger T>
75- inline WasmValVector lower_flat (LiftLowerContext &cx, const T &v)
77+ // Char ------------------------------------------------------------------
78+ template <Char T>
79+ inline void store (LiftLowerContext &cx, const T &v, uint32_t ptr)
7680 {
77- using WasmValType = WasmValTypeTrait<ValTrait<T>::flat_types[0 ]>::type;
78- return integer::lower_flat_signed (v, ValTrait<WasmValType>::size * 8 );
81+ integer::store<T>(cx, char_to_i32 (cx, v), ptr);
7982 }
8083
81- template <Boolean T>
82- inline T load ( const LiftLowerContext &cx, uint32_t ptr )
84+ template <Char T>
85+ inline WasmValVector lower_flat ( LiftLowerContext &cx, const T &v )
8386 {
84- return convert_int_to_bool (integer::load<uint8_t >(cx, ptr));
87+ using WasmValType = WasmValTypeTrait<ValTrait<T>::flat_types[0 ]>::type;
88+ return {static_cast <WasmValType>(char_to_i32 (cx, v))};
8589 }
8690
8791 template <Char T>
@@ -90,24 +94,24 @@ namespace cmcpp
9094 return convert_i32_to_char (cx, integer::load<uint32_t >(cx, ptr));
9195 }
9296
93- template <Integer T>
94- inline T load (const LiftLowerContext &cx, uint32_t ptr )
97+ template <Char T>
98+ inline T lift_flat (const LiftLowerContext &cx, const CoreValueIter &vi )
9599 {
96- return integer::load<T> (cx, ptr );
100+ return convert_i32_to_char (cx, vi. next < int32_t >() );
97101 }
98102
99- template <Boolean T>
100- inline WasmValVector lower_flat (LiftLowerContext &cx, const T &v)
103+ // Integer ------------------------------------------------------------------
104+ template <Integer T>
105+ inline void store (LiftLowerContext &cx, const T &v, uint32_t ptr)
101106 {
102- using WasmValType = WasmValTypeTrait<ValTrait<T>::flat_types[0 ]>::type;
103- return {static_cast <WasmValType>(v)};
107+ integer::store<T>(cx, v, ptr);
104108 }
105109
106- template <Char T>
110+ template <SignedInteger T>
107111 inline WasmValVector lower_flat (LiftLowerContext &cx, const T &v)
108112 {
109113 using WasmValType = WasmValTypeTrait<ValTrait<T>::flat_types[0 ]>::type;
110- return { static_cast <WasmValType>( char_to_i32 (cx, v))} ;
114+ return integer::lower_flat_signed (v, ValTrait <WasmValType>::size * 8 ) ;
111115 }
112116
113117 template <UnsignedInteger T>
@@ -118,16 +122,10 @@ namespace cmcpp
118122 return {fv};
119123 }
120124
121- template <Boolean T>
122- inline T lift_flat (const LiftLowerContext &cx, const CoreValueIter &vi)
123- {
124- return convert_int_to_bool (vi.next <int32_t >());
125- }
126-
127- template <Char T>
128- inline T lift_flat (const LiftLowerContext &cx, const CoreValueIter &vi)
125+ template <Integer T>
126+ inline T load (const LiftLowerContext &cx, uint32_t ptr)
129127 {
130- return convert_i32_to_char (cx, vi. next < int32_t >() );
128+ return integer::load<T> (cx, ptr );
131129 }
132130
133131 template <UnsignedInteger T>
0 commit comments