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:
2020-09-18 15:45:54 -07:00
parent 321fe8e1ea
commit cb5689c513
6 changed files with 136 additions and 105 deletions

View File

@@ -3,7 +3,7 @@ pub mod error;
mod locals;
pub mod thunk;
use crate::{syn::ast::Body, obj::prelude::*, vm::{consts::*, inst::Inst}};
use crate::{syn::ast::Body, obj::prelude::*, vm::{consts::*, package::Package}};
use std::collections::{BTreeMap, HashMap};
#[derive(Default)]
@@ -22,12 +22,12 @@ impl Compile {
}
/// Compiles the given AST body.
pub fn compile<'c>(&'c mut self, body: &Body) -> error::Result<(Vec<Inst>, &'c ConstPool)> {
let main = thunk::CompileBody::new(self)
pub fn compile(mut self, body: &Body) -> error::Result<Package> {
let main = thunk::CompileBody::new(&mut self)
.compile(body)?
.flatten()
.to_vec();
Ok((main, &self.const_data.const_pool))
Ok(Package::new(self.names, self.const_data.const_pool, main))
}
/// Gets the constant data that is interned in this compile session.
@@ -119,6 +119,9 @@ impl Compile {
}
}
/// Constant data pool used for building the const pool.
///
/// This distinguishes between the different types while building a const pool to avoid duplicates.
#[derive(Debug, Default)]
pub struct ConstData {
ints: HashMap<i64, (ConstHandle, IntRef)>,