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
use std::collections::HashMap;

use crate::types::{Args, Heap, Options};

pub type PackageCallback = fn(&Args, &mut Heap, &mut Heap, &String, &mut Options) -> ();
pub type RuntimeMethodRes = HashMap<&'static str, (&'static str, PackageCallback)>;

pub mod rt_module;
pub mod _root_syntax;

pub struct RuntimeValue {
  pub r#type: String,
  pub _inner: Heap,
  pub fn_ptr: RuntimeMethodRes,
}

impl RuntimeValue {
  pub fn new(r#type: &str, fn_ptr: RuntimeMethodRes) -> Self {
    Self {
      r#type: format!("{}", r#type),
      _inner: Heap::new(),
      fn_ptr,
    }
  }

  pub fn call_ptr(
    &mut self,
    caller: &str,
    v: &Vec<String>,
    a: &mut Heap,
    c: &String,
    o: &mut Options,
  ) -> Option<()> {
    let (_, f) = self.fn_ptr.get(caller)?;

    f(v, &mut self._inner, a, c, o);
    Some(())
  }
}