MCPcopy Create free account
hub / github.com/explodingcamera/tinywasm / exec

Method exec

crates/tinywasm/src/interpreter/executor.rs:113–823  ·  view source on GitHub ↗
(&mut self)

Source from the content-addressed store, hash-verified

111
112 #[inline(always)]
113 fn exec(&mut self) -> Result<Option<()>, Trap> {
114 macro_rules! stack_op {
115 (unary $ty:ty, |$v:ident| $expr:expr) => {{
116 let $v = <$ty>::stack_pop(&mut self.store.value_stack);
117 <$ty>::stack_push(&mut self.store.value_stack, $expr)?;
118 }};
119 (binary $ty:ty, |$lhs:ident, $rhs:ident| $expr:expr) => {{
120 let $rhs = <$ty>::stack_pop(&mut self.store.value_stack);
121 let $lhs = <$ty>::stack_pop(&mut self.store.value_stack);
122 <$ty>::stack_push(&mut self.store.value_stack, $expr)?;
123 }};
124 (binary try $ty:ty, |$lhs:ident, $rhs:ident| $expr:expr) => {{
125 let $rhs = <$ty>::stack_pop(&mut self.store.value_stack);
126 let $lhs = <$ty>::stack_pop(&mut self.store.value_stack);
127 <$ty>::stack_push(&mut self.store.value_stack, $expr?)?;
128 }};
129 (unary $from:ty => $to:ty, |$v:ident| $expr:expr) => {{
130 let $v = <$from>::stack_pop(&mut self.store.value_stack);
131 <$to>::stack_push(&mut self.store.value_stack, $expr)?;
132 }};
133 (binary $from:ty => $to:ty, |$lhs:ident, $rhs:ident| $expr:expr) => {{
134 let $rhs = <$from>::stack_pop(&mut self.store.value_stack);
135 let $lhs = <$from>::stack_pop(&mut self.store.value_stack);
136 <$to>::stack_push(&mut self.store.value_stack, $expr)?;
137 }};
138 (binary_into2 $from:ty => $to:ty, |$lhs:ident, $rhs:ident| $expr:expr) => {{
139 let $rhs = <$from>::stack_pop(&mut self.store.value_stack);
140 let $lhs = <$from>::stack_pop(&mut self.store.value_stack);
141 let out = $expr;
142 <$to>::stack_push(&mut self.store.value_stack, out.0)?;
143 <$to>::stack_push(&mut self.store.value_stack, out.1)?;
144 }};
145 (binary $lhs_ty:ty, $rhs_ty:ty, |$lhs:ident, $rhs:ident| $expr:expr) => {
146 stack_op!(binary $lhs_ty, $rhs_ty => $rhs_ty, |$lhs, $rhs| $expr)
147 };
148 (binary $lhs_ty:ty, $rhs_ty:ty => $res:ty, |$lhs:ident, $rhs:ident| $expr:expr) => {{
149 let $rhs = <$rhs_ty>::stack_pop(&mut self.store.value_stack);
150 let $lhs = <$lhs_ty>::stack_pop(&mut self.store.value_stack);
151 <$res>::stack_push(&mut self.store.value_stack, $expr)?;
152 }};
153 (ternary $ty:ty, |$a:ident, $b:ident, $c:ident| $expr:expr) => {{
154 let $c = <$ty>::stack_pop(&mut self.store.value_stack);
155 let $b = <$ty>::stack_pop(&mut self.store.value_stack);
156 let $a = <$ty>::stack_pop(&mut self.store.value_stack);
157 <$ty>::stack_push(&mut self.store.value_stack, $expr)?;
158 }};
159 (quaternary_into2 $from:ty => $to:ty, |$a:ident, $b:ident, $c:ident, $d:ident| $expr:expr) => {{
160 let $d = <$from>::stack_pop(&mut self.store.value_stack);
161 let $c = <$from>::stack_pop(&mut self.store.value_stack);
162 let $b = <$from>::stack_pop(&mut self.store.value_stack);
163 let $a = <$from>::stack_pop(&mut self.store.value_stack);
164 let out = $expr;
165 <$to>::stack_push(&mut self.store.value_stack, out.0)?;
166 <$to>::stack_push(&mut self.store.value_stack, out.1)?;
167 }};
168 (local_set_pop $ty:ty, $local_index:expr) => {{
169 let val = <$ty>::stack_pop(&mut self.store.value_stack);
170 <$ty>::local_set(&mut self.store.value_stack, &self.cf, *$local_index, val);

Callers 3

run_to_completionMethod · 0.45
run_with_time_budgetMethod · 0.45
run_with_fuelMethod · 0.45

Calls 15

Value128Class · 0.85
select_multiMethod · 0.80
exec_call_directMethod · 0.80
exec_call_selfMethod · 0.80
exec_return_call_selfMethod · 0.80
exec_jump_zero_32Method · 0.80
exec_jump_non_zero_32Method · 0.80
exec_jump_zero_64Method · 0.80
exec_jump_non_zero_64Method · 0.80

Tested by

no test coverage detected