~cloutier/principia

d20d21b02fff23b947ded066575b81520b14eb48 — Vincent Cloutier 5 months ago 6e99683
started moving to tokio
6 files changed, 166 insertions(+), 24 deletions(-)

M Cargo.lock
M cli/Cargo.toml
M cli/src/main.rs
M kernel/Cargo.toml
M kernel/src/builtins.rs
M kernel/src/lib.rs
M Cargo.lock => Cargo.lock +133 -20
@@ 148,6 148,12 @@ dependencies = [
]

[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"


@@ 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",


@@ 842,6 848,16 @@ dependencies = [
]

[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"


@@ 929,6 945,17 @@ dependencies = [
]

[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"


@@ 1067,12 1094,22 @@ 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"
source = "registry+https://github.com/rust-lang/crates.io-index"


@@ 1083,11 1120,24 @@ 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"
source = "registry+https://github.com/rust-lang/crates.io-index"


@@ 1100,6 1150,12 @@ 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"
source = "registry+https://github.com/rust-lang/crates.io-index"


@@ 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",


@@ 1593,6 1651,15 @@ dependencies = [
]

[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"


@@ 1611,6 1678,22 @@ dependencies = [
]

[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"


@@ 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",


@@ 1784,12 1867,31 @@ dependencies = [
]

[[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,12 1922,23 @@ 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"
source = "registry+https://github.com/rust-lang/crates.io-index"


@@ 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",
]

M cli/Cargo.toml => cli/Cargo.toml +1 -0
@@ 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"

M cli/src/main.rs => cli/src/main.rs +4 -2
@@ 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(_)) => {} ,

M kernel/Cargo.toml => kernel/Cargo.toml +1 -0
@@ 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"] }

M kernel/src/builtins.rs => kernel/src/builtins.rs +25 -1
@@ 47,7 47,7 @@ pub enum BuiltinResult {
    impure_res(Arc<ast::Node>, HashMap<String, ast::EnvNode>)
}

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())
        }
    },
];

M kernel/src/lib.rs => kernel/src/lib.rs +2 -1
@@ 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<std::string::String>, Receiver<std::string::String>) {
pub async fn start_kernel() -> (Sender<std::string::String>, Receiver<std::string::String>) {
    let (senderIn, receiverIn) = mpsc::channel::<std::string::String>();
    let (senderOut, receiverOut) = mpsc::channel::<std::string::String>();