mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-23 18:21:13 +08:00
refactor: 将基础类型定义放在单独 crate 以解决循环依赖
This commit is contained in:
Generated
+13
-3
@@ -786,7 +786,7 @@ dependencies = [
|
||||
"hashbrown 0.14.5",
|
||||
"oxide_compiler",
|
||||
"oxide_parser",
|
||||
"oxide_vm",
|
||||
"oxide_types",
|
||||
"rustc-hash",
|
||||
]
|
||||
|
||||
@@ -803,14 +803,24 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "oxide_vm"
|
||||
name = "oxide_types"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"fast-float",
|
||||
"hashbrown 0.14.5",
|
||||
"proptest",
|
||||
"rustc-hash",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "oxide_vm"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"fast-float",
|
||||
"oxide_compiler",
|
||||
"oxide_kernel",
|
||||
"oxide_parser",
|
||||
"oxide_types",
|
||||
"proptest",
|
||||
"rustc-hash",
|
||||
"ryu",
|
||||
|
||||
@@ -3,6 +3,7 @@ resolver = "2"
|
||||
members = [
|
||||
"crates/oxide_parser",
|
||||
"crates/oxide_compiler",
|
||||
"crates/oxide_types",
|
||||
"crates/oxide_vm",
|
||||
"crates/oxide_kernel",
|
||||
"crates/oxide_api",
|
||||
|
||||
@@ -5,8 +5,8 @@ use ansi_term::Colour::Red;
|
||||
use clap::{Parser, Subcommand};
|
||||
use oxide_compiler::compiler::Compiler;
|
||||
use oxide_parser::Allocator;
|
||||
use oxide_vm::value::JsValue;
|
||||
use oxide_vm::vm::Vm;
|
||||
use oxide_vm::JsValue;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(name = "oxide", version, about = "OxideJS - Rust JavaScript engine")]
|
||||
|
||||
@@ -4,12 +4,12 @@ version.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
rust-version.workspace = true
|
||||
description = "OxideJS - Shared kernel (CodeForge, ShapeForge, IcForge, StringForge, BuiltinWorld)"
|
||||
description = "OxideJS - Shared kernel (CodeForge, ShapeForge, PropForge, StringForge, BuiltinWorld)"
|
||||
|
||||
[dependencies]
|
||||
oxide_compiler = { path = "../oxide_compiler" }
|
||||
oxide_parser = { path = "../oxide_parser" }
|
||||
oxide_vm = { path = "../oxide_vm" }
|
||||
oxide_types = { path = "../oxide_types" }
|
||||
bumpalo.workspace = true
|
||||
dashmap.workspace = true
|
||||
hashbrown.workspace = true
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use oxide_vm::mem::P;
|
||||
use oxide_vm::object::JsObject;
|
||||
use oxide_vm::value::JsValue;
|
||||
use oxide_types::mem::P;
|
||||
use oxide_types::object::JsObject;
|
||||
use oxide_types::value::JsValue;
|
||||
|
||||
use crate::shape_forge::{ShapeForge, EMPTY_SHAPE_ID};
|
||||
use crate::string_forge::Interner;
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
#![allow(clippy::arc_with_non_send_sync)]
|
||||
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::builtin::BuiltinWorld;
|
||||
use crate::code_forge::CodeForge;
|
||||
use crate::prop_forge::PropForge;
|
||||
use crate::shape_forge::ShapeForge;
|
||||
use crate::string_forge::Interner;
|
||||
use crate::vm_pool::{VmGuard, VmPool};
|
||||
|
||||
pub struct KernelConfig {
|
||||
pub min_pool_size: usize,
|
||||
@@ -66,8 +65,6 @@ pub struct OxideKernel {
|
||||
pub code_forge: Arc<CodeForge>,
|
||||
pub prop_forge: Arc<PropForge>,
|
||||
pub builtin_world: Arc<BuiltinWorld>,
|
||||
#[allow(dead_code)]
|
||||
vm_pool: Mutex<Option<Arc<VmPool>>>,
|
||||
}
|
||||
|
||||
impl OxideKernel {
|
||||
@@ -85,28 +82,9 @@ impl OxideKernel {
|
||||
code_forge,
|
||||
prop_forge,
|
||||
builtin_world,
|
||||
vm_pool: Mutex::new(None),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init_vm_pool(self: &Arc<Self>) {
|
||||
let pool = VmPool::new(
|
||||
Arc::clone(self),
|
||||
self.config.min_pool_size,
|
||||
self.config.max_pool_size,
|
||||
);
|
||||
*self.vm_pool.lock().unwrap() = Some(pool);
|
||||
}
|
||||
|
||||
pub fn spawn(&self) -> VmGuard {
|
||||
self.vm_pool
|
||||
.lock()
|
||||
.unwrap()
|
||||
.as_ref()
|
||||
.expect("vm_pool not initialized — call init_vm_pool() first")
|
||||
.spawn()
|
||||
}
|
||||
|
||||
pub fn string_forge(&self) -> &Arc<Interner> {
|
||||
&self.string_forge
|
||||
}
|
||||
@@ -173,14 +151,4 @@ mod tests {
|
||||
assert!(KernelConfig::full().warmup_builtin_ic);
|
||||
assert_eq!(KernelConfig::full().max_pool_size, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_kernel_spawn() {
|
||||
let kernel = Arc::new(OxideKernel::new(KernelConfig::minimal()));
|
||||
kernel.init_vm_pool();
|
||||
let guard = kernel.spawn();
|
||||
drop(guard);
|
||||
let guard2 = kernel.spawn();
|
||||
drop(guard2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,4 +6,3 @@ pub mod kernel;
|
||||
pub mod prop_forge;
|
||||
pub mod shape_forge;
|
||||
pub mod string_forge;
|
||||
pub mod vm_pool;
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
[package]
|
||||
name = "oxide_types"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
rust-version.workspace = true
|
||||
description = "OxideJS - Shared core types (JsValue, JsObject, Shape, P, Epoch)"
|
||||
|
||||
[dependencies]
|
||||
bumpalo.workspace = true
|
||||
hashbrown.workspace = true
|
||||
rustc-hash.workspace = true
|
||||
|
||||
[dev-dependencies]
|
||||
proptest.workspace = true
|
||||
@@ -0,0 +1,6 @@
|
||||
#![doc = "OxideJS - Shared core types (JsValue, JsObject, Shape, P, Epoch)"]
|
||||
|
||||
pub mod mem;
|
||||
pub mod object;
|
||||
pub mod shape;
|
||||
pub mod value;
|
||||
@@ -8,8 +8,8 @@ description = "OxideJS - Register-based VM with epoch arena memory"
|
||||
|
||||
[dependencies]
|
||||
oxide_compiler = { path = "../oxide_compiler" }
|
||||
bumpalo.workspace = true
|
||||
hashbrown.workspace = true
|
||||
oxide_kernel = { path = "../oxide_kernel" }
|
||||
oxide_types = { path = "../oxide_types" }
|
||||
rustc-hash.workspace = true
|
||||
fast-float.workspace = true
|
||||
ryu.workspace = true
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::object::JsObject;
|
||||
use crate::shape::EMPTY_SHAPE_ID;
|
||||
use crate::value::JsValue;
|
||||
use crate::vm::Vm;
|
||||
use oxide_types::object::JsObject;
|
||||
use oxide_types::shape::EMPTY_SHAPE_ID;
|
||||
use oxide_types::value::JsValue;
|
||||
|
||||
pub fn to_primitive(val: JsValue) -> JsValue {
|
||||
if val.is_object() {
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
#![doc = "OxideJS - Register-based VM with epoch arena memory"]
|
||||
|
||||
pub mod coercion;
|
||||
pub mod mem;
|
||||
pub mod object;
|
||||
pub mod shape;
|
||||
pub mod value;
|
||||
pub mod vm;
|
||||
pub use value::JsValue;
|
||||
pub mod vm_pool;
|
||||
pub use oxide_types::value::JsValue;
|
||||
|
||||
@@ -5,10 +5,10 @@ use oxide_compiler::module::CompiledModule;
|
||||
use oxide_compiler::opcode::{self, OpCode};
|
||||
|
||||
use crate::coercion;
|
||||
use crate::mem::{Epoch, P};
|
||||
use crate::object::JsObject;
|
||||
use crate::shape::{self, EMPTY_SHAPE_ID};
|
||||
use crate::value::JsValue;
|
||||
use oxide_types::mem::{Epoch, P};
|
||||
use oxide_types::object::JsObject;
|
||||
use oxide_types::shape::{self, EMPTY_SHAPE_ID};
|
||||
use oxide_types::value::JsValue;
|
||||
|
||||
pub struct CallFrame {
|
||||
pub return_addr: usize,
|
||||
|
||||
@@ -2,10 +2,9 @@
|
||||
|
||||
use std::sync::{Arc, Condvar, Mutex};
|
||||
|
||||
use oxide_vm::mem::P;
|
||||
use oxide_vm::vm::Vm;
|
||||
|
||||
use crate::kernel::OxideKernel;
|
||||
use crate::vm::Vm;
|
||||
use oxide_kernel::kernel::OxideKernel;
|
||||
use oxide_types::mem::P;
|
||||
|
||||
struct VmPoolInner {
|
||||
available: Vec<Vm>,
|
||||
@@ -29,7 +28,11 @@ pub struct VmGuard {
|
||||
}
|
||||
|
||||
impl VmPool {
|
||||
pub fn new(kernel: Arc<OxideKernel>, min_size: usize, max_size: Option<usize>) -> Arc<Self> {
|
||||
pub fn new(
|
||||
kernel: Arc<OxideKernel>,
|
||||
#[allow(dead_code)] min_size: usize,
|
||||
max_size: Option<usize>,
|
||||
) -> Arc<Self> {
|
||||
let pool = Arc::new(Self {
|
||||
kernel,
|
||||
inner: Mutex::new(VmPoolInner {
|
||||
@@ -140,7 +143,7 @@ impl Drop for VmGuard {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::kernel::KernelConfig;
|
||||
use oxide_kernel::kernel::KernelConfig;
|
||||
|
||||
fn test_kernel() -> Arc<OxideKernel> {
|
||||
Arc::new(OxideKernel::new(KernelConfig::minimal()))
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::time::Instant;
|
||||
|
||||
use oxide_vm::mem::{Epoch, PersistentHeap};
|
||||
use oxide_types::mem::{Epoch, PersistentHeap};
|
||||
|
||||
#[test]
|
||||
fn epoch_alloc_and_read() {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use oxide_compiler::compiler::Compiler;
|
||||
use oxide_parser::Allocator;
|
||||
use oxide_vm::value::JsValue;
|
||||
use oxide_types::value::JsValue;
|
||||
use oxide_vm::vm::Vm;
|
||||
|
||||
fn eval(source: &str) -> String {
|
||||
|
||||
Reference in New Issue
Block a user