datex_core/runtime/
mod.rs

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
48
use std::{cell::RefCell, rc::Rc};

use crate::{utils::{logger::{LoggerContext, Logger}, crypto::Crypto, rust_crypto::RustCrypto}, datex_values::ValueResult};

mod stack;
mod execution;
pub mod memory;

use self::{execution::execute, memory::Memory};

const VERSION: &str = env!("CARGO_PKG_VERSION");


pub struct Runtime<'a> {
    pub version: String,
	pub ctx: &'a LoggerContext,
	pub crypto: &'a dyn Crypto,
	pub memory: Rc<RefCell<Memory>>
}

impl Runtime<'_> {
	
	pub fn new_with_crypto_and_logger<'a>(crypto: &'a dyn Crypto, ctx: &'a LoggerContext) -> Runtime<'a> {
		let logger = Logger::new_for_development(&ctx, "DATEX");
    	logger.success("initialized!");
		return Runtime { 
			version: VERSION.to_string(),
			crypto, 
			ctx, 
			memory: Rc::new(RefCell::new(Memory::new()))
		}
	}

	pub fn new() -> Runtime<'static> {
		return Runtime { 
			version: VERSION.to_string(), 
			crypto: &RustCrypto{},
			ctx: &LoggerContext { log_redirect: None},
			memory: Rc::new(RefCell::new(Memory::new()))
		}
	}

	pub fn execute(&self, dxb: &[u8]) -> ValueResult {
		execute(&self.ctx, dxb)
	}

}