From d20d21b02fff23b947ded066575b81520b14eb48 Mon Sep 17 00:00:00 2001 From: Vincent Cloutier Date: Sat, 24 Jun 2023 11:04:49 -0400 Subject: [PATCH] started moving to tokio --- Cargo.lock | 153 +++++++++++++++++++++++++++++++++++------ cli/Cargo.toml | 1 + cli/src/main.rs | 6 +- kernel/Cargo.toml | 1 + kernel/src/builtins.rs | 26 ++++++- kernel/src/lib.rs | 3 +- 6 files changed, 166 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4bd1ebe..9099005 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -147,6 +147,12 @@ dependencies = [ "iovec", ] +[[package]] +name = "bytes" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" + [[package]] name = "cc" version = "1.0.79" @@ -570,7 +576,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a5b34c246847f938a410a03c5458c7fee2274436675e76d8b903c08efc29c462" dependencies = [ "byteorder", - "bytes", + "bytes 0.4.12", "fnv", "futures", "http", @@ -627,7 +633,7 @@ version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6ccf5ede3a895d8856620237b2f02972c1bbc78d2965ad7fe8838d4a0ed41f0" dependencies = [ - "bytes", + "bytes 0.4.12", "fnv", "itoa 0.4.8", ] @@ -638,7 +644,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6741c859c1b2463a423a1dbce98d418e6c3c3fc720fb0d45528657320920292d" dependencies = [ - "bytes", + "bytes 0.4.12", "futures", "http", "tokio-buf", @@ -665,7 +671,7 @@ version = "0.12.36" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c843caf6296fc1f93444735205af9ed4e109a539005abb2564ae1d6fad34c52" dependencies = [ - "bytes", + "bytes 0.4.12", "futures", "futures-cpupool", "h2", @@ -678,7 +684,7 @@ dependencies = [ "net2", "rustc_version", "time", - "tokio", + "tokio 0.1.22", "tokio-buf", "tokio-executor", "tokio-io", @@ -695,7 +701,7 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3a800d6aa50af4b5850b2b0f659625ce9504df908e9733b635720483be26174f" dependencies = [ - "bytes", + "bytes 0.4.12", "futures", "hyper", "native-tls", @@ -841,6 +847,16 @@ dependencies = [ "scopeguard", ] +[[package]] +name = "lock_api" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" +dependencies = [ + "autocfg 1.1.0", + "scopeguard", +] + [[package]] name = "log" version = "0.4.19" @@ -928,6 +944,17 @@ dependencies = [ "winapi 0.2.8", ] +[[package]] +name = "mio" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" +dependencies = [ + "libc", + "wasi 0.11.0+wasi-snapshot-preview1", + "windows-sys 0.48.0", +] + [[package]] name = "miow" version = "0.2.2" @@ -1067,11 +1094,21 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f842b1982eb6c2fe34036a4fbfb06dd185a3f5c8edfaacdf7d1ea10b07de6252" dependencies = [ - "lock_api", - "parking_lot_core", + "lock_api 0.3.4", + "parking_lot_core 0.6.3", "rustc_version", ] +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api 0.4.10", + "parking_lot_core 0.9.8", +] + [[package]] name = "parking_lot_core" version = "0.6.3" @@ -1083,10 +1120,23 @@ dependencies = [ "libc", "redox_syscall 0.1.57", "rustc_version", - "smallvec", + "smallvec 0.6.14", "winapi 0.3.9", ] +[[package]] +name = "parking_lot_core" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "redox_syscall 0.3.5", + "smallvec 1.10.0", + "windows-targets", +] + [[package]] name = "percent-encoding" version = "1.0.1" @@ -1099,6 +1149,12 @@ version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" +[[package]] +name = "pin-project-lite" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" + [[package]] name = "pkg-config" version = "0.3.27" @@ -1115,6 +1171,7 @@ dependencies = [ "log", "principia-kernel", "rustyline", + "tokio 1.28.2", ] [[package]] @@ -1132,6 +1189,7 @@ dependencies = [ "rust-embed", "strsim 0.10.0", "tiny-keccak", + "tokio 1.28.2", "unicode-segmentation", "url 1.7.2", "whatlang", @@ -1351,7 +1409,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f88643aea3c1343c804950d7bf983bd2067f5ab59db6d613a08e05572f2714ab" dependencies = [ "base64", - "bytes", + "bytes 0.4.12", "cookie", "cookie_store", "encoding_rs", @@ -1368,7 +1426,7 @@ dependencies = [ "serde_json", "serde_urlencoded", "time", - "tokio", + "tokio 0.1.22", "tokio-executor", "tokio-io", "tokio-threadpool", @@ -1592,6 +1650,15 @@ dependencies = [ "digest", ] +[[package]] +name = "signal-hook-registry" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" +dependencies = [ + "libc", +] + [[package]] name = "slab" version = "0.4.8" @@ -1610,6 +1677,22 @@ dependencies = [ "maybe-uninit", ] +[[package]] +name = "smallvec" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" + +[[package]] +name = "socket2" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" +dependencies = [ + "libc", + "winapi 0.3.9", +] + [[package]] name = "static_assertions" version = "1.1.0" @@ -1622,7 +1705,7 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d24114bfcceb867ca7f71a0d3fe45d45619ec47a6fbfa98cb14e14250bfa5d6d" dependencies = [ - "bytes", + "bytes 0.4.12", ] [[package]] @@ -1770,9 +1853,9 @@ version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a09c0b5bb588872ab2f09afa13ee6e9dac11e10a0ec9e8e3ba39a5a5d530af6" dependencies = [ - "bytes", + "bytes 0.4.12", "futures", - "mio", + "mio 0.6.23", "num_cpus", "tokio-current-thread", "tokio-executor", @@ -1783,13 +1866,32 @@ dependencies = [ "tokio-timer", ] +[[package]] +name = "tokio" +version = "1.28.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94d7b1cfd2aa4011f2de74c2c4c63665e27a71006b0a192dcd2710272e73dfa2" +dependencies = [ + "autocfg 1.1.0", + "bytes 1.4.0", + "libc", + "mio 0.8.8", + "num_cpus", + "parking_lot 0.12.1", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", +] + [[package]] name = "tokio-buf" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8fb220f46c53859a4b7ec083e41dec9778ff0b1851c0942b211edb89e0ccdc46" dependencies = [ - "bytes", + "bytes 0.4.12", "either", "futures", ] @@ -1820,11 +1922,22 @@ version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57fc868aae093479e3131e3d165c93b1c7474109d13c90ec0dda2a1bbfff0674" dependencies = [ - "bytes", + "bytes 0.4.12", "futures", "log", ] +[[package]] +name = "tokio-macros" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.18", +] + [[package]] name = "tokio-reactor" version = "0.1.12" @@ -1835,9 +1948,9 @@ dependencies = [ "futures", "lazy_static", "log", - "mio", + "mio 0.6.23", "num_cpus", - "parking_lot", + "parking_lot 0.9.0", "slab", "tokio-executor", "tokio-io", @@ -1860,10 +1973,10 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98df18ed66e3b72e742f185882a9e201892407957e45fbff8da17ae7a7c51f72" dependencies = [ - "bytes", + "bytes 0.4.12", "futures", "iovec", - "mio", + "mio 0.6.23", "tokio-io", "tokio-reactor", ] diff --git a/cli/Cargo.toml b/cli/Cargo.toml index ee12750..1d00c87 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -12,6 +12,7 @@ clap = "2.33.0" log = { version = "0.4", features = ["max_level_trace", "release_max_level_warn"] } env_logger = "0.6.1" directories = "2.0" +tokio = { version = "1", features = ["full"] } [[bin]] name = "principia" diff --git a/cli/src/main.rs b/cli/src/main.rs index 53110b7..7785c07 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -10,13 +10,15 @@ extern crate clap; extern crate log; extern crate env_logger; extern crate directories; +extern crate tokio; use rustyline::error::ReadlineError; use rustyline::Editor; use directories::BaseDirs; -fn main() { +#[tokio::main] +async fn main() { env_logger::init(); let matches = clap_app!(myapp => (version: "0.1") @@ -35,7 +37,7 @@ fn main() { ).get_matches(); let mut content = String::new(); - let (kernelIn, kernelOut) = kernel::start_kernel(); + let (kernelIn, kernelOut) = kernel::start_kernel().await; match matches.subcommand() { ("kernel", Some(_)) => {} , diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index f3e5d5d..c0d3400 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -22,3 +22,4 @@ nom = "6.0.0-alpha1" tiny-keccak = { version = "2.0.1", features = ["keccak"] } directories = "2.0" strsim = "0.10.0" +tokio = { version = "1", features = ["full"] } diff --git a/kernel/src/builtins.rs b/kernel/src/builtins.rs index cd79f3a..a6c5454 100644 --- a/kernel/src/builtins.rs +++ b/kernel/src/builtins.rs @@ -47,7 +47,7 @@ pub enum BuiltinResult { impure_res(Arc, HashMap) } -pub const BUILTINS: [Builtin; 62] = [ +pub const BUILTINS: [Builtin; 63] = [ Builtin { should_evaluate: &|ast, _| ast.head() == "CompoundExpression" && ast.children.len() > 0, is_pure: true, @@ -1542,4 +1542,28 @@ pub const BUILTINS: [Builtin; 62] = [ BuiltinResult::pure_res(Arc::new(new_node)) } }, + Builtin { + should_evaluate: &|ast, _| ast.head() == "SocketOpen" + && ast.children.len() <= 2, + is_pure: false, + reevaluate_output: false, + func: &|ast, env| { + use std::{ + io::{prelude::*, BufReader}, + net::{TcpListener, TcpStream}, + }; + + let listener = TcpListener::bind("127.0.0.1:7878").unwrap(); + for stream in listener.incoming() { + let stream = stream.unwrap(); + + break; + } + + + let new_node = ast::Node::new(ast::Item::Symbol("True".to_owned())); + + BuiltinResult::impure_res(Arc::new(new_node), env.clone()) + } + }, ]; diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index f077c15..9d3a1e0 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -21,6 +21,7 @@ extern crate rust_embed; extern crate log; extern crate nom; extern crate strsim; +extern crate tokio; use directories::BaseDirs; @@ -30,7 +31,7 @@ mod ast; mod wikidata; mod builtins; -pub fn start_kernel() -> (Sender, Receiver) { +pub async fn start_kernel() -> (Sender, Receiver) { let (senderIn, receiverIn) = mpsc::channel::(); let (senderOut, receiverOut) = mpsc::channel::(); -- 2.45.2