datex_core/runtime/
mod.rs1use std::{cell::RefCell, rc::Rc};
2
3use crate::{utils::{logger::{LoggerContext, Logger}, crypto::Crypto, rust_crypto::RustCrypto}, datex_values::ValueResult};
4
5mod stack;
6mod execution;
7pub mod memory;
8
9use self::{execution::execute, memory::Memory};
10
11const VERSION: &str = env!("CARGO_PKG_VERSION");
12
13
14pub struct Runtime<'a> {
15 pub version: String,
16 pub ctx: &'a LoggerContext,
17 pub crypto: &'a dyn Crypto,
18 pub memory: Rc<RefCell<Memory>>
19}
20
21impl Runtime<'_> {
22
23 pub fn new_with_crypto_and_logger<'a>(crypto: &'a dyn Crypto, ctx: &'a LoggerContext) -> Runtime<'a> {
24 let logger = Logger::new_for_development(&ctx, "DATEX");
25 logger.success("initialized!");
26 return Runtime {
27 version: VERSION.to_string(),
28 crypto,
29 ctx,
30 memory: Rc::new(RefCell::new(Memory::new()))
31 }
32 }
33
34 pub fn new() -> Runtime<'static> {
35 return Runtime {
36 version: VERSION.to_string(),
37 crypto: &RustCrypto{},
38 ctx: &LoggerContext { log_redirect: None},
39 memory: Rc::new(RefCell::new(Memory::new()))
40 }
41 }
42
43 pub fn execute(&self, dxb: &[u8]) -> ValueResult {
44 execute(&self.ctx, dxb)
45 }
46
47}
48