Clean up op codes.
This commit is contained in:
parent
9c4ca23765
commit
7aa93c3986
@ -101,60 +101,9 @@ mov_register(
|
|||||||
)
|
)
|
||||||
----
|
----
|
||||||
|
|
||||||
=== Load Byte
|
=== Load
|
||||||
|
|
||||||
Loads the target register with the `u8` stored at the offset from the base of the object stored in the source register.
|
Loads the target register with the `DvmValue` inner value stored in the field at `field_index` in the object in the
|
||||||
|
|
||||||
[source]
|
|
||||||
----
|
|
||||||
load_byte(
|
|
||||||
target_register: u8,
|
|
||||||
source_register: u8,
|
|
||||||
offset: usize
|
|
||||||
)
|
|
||||||
----
|
|
||||||
|
|
||||||
The source register must contain a `DvmValue::Object` at runtime.
|
|
||||||
|
|
||||||
=== Load Int
|
|
||||||
|
|
||||||
Loads the target register with the `i32` stored at the offset from the base of the object stored in the source register.
|
|
||||||
|
|
||||||
[source]
|
|
||||||
----
|
|
||||||
load_int(
|
|
||||||
target_register: u8,
|
|
||||||
source_register: u8,
|
|
||||||
offset: usize
|
|
||||||
)
|
|
||||||
----
|
|
||||||
|
|
||||||
The source register must contain a `DvmValue::Object` at runtime.
|
|
||||||
|
|
||||||
=== Load Long
|
|
||||||
|
|
||||||
Loads the target register with the `i64` stored at the offset from the base of the object stored in the source register.
|
|
||||||
|
|
||||||
[source]
|
|
||||||
----
|
|
||||||
load_long(
|
|
||||||
target_register: u8,
|
|
||||||
source_register: u8,
|
|
||||||
offset: usize
|
|
||||||
)
|
|
||||||
----
|
|
||||||
|
|
||||||
The source register must contain a `DvmValue::Object` at runtime.
|
|
||||||
|
|
||||||
=== Load Double
|
|
||||||
|
|
||||||
=== Load USize
|
|
||||||
|
|
||||||
=== Load Boolean
|
|
||||||
|
|
||||||
=== Load Object
|
|
||||||
|
|
||||||
Loads the target register with the `DvmValue::Object` stored at the offset from the base of the object stored in the
|
|
||||||
source register.
|
source register.
|
||||||
|
|
||||||
[source]
|
[source]
|
||||||
@ -162,16 +111,15 @@ source register.
|
|||||||
load_object(
|
load_object(
|
||||||
target_register: u8,
|
target_register: u8,
|
||||||
source_register: u8,
|
source_register: u8,
|
||||||
offset: usize
|
field_index: usize
|
||||||
)
|
)
|
||||||
----
|
----
|
||||||
|
|
||||||
The source register must contain a `DvmValue::Object` at runtime, and the data at the offset from that object's base
|
The source register must contain a `DvmValue::Object` at runtime.
|
||||||
must be a valid `Rc<DvmObject>`.
|
|
||||||
|
|
||||||
=== Store
|
=== Store
|
||||||
|
|
||||||
Stores the value contained in the source register to the offset from the base of the object contained in the target
|
Stores the value contained in the source register to the field at `field_index` in the object contained in the target
|
||||||
register.
|
register.
|
||||||
|
|
||||||
[source]
|
[source]
|
||||||
|
@ -30,7 +30,7 @@ impl DvmValue {
|
|||||||
panic!("Expected DvmValue::Object, but found DvmValue::{:?}", self);
|
panic!("Expected DvmValue::Object, but found DvmValue::{:?}", self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_object(&self) -> bool {
|
pub fn is_object(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
DvmValue::Object(_) => true,
|
DvmValue::Object(_) => true,
|
||||||
|
@ -274,6 +274,9 @@ pub fn run_byte_code(state: &mut DvmState, context: &DvmContext, byte_code: &[u8
|
|||||||
let mut iter = byte_code.iter().cloned();
|
let mut iter = byte_code.iter().cloned();
|
||||||
while let Some(op_code) = iter.next() {
|
while let Some(op_code) = iter.next() {
|
||||||
match op_code {
|
match op_code {
|
||||||
|
MOV_BYTE => {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
MOV_INT => {
|
MOV_INT => {
|
||||||
let target_register = next_8!(iter, usize);
|
let target_register = next_8!(iter, usize);
|
||||||
let operand = next_32_le!(iter, u32) as i32;
|
let operand = next_32_le!(iter, u32) as i32;
|
||||||
|
@ -1,46 +1,39 @@
|
|||||||
use crate::push_bytes;
|
pub const MOV_BYTE: u8 = 0x01;
|
||||||
|
pub const MOV_INT: u8 = 0x02;
|
||||||
|
pub const MOV_LONG: u8 = 0x03;
|
||||||
|
pub const MOV_U_SIZE: u8 = 0x04;
|
||||||
|
pub const MOV_DOUBLE: u8 = 0x05;
|
||||||
|
pub const MOV_BOOLEAN: u8 = 0x06;
|
||||||
|
pub const MOV_REGISTER: u8 = 0x07;
|
||||||
|
pub const MOV_CONST: u8 = 0x08;
|
||||||
|
|
||||||
/// ## mov(register: u8, operand: u32)
|
pub const LOAD: u8 = 0x10;
|
||||||
/// - 0: opcode
|
pub const STORE: u8 = 0x11;
|
||||||
/// - 1: register
|
|
||||||
/// - 2..5: operand
|
|
||||||
pub const MOV_INT: u8 = 0x01;
|
|
||||||
|
|
||||||
pub const MOV_LONG: u8 = 0x02;
|
pub const ALLOC: u8 = 0x20;
|
||||||
pub const MOV_DOUBLE: u8 = 0x03;
|
pub const DEALLOC: u8 = 0x21;
|
||||||
|
pub const ALLOC_RAW: u8 = 0x22;
|
||||||
|
pub const DEALLOC_RAW: u8 = 0x23;
|
||||||
|
|
||||||
/// ## mov(target_register: u8, source_register: u8)
|
pub const PLATFORM_CALL: u8 = 0x30;
|
||||||
/// 0: opcode
|
pub const INVOKE_FN: u8 = 0x31;
|
||||||
/// 1: target_register
|
pub const INVOKE_VIRTUAL: u8 = 0x32;
|
||||||
/// 2: source_register
|
pub const INVOKE_DYNAMIC: u8 = 0x33;
|
||||||
pub const MOV_REGISTER: u8 = 0x04;
|
|
||||||
|
|
||||||
/// ## alloc(register: u8, size: u32)
|
pub const ADD: u8 = 0x40;
|
||||||
/// 0: opcode
|
pub const SUBTRACT: u8 = 0x41;
|
||||||
/// 1: register
|
pub const MULTIPLY: u8 = 0x42;
|
||||||
/// 2..5: size
|
pub const DIVIDE: u8 = 0x43;
|
||||||
pub const ALLOC: u8 = 0x05;
|
pub const MODULO: u8 = 0x44;
|
||||||
|
pub const POWER: u8 = 0x45;
|
||||||
|
|
||||||
/// ## dealloc(register: u8)
|
macro_rules! push_bytes {
|
||||||
/// 0: opcode
|
( $dest: expr, $src: expr ) => {
|
||||||
/// 1: register
|
for b in $src {
|
||||||
pub const DEALLOC: u8 = 0x06;
|
$dest.push(b);
|
||||||
|
}
|
||||||
pub const MOV_CONST: u8 = 0x0b;
|
};
|
||||||
|
}
|
||||||
pub const ALLOC_RAW: u8 = 0x0d;
|
|
||||||
pub const DEALLOC_RAW: u8 = 0x0e;
|
|
||||||
|
|
||||||
pub const PLATFORM_CALL: u8 = 0x10;
|
|
||||||
pub const INVOKE_FN: u8 = 0x11;
|
|
||||||
pub const INVOKE_VIRTUAL: u8 = 0x12;
|
|
||||||
pub const INVOKE_DYNAMIC: u8 = 0x14;
|
|
||||||
|
|
||||||
pub const MULTIPLY: u8 = 0x40;
|
|
||||||
|
|
||||||
pub const LOAD: u8 = 0x50;
|
|
||||||
|
|
||||||
pub const STORE: u8 = 0x60;
|
|
||||||
|
|
||||||
macro_rules! push_number {
|
macro_rules! push_number {
|
||||||
( $dest: expr, $num: expr ) => {
|
( $dest: expr, $num: expr ) => {
|
||||||
@ -84,24 +77,14 @@ pub fn add_dealloc(code: &mut Vec<u8>, register: u8) {
|
|||||||
code.push(register);
|
code.push(register);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_load(
|
pub fn add_load(code: &mut Vec<u8>, target_register: u8, source_register: u8, field_index: usize) {
|
||||||
code: &mut Vec<u8>,
|
|
||||||
target_register: u8,
|
|
||||||
source_register: u8,
|
|
||||||
field_index: usize
|
|
||||||
) {
|
|
||||||
code.push(LOAD);
|
code.push(LOAD);
|
||||||
code.push(target_register);
|
code.push(target_register);
|
||||||
code.push(source_register);
|
code.push(source_register);
|
||||||
push_number!(code, field_index);
|
push_number!(code, field_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_store(
|
pub fn add_store(code: &mut Vec<u8>, target_register: u8, field_index: usize, source_register: u8) {
|
||||||
code: &mut Vec<u8>,
|
|
||||||
target_register: u8,
|
|
||||||
field_index: usize,
|
|
||||||
source_register: u8,
|
|
||||||
) {
|
|
||||||
code.push(STORE);
|
code.push(STORE);
|
||||||
code.push(target_register);
|
code.push(target_register);
|
||||||
push_number!(code, field_index);
|
push_number!(code, field_index);
|
||||||
|
@ -22,15 +22,5 @@ macro_rules! get_64_le {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! push_bytes {
|
|
||||||
( $dest: expr, $src: expr ) => {
|
|
||||||
for b in $src {
|
|
||||||
$dest.push(b);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
pub use get_32_le;
|
pub use get_32_le;
|
||||||
pub use get_64_le;
|
pub use get_64_le;
|
||||||
pub use push_bytes;
|
|
||||||
|
Loading…
Reference in New Issue
Block a user