Add vm:📦:Package, instruction disassembly
* Code is compiled into a vm:📦:Package which contains the executable code, the constants, and the local name mappings. Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -2,20 +2,21 @@ pub mod consts;
|
||||
pub mod error;
|
||||
pub mod frame;
|
||||
pub mod inst;
|
||||
pub mod package;
|
||||
|
||||
use crate::{
|
||||
obj::{reserved::*, prelude::*},
|
||||
vm::{consts::*, error::*, frame::*, inst::*},
|
||||
vm::{error::*, frame::*, inst::*, package::*},
|
||||
};
|
||||
use shredder::{GcSafe, Scanner, Scan};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Vm<'c> {
|
||||
pub struct Vm<'p> {
|
||||
stack: Vec<ObjRef>,
|
||||
frames: Vec<Frame>,
|
||||
pc: usize,
|
||||
condition: bool,
|
||||
const_pool: &'c ConstPool,
|
||||
package: &'p Package,
|
||||
}
|
||||
|
||||
unsafe impl Scan for Vm<'_> {
|
||||
@@ -27,17 +28,22 @@ unsafe impl Scan for Vm<'_> {
|
||||
|
||||
unsafe impl GcSafe for Vm<'_> {}
|
||||
|
||||
impl<'c> Vm<'c> {
|
||||
pub fn new(const_pool: &'c ConstPool) -> Self {
|
||||
impl<'p> Vm<'p> {
|
||||
pub fn new(package: &'p Package) -> Self {
|
||||
Self {
|
||||
stack: Default::default(),
|
||||
frames: vec![],
|
||||
pc: 0,
|
||||
condition: false,
|
||||
const_pool,
|
||||
package,
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the package that is currently loaded by this VM.
|
||||
pub fn package(&self) -> &'p Package {
|
||||
self.package
|
||||
}
|
||||
|
||||
/// Gets the current stack frame, if any.
|
||||
pub fn frame(&self) -> Option<&Frame> {
|
||||
self.frames.last()
|
||||
@@ -126,7 +132,10 @@ impl<'c> Vm<'c> {
|
||||
self.push(sym_ref);
|
||||
}
|
||||
Inst::PushConst(hdl) => {
|
||||
let obj_ref = self.const_pool.get(hdl).clone();
|
||||
let obj_ref = self.package()
|
||||
.const_pool()
|
||||
.get(hdl)
|
||||
.clone();
|
||||
self.push(obj_ref);
|
||||
}
|
||||
Inst::LoadName(_sym) => todo!(),
|
||||
|
||||
Reference in New Issue
Block a user