This commit is contained in:
nora 2022-01-01 15:12:26 +01:00
parent 15429e67dc
commit ffeec8e192
3 changed files with 30 additions and 1 deletions

View file

@ -1,19 +1,43 @@
//! The bytecode that is executed in the vm
//!
//! # Details
//!
//! ## Function Blocks
//! Every function is compiled into a bytecode block. These blocks are self-contained, and contain
//! all debug- and other information associated with it. The final bytecode is a collection of
//! these blocks.
//!
//! Note: Because of closures, function blocks have more required inputs than just the parameters,
//! but the compiler should handle that correctly.
//!
//! ## Local offsets
//! Variables offsets are calculated as `local offsets`. Local offsets are calculated relative to
//! the start of the space of the stack required by that function. The interpreter must keep track
//! of the stack start of each function, to be able to calculate these offsets.
use crate::errors::Span;
use crate::vm::Value;
use bumpalo::collections::Vec;
/// This struct contains all data for a function.
#[derive(Debug)]
pub struct FnBlock<'bc> {
/// The bytecode of the function
pub code: Vec<'bc, Instr>,
/// The sizes of the stack required by the function at each instruction. This is only used
/// during compilation to calculate local variable offsets.
pub stack_sizes: Vec<'bc, usize>,
/// The corresponding source code location of each instruction. This is debuginfo and only
/// used if there are errors.
pub spans: Vec<'bc, Span>,
/// How many parameters the function accepts.
pub arity: u8,
}
/// A bytecode instruction. For more details on the structure of the bytecode, read the module level docs [`bytecode`](`self`)
#[derive(Debug, Clone, Copy)]
pub enum Instr {
/// An operation that does nothing.
Nop,
/// Store the current value on the stack to the stack location with the local offset `usize`
@ -24,6 +48,8 @@ pub enum Instr {
PushVal(Value),
/// Negate the top value on the stack. Only works with numbers and booleans
Neg,
// The binary operations. The `rhs` is on top of the stack, and `lhs` is below it
BinAdd,
BinSub,
BinMul,

View file

@ -1,4 +1,6 @@
#![allow(dead_code)]
//! The garbage collector for the language
//!
//! The structure of the GC might change, but for now it's simply a `LinkedList` of `Object`s.
use crate::vm::Value;
use crate::{HashMap, HashSet};

View file

@ -1,3 +1,4 @@
#![doc = include_str!("../README.md")]
#![deny(clippy::disallowed_type)]
mod ast;