Add basic blocks and implementation of flattening thunks -> basic blocks

* Basic are a more linear way of representing code. Thunks beget basic
  blocks, which beget vectors of instructions.
* Basic blocks are also being flattened into a vector of instructions
  (hopefully, no tests done yet)
* OH yeah locals can be collected too (but currently are not being
  collected in the compiler, that should come soon)

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-09-16 17:18:31 -07:00
parent ef38680fe5
commit 582b3a4b73
14 changed files with 540 additions and 124 deletions

View File

@@ -1,17 +1,6 @@
use crate::obj::prelude::*;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ConstHandle(usize);
impl ConstHandle {
pub fn index(&self) -> usize {
self.0
}
pub fn new(handle: usize) -> Self {
ConstHandle(handle)
}
}
handle_type!(ConstHandle);
#[derive(Debug, Default)]
pub struct ConstPool {

View File

@@ -1,6 +1,5 @@
use crate::obj::prelude::*;
use shredder::{GcSafe, Scan, Scanner};
use std::collections::BTreeMap;
/// A stack call frame.
#[derive(Debug, Clone)]
@@ -25,8 +24,6 @@ unsafe impl Scan for FrameKind {
unsafe impl GcSafe for FrameKind {}
pub type Locals = BTreeMap<usize, ObjRef>;
#[derive(Scan, Debug, Clone)]
pub struct Frame {
locals: Locals,

View File

@@ -25,7 +25,7 @@ pub enum Inst {
///
/// In code, it would look like this:
///
/// target.symbol = source
/// `target.symbol = source`
///
SetAttr(Sym),

View File

@@ -81,8 +81,6 @@ impl<'c> Vm<'c> {
/// Set the next program counter value.
///
/// This may cause the running program to crash. Handle with care.
///
/// TODO : consider making this `unsafe`? Is that appropriate in this context?
pub fn set_pc(&mut self, pc: usize) {
self.pc = pc;
}