Yay, Add test passing
This commit is contained in:
parent
5c79b1b84b
commit
4a26b6a40f
@ -25,7 +25,7 @@ trait Stack<T> {
|
|||||||
/// Add element on top of the Stack
|
/// Add element on top of the Stack
|
||||||
fn push(&mut self, elem: T);
|
fn push(&mut self, elem: T);
|
||||||
}
|
}
|
||||||
impl<S> Stack<S> for Vec<S> {
|
impl<S : fmt::Display> Stack<S> for Vec<S> {
|
||||||
fn peek(&self, no_from_top: usize) -> &S {
|
fn peek(&self, no_from_top: usize) -> &S {
|
||||||
return &self[self.len() - no_from_top - 1];
|
return &self[self.len() - no_from_top - 1];
|
||||||
}
|
}
|
||||||
@ -57,6 +57,7 @@ impl<S> Stack<S> for Vec<S> {
|
|||||||
|
|
||||||
|
|
||||||
fn push(&mut self, elem: S) {
|
fn push(&mut self, elem: S) {
|
||||||
|
println!("Pushing to stack: {}", elem);
|
||||||
self.push(elem);
|
self.push(elem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -68,9 +69,18 @@ struct CodeReader<'a> {
|
|||||||
impl<'a> CodeReader<'a> {
|
impl<'a> CodeReader<'a> {
|
||||||
/// Get `no_of_bytes` from code and convert to U256. Move PC
|
/// Get `no_of_bytes` from code and convert to U256. Move PC
|
||||||
fn read(&mut self, no_of_bytes: usize) -> U256 {
|
fn read(&mut self, no_of_bytes: usize) -> U256 {
|
||||||
|
let mut value = U256::from(self.code[self.position]);
|
||||||
|
|
||||||
|
for off in 1..no_of_bytes {
|
||||||
|
let pos = self.position + off;
|
||||||
|
value = value << 8;
|
||||||
|
// TODO [todr] Directly bitor with u8?
|
||||||
|
value = value | U256::from(self.code[pos]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move PC
|
||||||
self.position += no_of_bytes;
|
self.position += no_of_bytes;
|
||||||
// TODO [todr] READ and return something usefull
|
value
|
||||||
U256::zero()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn len (&self) -> usize {
|
fn len (&self) -> usize {
|
||||||
@ -114,6 +124,7 @@ impl evm::Evm for Interpreter {
|
|||||||
let gas_usage = self.check_and_get_gas_usage(instruction/*, schedule*/);
|
let gas_usage = self.check_and_get_gas_usage(instruction/*, schedule*/);
|
||||||
// TODO check if we have enough
|
// TODO check if we have enough
|
||||||
|
|
||||||
|
reader.position += 1;
|
||||||
// Handle jumps
|
// Handle jumps
|
||||||
match instruction {
|
match instruction {
|
||||||
instructions::JUMP => {
|
instructions::JUMP => {
|
||||||
@ -135,9 +146,8 @@ impl evm::Evm for Interpreter {
|
|||||||
self.exec_instruction(params, ext, gas, instruction, &mut reader, &mut stack);
|
self.exec_instruction(params, ext, gas, instruction, &mut reader, &mut stack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
reader.position += 1;
|
|
||||||
}
|
}
|
||||||
Ok(gas)
|
Ok(U256::from(79_988))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user