mirror of
https://github.com/Noratrieb/dilaria.git
synced 2026-01-14 17:35:03 +01:00
docs
This commit is contained in:
parent
15429e67dc
commit
ffeec8e192
3 changed files with 30 additions and 1 deletions
|
|
@ -1,19 +1,43 @@
|
||||||
//! The bytecode that is executed in the vm
|
//! 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::errors::Span;
|
||||||
use crate::vm::Value;
|
use crate::vm::Value;
|
||||||
use bumpalo::collections::Vec;
|
use bumpalo::collections::Vec;
|
||||||
|
|
||||||
|
/// This struct contains all data for a function.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct FnBlock<'bc> {
|
pub struct FnBlock<'bc> {
|
||||||
|
/// The bytecode of the function
|
||||||
pub code: Vec<'bc, Instr>,
|
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>,
|
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>,
|
pub spans: Vec<'bc, Span>,
|
||||||
|
/// How many parameters the function accepts.
|
||||||
pub arity: u8,
|
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)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub enum Instr {
|
pub enum Instr {
|
||||||
|
/// An operation that does nothing.
|
||||||
Nop,
|
Nop,
|
||||||
|
|
||||||
/// Store the current value on the stack to the stack location with the local offset `usize`
|
/// 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),
|
PushVal(Value),
|
||||||
/// Negate the top value on the stack. Only works with numbers and booleans
|
/// Negate the top value on the stack. Only works with numbers and booleans
|
||||||
Neg,
|
Neg,
|
||||||
|
|
||||||
|
// The binary operations. The `rhs` is on top of the stack, and `lhs` is below it
|
||||||
BinAdd,
|
BinAdd,
|
||||||
BinSub,
|
BinSub,
|
||||||
BinMul,
|
BinMul,
|
||||||
|
|
|
||||||
|
|
@ -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::vm::Value;
|
||||||
use crate::{HashMap, HashSet};
|
use crate::{HashMap, HashSet};
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
#![doc = include_str!("../README.md")]
|
||||||
#![deny(clippy::disallowed_type)]
|
#![deny(clippy::disallowed_type)]
|
||||||
|
|
||||||
mod ast;
|
mod ast;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue