feat: ready for JIT
This commit is contained in:
@@ -4,14 +4,11 @@ version = "0.0.0"
|
|||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["vm", "jit", "repl"]
|
|
||||||
vm = []
|
|
||||||
jit = ["dep:inkwell"]
|
|
||||||
repl = ["dep:rustyline"]
|
repl = ["dep:rustyline"]
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "repl-vm"
|
name = "repl"
|
||||||
required-features = ["vm", "repl"]
|
required-features = ["repl"]
|
||||||
|
|
||||||
[profile.perf]
|
[profile.perf]
|
||||||
debug = 1
|
debug = 1
|
||||||
@@ -26,6 +23,6 @@ derive_more = { version = "2.0", features = [ "full" ] }
|
|||||||
ecow = "0.2"
|
ecow = "0.2"
|
||||||
regex = "1.11"
|
regex = "1.11"
|
||||||
|
|
||||||
inkwell = { version = "0.6.0", features = ["llvm18-1"], optional = true }
|
inkwell = { version = "0.6.0", features = ["llvm18-1"] }
|
||||||
|
|
||||||
rustyline = { version = "15.0", optional = true }
|
rustyline = { version = "15.0", optional = true }
|
||||||
|
|||||||
11
src/ir.rs
11
src/ir.rs
@@ -5,8 +5,6 @@ use rnix::ast::{self, Expr};
|
|||||||
|
|
||||||
use crate::compile::*;
|
use crate::compile::*;
|
||||||
use crate::error::*;
|
use crate::error::*;
|
||||||
#[cfg(feature = "jit")]
|
|
||||||
use crate::jit::*;
|
|
||||||
use crate::ty::internal as i;
|
use crate::ty::internal as i;
|
||||||
|
|
||||||
pub fn downgrade(expr: Expr) -> Result<Downgraded> {
|
pub fn downgrade(expr: Expr) -> Result<Downgraded> {
|
||||||
@@ -62,15 +60,6 @@ macro_rules! ir {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "jit")]
|
|
||||||
impl CodeGen for Ir {
|
|
||||||
fn codegen(self, ctx: &JITContext<'_>) {
|
|
||||||
match self {
|
|
||||||
$(Ir::$ty(ir) => ir.codegen(ctx),)*
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$(
|
$(
|
||||||
$(
|
$(
|
||||||
#[$($x)*]
|
#[$($x)*]
|
||||||
|
|||||||
@@ -1,111 +0,0 @@
|
|||||||
#![allow(unused_variables)]
|
|
||||||
|
|
||||||
use crate::ir::*;
|
|
||||||
|
|
||||||
use super::JITContext;
|
|
||||||
|
|
||||||
pub trait CodeGen {
|
|
||||||
fn codegen(self, ctx: &JITContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CodeGen for Attrs {
|
|
||||||
fn codegen(self, ctx: &JITContext) {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CodeGen for List {
|
|
||||||
fn codegen(self, ctx: &JITContext) {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CodeGen for HasAttr {
|
|
||||||
fn codegen(self, ctx: &JITContext) {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CodeGen for BinOp {
|
|
||||||
fn codegen(self, ctx: &JITContext) {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CodeGen for UnOp {
|
|
||||||
fn codegen(self, ctx: &JITContext) {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CodeGen for Select {
|
|
||||||
fn codegen(self, ctx: &JITContext) {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CodeGen for If {
|
|
||||||
fn codegen(self, ctx: &JITContext) {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CodeGen for LoadFunc {
|
|
||||||
fn codegen(self, ctx: &JITContext) {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CodeGen for Call {
|
|
||||||
fn codegen(self, ctx: &JITContext) {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CodeGen for Let {
|
|
||||||
fn codegen(self, ctx: &JITContext) {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CodeGen for With {
|
|
||||||
fn codegen(self, ctx: &JITContext) {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CodeGen for Assert {
|
|
||||||
fn codegen(self, ctx: &JITContext) {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CodeGen for ConcatStrings {
|
|
||||||
fn codegen(self, ctx: &JITContext) {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CodeGen for Const {
|
|
||||||
fn codegen(self, ctx: &JITContext) {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CodeGen for Var {
|
|
||||||
fn codegen(self, ctx: &JITContext) {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CodeGen for Thunk {
|
|
||||||
fn codegen(self, ctx: &JITContext) {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CodeGen for Path {
|
|
||||||
fn codegen(self, ctx: &JITContext) {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
use inkwell::OptimizationLevel;
|
|
||||||
use inkwell::builder::Builder;
|
|
||||||
use inkwell::context::Context;
|
|
||||||
use inkwell::execution_engine::ExecutionEngine;
|
|
||||||
use inkwell::module::Module;
|
|
||||||
|
|
||||||
mod codegen;
|
|
||||||
|
|
||||||
pub use codegen::CodeGen;
|
|
||||||
|
|
||||||
pub struct JITContext<'ctx> {
|
|
||||||
context: &'ctx Context,
|
|
||||||
module: Module<'ctx>,
|
|
||||||
builder: Builder<'ctx>,
|
|
||||||
execution_engine: ExecutionEngine<'ctx>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'ctx> JITContext<'ctx> {
|
|
||||||
pub fn new(context: &Context) -> JITContext {
|
|
||||||
let module = context.create_module("nixjit");
|
|
||||||
JITContext {
|
|
||||||
execution_engine: module
|
|
||||||
.create_jit_execution_engine(OptimizationLevel::None)
|
|
||||||
.unwrap(),
|
|
||||||
builder: context.create_builder(),
|
|
||||||
context,
|
|
||||||
module,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -7,9 +7,6 @@ mod ty;
|
|||||||
pub mod compile;
|
pub mod compile;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod ir;
|
pub mod ir;
|
||||||
#[cfg(feature = "jit")]
|
|
||||||
pub mod jit;
|
|
||||||
#[cfg(feature = "vm")]
|
|
||||||
pub mod vm;
|
pub mod vm;
|
||||||
|
|
||||||
pub use ty::public::Value;
|
pub use ty::public::Value;
|
||||||
|
|||||||
Reference in New Issue
Block a user