1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
use alloc::{borrow::ToOwned, format};
use ellie_core::defs::PlatformArchitecture;
use crate::{
heap_memory::HeapMemory,
instruction_utils::EXP,
raw_type::StaticRawType,
stack::Stack,
stack_memory::StackMemory,
utils::{AddressingValues, ThreadPanicReason},
};
use super::{ExecuterPanic, ExecuterResult, StaticProgram};
impl super::InstructionExecuter for EXP {
fn execute(
&self,
_heap_memory: &mut HeapMemory,
_program: StaticProgram,
current_stack: &mut Stack,
_stack_memory: &mut StackMemory,
addressing_value: &AddressingValues,
_arch: PlatformArchitecture,
) -> Result<ExecuterResult, ExecuterPanic> {
match &addressing_value {
AddressingValues::Implicit => {
match (
current_stack.registers.B.type_id.id,
current_stack.registers.C.type_id.id,
) {
(1, 1) => {
let b_value = current_stack.registers.B.to_int();
let c_value = current_stack.registers.C.to_int();
let result = match b_value.checked_pow(c_value.try_into().unwrap()) {
Some(e) => e,
None => {
return Err(ExecuterPanic {
reason: ThreadPanicReason::IntegerOverflow,
code_location: format!("{}:{}", file!(), line!()),
});
}
};
current_stack.registers.A = StaticRawType::from_int(result);
}
(2, 2) => {
/* let b_value = current_stack.registers.B.to_float();
let c_value = current_stack.registers.C.to_float();
let result = b_value.powf(c_value);
if result.is_finite() {
current_stack.registers.A = StaticRawType::from_float(result);
} else {
return Err(ExecuterPanic {
reason: ThreadPanicReason::FloatOverflow,
code_location: format!("{}:{}", file!(), line!()),
});
} */
return Err(ExecuterPanic {
reason: ThreadPanicReason::RuntimeError("EXP is todo.".to_owned()),
code_location: format!("{}:{}", file!(), line!()),
});
}
(3, 3) => {
/* let b_value = current_stack.registers.B.to_double();
let c_value = current_stack.registers.C.to_double();
let result = b_value.powf(c_value);
if result.is_finite() {
current_stack.registers.A = StaticRawType::from_double(result);
} else {
return Err(ExecuterPanic {
reason: ThreadPanicReason::DoubleOverflow,
code_location: format!("{}:{}", file!(), line!()),
});
} */
return Err(ExecuterPanic {
reason: ThreadPanicReason::RuntimeError("EXP is todo.".to_owned()),
code_location: format!("{}:{}", file!(), line!()),
});
}
_ => {
return Err(ExecuterPanic {
reason: ThreadPanicReason::UnmergebleTypes(
format!("{}", current_stack.registers.B.type_id),
format!("{}", current_stack.registers.C.type_id),
),
code_location: format!("{}:{}", file!(), line!()),
});
}
};
}
_ => {
return Err(ExecuterPanic {
reason: ThreadPanicReason::IllegalAddressingValue,
code_location: format!("{}:{}", file!(), line!()),
})
}
}
Ok(ExecuterResult::Continue)
}
}