feat(vm/Origin): make call method async
This commit is contained in:
parent
9c0ad2fa15
commit
6c75da9cd2
77
Cargo.lock
generated
77
Cargo.lock
generated
|
@ -11,6 +11,17 @@ dependencies = [
|
|||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-trait"
|
||||
version = "0.1.57"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "76464446b8bc32758d7e88ee1a804d9914cd9b1cb264c029899680b0be29826f"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "atty"
|
||||
version = "0.2.14"
|
||||
|
@ -87,6 +98,15 @@ dependencies = [
|
|||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fastrand"
|
||||
version = "1.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499"
|
||||
dependencies = [
|
||||
"instant",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fogtix-bytecode"
|
||||
version = "0.0.0"
|
||||
|
@ -100,7 +120,9 @@ dependencies = [
|
|||
name = "fogtix-vm"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"fogtix-bytecode",
|
||||
"futures-lite",
|
||||
"once_cell",
|
||||
"proptest",
|
||||
"tracing",
|
||||
|
@ -112,10 +134,38 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"clap",
|
||||
"fogtix-vm",
|
||||
"futures-lite",
|
||||
"readfilez",
|
||||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-core"
|
||||
version = "0.3.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4e5aa3de05362c3fb88de6531e6296e85cde7739cccad4b9dfeeb7f6ebce56bf"
|
||||
|
||||
[[package]]
|
||||
name = "futures-io"
|
||||
version = "0.3.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bbf4d2a7a308fd4578637c0b17c7e1c7ba127b8f6ba00b29f717e9655d85eb68"
|
||||
|
||||
[[package]]
|
||||
name = "futures-lite"
|
||||
version = "1.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7694489acd39452c77daa48516b894c153f192c3578d5a839b62c58099fcbf48"
|
||||
dependencies = [
|
||||
"fastrand",
|
||||
"futures-core",
|
||||
"futures-io",
|
||||
"memchr",
|
||||
"parking",
|
||||
"pin-project-lite",
|
||||
"waker-fn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.12.3"
|
||||
|
@ -141,6 +191,15 @@ dependencies = [
|
|||
"hashbrown",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "instant"
|
||||
version = "0.1.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "int-enum"
|
||||
version = "0.4.0"
|
||||
|
@ -185,6 +244,12 @@ dependencies = [
|
|||
"cfg-if 1.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
||||
|
||||
[[package]]
|
||||
name = "memmap2"
|
||||
version = "0.5.7"
|
||||
|
@ -215,6 +280,12 @@ version = "6.3.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff"
|
||||
|
||||
[[package]]
|
||||
name = "parking"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72"
|
||||
|
||||
[[package]]
|
||||
name = "pin-project-lite"
|
||||
version = "0.2.9"
|
||||
|
@ -459,6 +530,12 @@ version = "0.1.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
|
||||
|
||||
[[package]]
|
||||
name = "waker-fn"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca"
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
|
|
|
@ -11,5 +11,7 @@ fogtix-vm.path = "../fogtix-vm"
|
|||
readfilez = "0.3"
|
||||
tracing-subscriber = "0.3"
|
||||
|
||||
[[bin]]
|
||||
name = "fogtix-vm"
|
||||
[dependencies.futures-lite]
|
||||
version = "1.12"
|
||||
default-features = false
|
||||
features = ["std"]
|
||||
|
|
|
@ -22,14 +22,16 @@ fn main() {
|
|||
.expect("unable to open/load main module"),
|
||||
);
|
||||
|
||||
fogtix_vm::Process {
|
||||
korigs: fogtix_vm::make_default_origins(),
|
||||
stack: Vec::new(),
|
||||
callstack: Vec::new(),
|
||||
instrp: fogtix_vm::InstrPtr {
|
||||
m: main_mod,
|
||||
pos: 0,
|
||||
},
|
||||
}
|
||||
.run(None);
|
||||
futures_lite::future::block_on(
|
||||
fogtix_vm::Process {
|
||||
korigs: fogtix_vm::make_default_origins(),
|
||||
stack: Vec::new(),
|
||||
callstack: Vec::new(),
|
||||
instrp: fogtix_vm::InstrPtr {
|
||||
m: main_mod,
|
||||
pos: 0,
|
||||
},
|
||||
}
|
||||
.run(None),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ license = "GPL-2+"
|
|||
publish = false
|
||||
|
||||
[dependencies]
|
||||
async-trait = "0.1"
|
||||
tracing = "0.1"
|
||||
|
||||
[dependencies.fogtix-bytecode]
|
||||
|
@ -15,6 +16,11 @@ features = ["std"]
|
|||
[dev-dependencies]
|
||||
once_cell = "1.15"
|
||||
|
||||
[dev-dependencies.futures-lite]
|
||||
version = "1.12"
|
||||
default-features = false
|
||||
features = ["std"]
|
||||
|
||||
[dev-dependencies.proptest]
|
||||
version = "1.0"
|
||||
default-features = false
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use async_trait::async_trait;
|
||||
use fogtix_bytecode::{Atom, Instr, Parse, Pointer, Value as BcValue};
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
||||
|
@ -41,8 +42,9 @@ impl InstrPtr {
|
|||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait Origin: Send + Sync + core::fmt::Debug {
|
||||
fn call(&self, p: &Pointer, a: &Atom, stack: &mut Vec<StackEntValue>) -> InstrPtr;
|
||||
async fn call(&self, p: &Pointer, a: &Atom, stack: &mut Vec<StackEntValue>) -> InstrPtr;
|
||||
}
|
||||
|
||||
pub type KnownOrigins = Arc<[RwLock<Option<Box<dyn Origin>>>; 0x10000]>;
|
||||
|
@ -94,7 +96,7 @@ impl Process {
|
|||
verify_jumptarget_explicit(previptr, jinstr, &self.instrp)
|
||||
}
|
||||
|
||||
pub fn run(&mut self, mut fuel: Option<&mut u64>) {
|
||||
pub async fn run(&mut self, mut fuel: Option<&mut u64>) {
|
||||
loop {
|
||||
use fogtix_bytecode::consts::MathBinOp;
|
||||
let previptr = self.instrp.pos;
|
||||
|
@ -145,7 +147,7 @@ impl Process {
|
|||
Ok(origin) => match origin.as_ref() {
|
||||
Some(origin) => {
|
||||
wp.set_origin(0);
|
||||
self.instrp = origin.call(&wp, &atom, &mut args);
|
||||
self.instrp = origin.call(&wp, &atom, &mut args).await;
|
||||
self.stack.extend(args);
|
||||
}
|
||||
None => {
|
||||
|
@ -415,7 +417,7 @@ mod tests {
|
|||
pos: 0,
|
||||
},
|
||||
};
|
||||
p.run(Some(&mut 1024));
|
||||
futures_lite::future::block_on(p.run(Some(&mut 1024)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue