pub struct Code<T> {
pub symbols: Vec<(usize, String)>,
pub code: Vec<usize>,
pub data: Vec<T>,
pub labels: Vec<(usize, String)>,
}
Expand description
A structure containing runnable or dumpable code.
See the module-level docs for more details.
Fields§
§symbols: Vec<(usize, String)>
§code: Vec<usize>
§data: Vec<T>
§labels: Vec<(usize, String)>
Implementations§
Source§impl<T: Debug> Code<T>
impl<T: Debug> Code<T>
Sourcepub fn empty() -> Code<T>
pub fn empty() -> Code<T>
Create an empty code.
Not useful for anything except tests and documentation.
Sourcepub fn symbols(&self) -> &[(usize, String)]
pub fn symbols(&self) -> &[(usize, String)]
Retrieve a list of all symbols in the code.
This is a list of tuples containing op codes and instruction names.
Sourcepub fn code(&self) -> &[usize]
pub fn code(&self) -> &[usize]
Retrieve a list of instructions in the code.
This is the executable source program of the code. It is a simple format based around the following:
| Op Code | No of args | Args ... |
| 0x01 | 0x03 | 0x01, 0x02, 0x03 |
Sourcepub fn labels(&self) -> &[(usize, String)]
pub fn labels(&self) -> &[(usize, String)]
Retrieve a list of labels used in the program.
Returns a list of tuples containing the IP of the label and the name of the label.
Sourcepub fn get_label_ip(&self, name: &str) -> Option<usize>
pub fn get_label_ip(&self, name: &str) -> Option<usize>
Returns the IP for a given label.
This function is used within the Machine
to perform jumps.
Trait Implementations§
Source§impl<T: FromByteCode + Debug> FromByteCode for Code<T>
impl<T: FromByteCode + Debug> FromByteCode for Code<T>
Source§impl<T: ToByteCode + Debug> ToByteCode for Code<T>
impl<T: ToByteCode + Debug> ToByteCode for Code<T>
Source§fn to_byte_code(&self, buf: &mut dyn Write)
fn to_byte_code(&self, buf: &mut dyn Write)
Create bytecode for this Code
.
Encodes into a Map of the following format:
{
"code" => [ 0, 1, 0, 0, 1, 1, 1, 0 ],
"data" => [ 123, 456 ],
"symbols" => [ 0, "push", 1, "add" ],
"labels" => [ 0, "main" ]
}
Auto Trait Implementations§
impl<T> Freeze for Code<T>
impl<T> RefUnwindSafe for Code<T>where
T: RefUnwindSafe,
impl<T> Send for Code<T>where
T: Send,
impl<T> Sync for Code<T>where
T: Sync,
impl<T> Unpin for Code<T>where
T: Unpin,
impl<T> UnwindSafe for Code<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more