This repository has been archived by the owner on Jan 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Follows FuelLabs/fuel-asm#34
- Loading branch information
Showing
5 changed files
with
74 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ repository = "https:/FuelLabs/fuel-tx" | |
description = "FuelVM transaction." | ||
|
||
[dependencies] | ||
fuel-asm = { git = "ssh://[email protected]/FuelLabs/fuel-asm.git", default-features = false } | ||
fuel-asm = { git = "ssh://[email protected]/FuelLabs/fuel-asm.git", default-features = false, branch = "vlopes11/panic-reason" } | ||
fuel-types = { git = "ssh://[email protected]/FuelLabs/fuel-types.git", default-features = false } | ||
itertools = { version = "0.10", optional = true } | ||
rand = { version = "0.8", optional = true } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use fuel_asm::{Instruction, Opcode, PanicReason}; | ||
use fuel_types::Word; | ||
|
||
use std::mem; | ||
|
||
const WORD_SIZE: usize = mem::size_of::<Word>(); | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
#[cfg_attr(feature = "serde-types", derive(serde::Serialize, serde::Deserialize))] | ||
pub struct ScriptResult { | ||
result: PanicReason, | ||
instruction: Instruction, | ||
} | ||
|
||
impl ScriptResult { | ||
pub const fn new(result: PanicReason, instruction: Instruction) -> Self { | ||
Self { | ||
result, | ||
instruction, | ||
} | ||
} | ||
|
||
pub const fn result(&self) -> &PanicReason { | ||
&self.result | ||
} | ||
|
||
pub const fn instruction(&self) -> &Instruction { | ||
&self.instruction | ||
} | ||
} | ||
|
||
const RESULT_OFFSET: Word = (WORD_SIZE * 8 - 8) as Word; | ||
const INSTR_OFFSET: Word = ((WORD_SIZE - mem::size_of::<u32>()) * 8 - 8) as Word; | ||
|
||
impl From<ScriptResult> for Word { | ||
fn from(r: ScriptResult) -> Word { | ||
let result = Word::from(r.result); | ||
let instruction = u32::from(r.instruction) as Word; | ||
|
||
(result << RESULT_OFFSET) | (instruction << INSTR_OFFSET) | ||
} | ||
} | ||
|
||
impl From<Word> for ScriptResult { | ||
fn from(val: Word) -> Self { | ||
let result = PanicReason::from(val >> RESULT_OFFSET); | ||
let instruction = Instruction::from((val >> INSTR_OFFSET) as u32); | ||
|
||
Self::new(result, instruction) | ||
} | ||
} | ||
|
||
impl From<ScriptResult> for Instruction { | ||
fn from(r: ScriptResult) -> Self { | ||
r.instruction | ||
} | ||
} | ||
|
||
impl From<ScriptResult> for Opcode { | ||
fn from(r: ScriptResult) -> Self { | ||
r.instruction.into() | ||
} | ||
} | ||
|
||
impl From<ScriptResult> for PanicReason { | ||
fn from(r: ScriptResult) -> Self { | ||
r.result | ||
} | ||
} |