1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#![deny(missing_docs)]
//! `flowruntime` is a crate that defines a set of functions for a flow program to interact with the
//! host system, such as files, stdio etc.

use std::sync::{Arc, Mutex};

use flowrlib::lib_manifest::{ImplementationLocator::Native, LibraryManifest};
use flowrlib::manifest::MetaData;

use crate::runtime_client::RuntimeClient;

/// `runtime_client` is a trait for clients connectibe to the run-time must implement
pub mod runtime_client;
/// `args` is a module to interact with a programs arguments
mod args;
/// `file` is a module to interact with the file system
mod file;
/// `stdio` is a module to interact with standard IO
mod stdio;

/// Return a `LibraryManifest` for the run-time functions
pub fn get_manifest(client: Arc<Mutex<dyn RuntimeClient>>) -> LibraryManifest {
    let metadata = MetaData {
        name: "flowruntime".into(),
        version: "0.1.0".into(),
        description: "Runtime library provided by flowr binary".into(),
        author_name: "Andrew Mackenzie".into(),
        author_email: "andrew@mackenzie-serres.net".into(),

    };
    let mut manifest = LibraryManifest::new(metadata);

    manifest.locators.insert("lib://flowruntime/args/get/Get".to_string(),
                             Native(Arc::new(args::get::Get { client: client.clone() })));
    manifest.locators.insert("lib://flowruntime/file/file_write/FileWrite".to_string(),
                             Native(Arc::new(file::file_write::FileWrite { client: client.clone() })));
    manifest.locators.insert("lib://flowruntime/stdio/readline/Readline".to_string(),
                             Native(Arc::new(stdio::readline::Readline { client: client.clone() })));
    manifest.locators.insert("lib://flowruntime/stdio/stdin/Stdin".to_string(),
                             Native(Arc::new(stdio::stdin::Stdin { client: client.clone() })));
    manifest.locators.insert("lib://flowruntime/stdio/stdout/Stdout".to_string(),
                             Native(Arc::new(stdio::stdout::Stdout { client: client.clone() })));
    manifest.locators.insert("lib://flowruntime/stdio/stderr/Stderr".to_string(),
                             Native(Arc::new(stdio::stderr::Stderr { client: client.clone() })));

    manifest
}