mirror of
https://github.com/Noratrieb/dilaria.git
synced 2026-01-16 18:35:02 +01:00
more vm and alloc and intern
This commit is contained in:
parent
e58e6e3dc4
commit
dc26b52bd2
8 changed files with 200 additions and 112 deletions
33
src/lib.rs
33
src/lib.rs
|
|
@ -4,29 +4,48 @@ mod ast;
|
|||
mod bytecode;
|
||||
mod compile;
|
||||
mod errors;
|
||||
mod gc;
|
||||
mod lex;
|
||||
mod parse;
|
||||
mod value;
|
||||
mod vm;
|
||||
|
||||
use crate::ast::Program;
|
||||
|
||||
use crate::gc::RtAlloc;
|
||||
pub use bumpalo::Bump;
|
||||
pub use lex::*;
|
||||
pub use parse::*;
|
||||
|
||||
#[cfg(not(feature = "fxhash"))]
|
||||
#[allow(clippy::disallowed_type)]
|
||||
type HashMap<K, V> = std::collections::HashMap<K, V>;
|
||||
|
||||
#[cfg(feature = "fxhash")]
|
||||
type HashMap<K, V> = rustc_hash::FxHashMap<K, V>;
|
||||
|
||||
#[cfg(not(feature = "fxhash"))]
|
||||
#[allow(clippy::disallowed_type)]
|
||||
type HashSet<T> = std::collections::HashSet<T>;
|
||||
|
||||
#[cfg(feature = "fxhash")]
|
||||
type HashSet<T> = rustc_hash::FxHashSet<T>;
|
||||
|
||||
pub fn run_program(program: &str) {
|
||||
let ast_alloc = Bump::new();
|
||||
|
||||
let lexer = lex::Lexer::new(program);
|
||||
// SAFETY: I will try to 🥺
|
||||
let mut runtime = unsafe { RtAlloc::new() };
|
||||
|
||||
let lexer = lex::Lexer::new(program, &mut runtime);
|
||||
let ast = parse::parse(lexer, &ast_alloc);
|
||||
|
||||
match ast {
|
||||
Ok(ast) => process_ast(program, ast),
|
||||
Ok(ast) => process_ast(program, ast, runtime),
|
||||
Err(err) => errors::display_error(program, err),
|
||||
}
|
||||
}
|
||||
|
||||
fn process_ast(program: &str, ast: Program) {
|
||||
fn process_ast(program: &str, ast: Program, runtime: RtAlloc) {
|
||||
println!("AST:\n{:?}\n", ast);
|
||||
|
||||
let bytecode_alloc = Bump::new();
|
||||
|
|
@ -34,7 +53,11 @@ fn process_ast(program: &str, ast: Program) {
|
|||
let bytecode = compile::compile(&ast, &bytecode_alloc);
|
||||
|
||||
match bytecode {
|
||||
Ok(code) => println!("Bytecode:\n{:#?}\n", code),
|
||||
Ok(code) => {
|
||||
println!("Bytecode:\n{:#?}\n", code);
|
||||
|
||||
let _result_lol = vm::execute(&code, runtime);
|
||||
}
|
||||
Err(err) => errors::display_error(program, err),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue