Clean up Operation type
This commit is contained in:
parent
77cb82b9fe
commit
8b06af9634
@ -1,16 +1,10 @@
|
|||||||
//! Part of an [Instruction][crate::Instruction], which can be executed by the Dust virtual machine.
|
//! Part of an [Instruction][crate::Instruction] that is encoded as a single byte.
|
||||||
//!
|
|
||||||
//! !!! Warning !!!
|
|
||||||
//! The byte values of the operations matter. The seventh and eighth bits must be zero so that the
|
|
||||||
//! [Instruction][crate::Instruction] type can use them as flags.
|
|
||||||
|
|
||||||
use std::fmt::{self, Display, Formatter};
|
use std::fmt::{self, Display, Formatter};
|
||||||
|
|
||||||
macro_rules! define_operation {
|
macro_rules! define_operation {
|
||||||
($(($name:ident, $byte:literal, $str:expr, $type:expr)),*) => {
|
($(($name:ident, $byte:literal, $str:expr)),*) => {
|
||||||
/// Part of an [Instruction][crate::Instruction], which can be executed by the Dust virtual machine.)
|
/// Part of an [Instruction][crate::Instruction] that is encoded as a single byte.
|
||||||
///
|
|
||||||
/// See the [module-level documentation](index.html) for more information.
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
pub enum Operation {
|
pub enum Operation {
|
||||||
$(
|
$(
|
||||||
@ -58,31 +52,39 @@ macro_rules! define_operation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
define_operation! {
|
define_operation! {
|
||||||
(Move, 0b0000_0000, "MOVE", None),
|
(Move, 0, "MOVE"),
|
||||||
(Close, 0b000_0001, "CLOSE", None),
|
(Close, 1, "CLOSE"),
|
||||||
(LoadBoolean, 0b0000_0010, "LOAD_BOOLEAN", None),
|
|
||||||
(LoadConstant, 0b0000_0011, "LOAD_CONSTANT", None),
|
(LoadBoolean, 2, "LOAD_BOOLEAN"),
|
||||||
(LoadList, 0b0000_0100, "LOAD_LIST", None),
|
(LoadConstant, 3, "LOAD_CONSTANT"),
|
||||||
(LoadSelf, 0b0000_0101, "LOAD_SELF", None),
|
(LoadList, 4, "LOAD_LIST"),
|
||||||
(DefineLocal, 0b0000_0110, "DEFINE_LOCAL", None),
|
(LoadSelf, 5, "LOAD_SELF"),
|
||||||
(GetLocal, 0b0000_0111, "GET_LOCAL", None),
|
|
||||||
(SetLocal, 0b0000_1000, "SET_LOCAL", None),
|
(DefineLocal, 6, "DEFINE_LOCAL"),
|
||||||
(Add, 0b0000_1001, "ADD", None),
|
(GetLocal, 7, "GET_LOCAL"),
|
||||||
(Subtract, 0b0000_1010, "SUBTRACT", None),
|
(SetLocal, 8, "SET_LOCAL"),
|
||||||
(Multiply, 0b0000_1011, "MULTIPLY", None),
|
|
||||||
(Divide, 0b0000_1100, "DIVIDE", None),
|
(Add, 9, "ADD"),
|
||||||
(Modulo, 0b0000_1101, "MODULO", None),
|
(Subtract, 10, "SUBTRACT"),
|
||||||
(Test, 0b0000_1110, "TEST", None),
|
(Multiply, 11, "MULTIPLY"),
|
||||||
(TestSet, 0b0000_1111, "TEST_SET", None),
|
(Divide, 12, "DIVIDE"),
|
||||||
(Equal, 0b0001_0000, "EQUAL", None),
|
(Modulo, 13, "MODULO"),
|
||||||
(Less, 0b0001_0001, "LESS", None),
|
|
||||||
(LessEqual, 0b0001_0010, "LESS_EQUAL", None),
|
(Test, 14, "TEST"),
|
||||||
(Negate, 0b0001_0011, "NEGATE", None),
|
(TestSet, 15, "TEST_SET"),
|
||||||
(Not, 0b0001_0100, "NOT", None),
|
|
||||||
(Jump, 0b0001_0101, "JUMP", None),
|
(Equal, 16, "EQUAL"),
|
||||||
(Call, 0b0001_0110, "CALL", None),
|
(Less, 17, "LESS"),
|
||||||
(CallNative, 0b0001_0111, "CALL_NATIVE", None),
|
(LessEqual, 18, "LESS_EQUAL"),
|
||||||
(Return, 0b0001_1000, "RETURN", None)
|
|
||||||
|
(Negate, 19, "NEGATE"),
|
||||||
|
(Not, 20, "NOT"),
|
||||||
|
|
||||||
|
(Call, 21, "CALL"),
|
||||||
|
(CallNative, 22, "CALL_NATIVE"),
|
||||||
|
|
||||||
|
(Jump, 23, "JUMP"),
|
||||||
|
(Return, 24, "RETURN")
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Operation {
|
impl Operation {
|
||||||
|
Loading…
Reference in New Issue
Block a user