-
-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
69 additions
and
72 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
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 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 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 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,47 @@ | ||
use crate::{ | ||
vm::{opcode::Operation, CompletionType}, | ||
Context, JsResult, | ||
}; | ||
|
||
/// `GetArgument` implements the Opcode Operation for `Opcode::GetArgument` | ||
/// | ||
/// Operation: | ||
/// - Get i-th argument of the current frame. | ||
#[derive(Debug, Clone, Copy)] | ||
pub(crate) struct GetArgument; | ||
|
||
impl GetArgument { | ||
#[allow(clippy::unnecessary_wraps)] | ||
fn operation(context: &mut Context<'_>, index: usize) -> JsResult<CompletionType> { | ||
let fp = context.vm.frame().fp as usize; | ||
let argument_index = fp + 2; | ||
let argument_count = context.vm.frame().argument_count as usize; | ||
|
||
let value = context.vm.stack[argument_index..(argument_index + argument_count)] | ||
.get(index) | ||
.cloned() | ||
.unwrap_or_default(); | ||
context.vm.push(value); | ||
Ok(CompletionType::Normal) | ||
} | ||
} | ||
|
||
impl Operation for GetArgument { | ||
const NAME: &'static str = "GetArgument"; | ||
const INSTRUCTION: &'static str = "INST - GetArgument"; | ||
|
||
fn execute(context: &mut Context<'_>) -> JsResult<CompletionType> { | ||
let index = context.vm.read::<u8>() as usize; | ||
Self::operation(context, index) | ||
} | ||
|
||
fn execute_with_u16_operands(context: &mut Context<'_>) -> JsResult<CompletionType> { | ||
let index = context.vm.read::<u16>() as usize; | ||
Self::operation(context, index) | ||
} | ||
|
||
fn execute_with_u32_operands(context: &mut Context<'_>) -> JsResult<CompletionType> { | ||
let index = context.vm.read::<u32>() as usize; | ||
Self::operation(context, index) | ||
} | ||
} |
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 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