solomon_gremlin/process/traversal/
bytecode.rs

1use crate::GValue;
2
3#[derive(Debug, PartialEq, Clone)]
4pub struct Bytecode {
5	source_instructions: Vec<Instruction>,
6	step_instructions: Vec<Instruction>,
7}
8
9impl Default for Bytecode {
10	fn default() -> Bytecode {
11		Bytecode {
12			source_instructions: vec![],
13			step_instructions: vec![],
14		}
15	}
16}
17impl Bytecode {
18	pub fn new() -> Bytecode {
19		Default::default()
20	}
21
22	pub fn add_source(&mut self, source_name: String, args: Vec<GValue>) {
23		self.source_instructions.push(Instruction::new(source_name, args));
24	}
25	pub fn add_step(&mut self, step_name: String, args: Vec<GValue>) {
26		self.step_instructions.push(Instruction::new(step_name, args));
27	}
28
29	pub fn steps(&self) -> &Vec<Instruction> {
30		&self.step_instructions
31	}
32
33	pub fn sources(&self) -> &Vec<Instruction> {
34		&self.source_instructions
35	}
36}
37
38lazy_static! {
39	pub static ref WRITE_OPERATORS: Vec<&'static str> =
40		vec!["addV", "property", "addE", "from", "to", "drop"];
41}
42
43#[derive(Debug, PartialEq, Clone)]
44pub struct Instruction {
45	operator: String,
46	args: Vec<GValue>,
47}
48
49impl Instruction {
50	pub fn new(operator: String, args: Vec<GValue>) -> Instruction {
51		Instruction {
52			operator,
53			args,
54		}
55	}
56
57	pub fn operator(&self) -> &String {
58		&self.operator
59	}
60
61	pub fn args(&self) -> &Vec<GValue> {
62		&self.args
63	}
64}