restructure runtime

This commit is contained in:
nora 2022-04-26 20:18:23 +02:00
parent 266eeb7327
commit 6563a7bd6c
8 changed files with 20 additions and 16 deletions

View file

@ -5,15 +5,17 @@ use std::{cell::RefCell, rc::Rc};
use bumpalo::{collections::Vec, Bump}; use bumpalo::{collections::Vec, Bump};
use crate::{ use crate::{
bytecode::{FnBlock, Instr},
errors::{CompilerError, Span}, errors::{CompilerError, Span},
gc::Symbol, runtime::{
bytecode::{FnBlock, Instr},
gc::{RtAlloc, Symbol},
vm::Value,
},
syntax::ast::{ syntax::ast::{
Assignment, BinaryOp, BinaryOpKind, Block, Call, CallKind, Declaration, ElsePart, Expr, Assignment, BinaryOp, BinaryOpKind, Block, Call, CallKind, Declaration, ElsePart, Expr,
FnDecl, Ident, IfStmt, Literal, Program, Stmt, UnaryOp, WhileStmt, FnDecl, Ident, IfStmt, Literal, Program, Stmt, UnaryOp, WhileStmt,
}, },
vm::Value, HashMap,
HashMap, RtAlloc,
}; };
type CResult<T = ()> = Result<T, CompilerError>; type CResult<T = ()> = Result<T, CompilerError>;

View file

@ -1,12 +1,10 @@
#![deny(clippy::disallowed_types)] #![deny(clippy::disallowed_types)]
mod bytecode;
mod compile; mod compile;
mod errors; mod errors;
mod gc; mod runtime;
mod syntax; mod syntax;
mod util; mod util;
mod vm;
use std::io::Write; use std::io::Write;
@ -14,7 +12,7 @@ pub use bumpalo::Bump;
pub use crate::syntax::{lex::*, parse::*}; pub use crate::syntax::{lex::*, parse::*};
use crate::{ use crate::{
gc::RtAlloc, runtime::gc::RtAlloc,
syntax::{ast::Program, lex, parse}, syntax::{ast::Program, lex, parse},
}; };
@ -72,7 +70,7 @@ fn process_ast(program: &str, ast: &Program, mut runtime: RtAlloc, cfg: &mut Con
util::dbg("Bytecode:\n", code); util::dbg("Bytecode:\n", code);
} }
let result = vm::execute(code, runtime, cfg); let result = runtime::vm::execute(code, runtime, cfg);
if let Err(msg) = result { if let Err(msg) = result {
eprintln!("error: {msg}"); eprintln!("error: {msg}");
} }

View file

@ -62,7 +62,7 @@ use std::fmt::{Debug, Formatter};
use bumpalo::collections::Vec; use bumpalo::collections::Vec;
use crate::{errors::Span, vm::Value}; use crate::{errors::Span, runtime::vm::Value};
/// This struct contains all data for a function. /// This struct contains all data for a function.
pub struct FnBlock<'bc> { pub struct FnBlock<'bc> {

View file

@ -12,7 +12,7 @@ use std::{
use dbg_pls::DebugPls; use dbg_pls::DebugPls;
use crate::{vm::Value, HashMap, HashSet}; use crate::{runtime::vm::Value, HashMap, HashSet};
/// A pointer to a garbage collected value. This pointer *must* always be valid, and a value /// A pointer to a garbage collected value. This pointer *must* always be valid, and a value
/// is only allowed to be freed once no Gc is pointing at it anymore. This is achieved through /// is only allowed to be freed once no Gc is pointing at it anymore. This is achieved through

3
src/runtime/mod.rs Normal file
View file

@ -0,0 +1,3 @@
pub mod bytecode;
pub mod gc;
pub mod vm;

View file

@ -4,8 +4,10 @@ use std::{
}; };
use crate::{ use crate::{
bytecode::{FnBlock, Function, Instr}, runtime::{
gc::{Object, RtAlloc, Symbol}, bytecode::{FnBlock, Function, Instr},
gc::{Object, RtAlloc, Symbol},
},
util, Config, util, Config,
}; };

View file

@ -3,7 +3,7 @@
//! //!
//! All AST nodes are bump allocated into the lifetime `'ast` //! All AST nodes are bump allocated into the lifetime `'ast`
use crate::{errors::Span, gc::Symbol}; use crate::{errors::Span, runtime::gc::Symbol};
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)] #[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
#[cfg_attr(feature = "_debug", derive(dbg_pls::DebugPls))] #[cfg_attr(feature = "_debug", derive(dbg_pls::DebugPls))]

View file

@ -8,8 +8,7 @@ use std::{iter::Peekable, str::CharIndices};
use crate::{ use crate::{
errors::{CompilerError, Span}, errors::{CompilerError, Span},
gc::Symbol, runtime::gc::{RtAlloc, Symbol},
RtAlloc,
}; };
/// ///