rigz_vm/
scope.rs

1use crate::lifecycle::Lifecycle;
2use crate::Instruction;
3
4/**
5todo need to know whether scope is function, root, or expression for returns
6for functions, return value
7for root, this is a halt
8otherwise inner scope returns should cascade to function call or root
9*/
10
11#[derive(Clone, Debug, PartialEq, Eq)]
12pub struct Scope<'vm> {
13    pub instructions: Vec<Instruction<'vm>>,
14    pub lifecycle: Option<Lifecycle>,
15    pub named: &'vm str,
16    pub args: Vec<(&'vm str, bool)>,
17    pub set_self: Option<bool>,
18}
19
20impl Default for Scope<'_> {
21    fn default() -> Self {
22        Scope {
23            named: "main",
24            instructions: Default::default(),
25            lifecycle: None,
26            args: vec![],
27            set_self: None,
28        }
29    }
30}
31
32impl<'vm> Scope<'vm> {
33    #[inline]
34    pub fn new(named: &'vm str, args: Vec<(&'vm str, bool)>, set_self: Option<bool>) -> Self {
35        Scope {
36            named,
37            args,
38            set_self,
39            ..Default::default()
40        }
41    }
42
43    #[inline]
44    pub fn lifecycle(
45        named: &'vm str,
46        args: Vec<(&'vm str, bool)>,
47        lifecycle: Lifecycle,
48        set_self: Option<bool>,
49    ) -> Self {
50        Scope {
51            lifecycle: Some(lifecycle),
52            named,
53            args,
54            set_self,
55            ..Default::default()
56        }
57    }
58}