-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Still some tests failing, but added catch & throw instructions as well as exception reference support.
- Loading branch information
Showing
3 changed files
with
62 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use super::Instruction; | ||
use crate::builtins::WasmbinCountable; | ||
use crate::indices::{ExceptionId, LabelId}; | ||
use crate::io::{encode_decode_as, Wasmbin}; | ||
use crate::types::BlockType; | ||
use crate::visit::Visit; | ||
|
||
#[derive(Wasmbin)] | ||
#[repr(u8)] | ||
enum CatchRepr { | ||
Catch { | ||
exception: ExceptionId, | ||
target: LabelId, | ||
} = 0x00, | ||
CatchRef { | ||
exception: ExceptionId, | ||
target: LabelId, | ||
} = 0x01, | ||
CatchAll { | ||
target: LabelId, | ||
} = 0x02, | ||
CatchAllRef { | ||
target: LabelId, | ||
} = 0x03, | ||
} | ||
|
||
#[derive(WasmbinCountable, Debug, PartialEq, Eq, Hash, Clone, Visit)] | ||
pub struct Catch { | ||
/// Whether to store an exception reference on the stack. | ||
pub catch_ref: bool, | ||
/// Catch a specific exception or any exception if set to `None`. | ||
pub exception_filter: Option<ExceptionId>, | ||
/// Target label. | ||
pub target: LabelId, | ||
} | ||
|
||
encode_decode_as!(Catch, { | ||
(Catch { catch_ref: false, exception_filter: Some(exception), target }) <=> (CatchRepr::Catch { exception, target }), | ||
(Catch { catch_ref: true, exception_filter: Some(exception), target }) <=> (CatchRepr::CatchRef { exception, target }), | ||
(Catch { catch_ref: false, exception_filter: None, target }) <=> (CatchRepr::CatchAll { target }), | ||
(Catch { catch_ref: true, exception_filter: None, target }) <=> (CatchRepr::CatchAllRef { target }), | ||
}); | ||
|
||
#[derive(Wasmbin, Debug, PartialEq, Eq, Hash, Clone, Visit)] | ||
pub struct TryTable { | ||
pub block_type: BlockType, | ||
pub catches: Vec<Catch>, | ||
pub instructions: Vec<Instruction>, | ||
} |
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