-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VM can now disassemble instructions while executing
- Added better line data representation - Also still moving files around and got rid of the Disassembler trait
- Loading branch information
Showing
7 changed files
with
60 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use crate::vm::block::{Block, Line}; | ||
|
||
impl Block { | ||
pub(super) fn add_line(&mut self, offset: usize, line: usize) { | ||
self.lines.push(Line { offset, line }); | ||
} | ||
|
||
pub(super) fn get_line(&self, offset: usize) -> usize { | ||
let mut line = 0; | ||
let mut low = 0; | ||
let mut high = self.lines.len() - 1; | ||
|
||
while low <= high { | ||
let mid = (low + high) / 2; | ||
let l = self.lines.get(mid).unwrap(); | ||
if l.offset > offset { | ||
high = mid - 1; | ||
} else { | ||
line = l.line; | ||
low = mid + 1; | ||
} | ||
} | ||
line | ||
} | ||
} |
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 |
---|---|---|
@@ -1,24 +1,29 @@ | ||
pub(self) mod block; | ||
mod constants; | ||
mod lines; | ||
mod opcodes; | ||
|
||
#[cfg(feature = "disassemble")] | ||
mod disassembler; | ||
pub(super) mod disassembler; | ||
|
||
pub(crate) use crate::vm::block::opcodes::OpCode; | ||
use crate::vm::vm::Value; | ||
|
||
#[allow(dead_code)] | ||
pub struct Block { | ||
name: String, | ||
constants: Constants, | ||
instructions: Vec<u8>, | ||
lines: Vec<usize>, | ||
lines: Vec<Line>, | ||
} | ||
|
||
type Value = f64; | ||
pub struct Constants { | ||
struct Constants { | ||
values: Vec<Value>, | ||
} | ||
|
||
struct Line { | ||
pub line: usize, | ||
pub offset: usize, | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests; |
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