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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// use garnish_lang_runtime::*;
// fn execute_all_instructions(runtime: &mut GarnishLangRuntime<SimpleRuntimeData>) {
// loop {
// match runtime.execute_current_instruction::<EmptyContext>(None) {
// Err(e) => {
// println!("{:?}", e);
// break;
// }
// Ok(data) => match data.get_state() {
// GarnishLangRuntimeState::Running => (),
// GarnishLangRuntimeState::End => break,
// },
// }
// }
// }
// #[test]
// fn adding_numbers_with_sub_expression() {
// let mut runtime = GarnishLangRuntime::simple();
// runtime.add_data(ExpressionData::integer(100)).unwrap();
// runtime.add_data(ExpressionData::integer(200)).unwrap();
// runtime.add_data(ExpressionData::integer(300)).unwrap();
// runtime.add_data(ExpressionData::expression(0)).unwrap();
// runtime.end_constant_data().unwrap();
// runtime.add_input_reference(2).unwrap();
// runtime.add_instruction(Instruction::Put, Some(1)).unwrap();
// runtime.add_instruction(Instruction::Put, Some(2)).unwrap();
// runtime.add_instruction(Instruction::PerformAddition, None).unwrap();
// runtime.add_instruction(Instruction::EndExpression, None).unwrap();
// runtime.add_instruction(Instruction::Put, Some(3)).unwrap();
// runtime.add_instruction(Instruction::Put, Some(4)).unwrap();
// runtime.add_instruction(Instruction::EmptyApply, None).unwrap();
// runtime.add_instruction(Instruction::PerformAddition, None).unwrap();
// runtime.add_instruction(Instruction::EndExpression, None).unwrap();
// runtime.add_expression(1).unwrap();
// runtime.set_instruction_cursor(5).unwrap();
// execute_all_instructions(&mut runtime);
// assert_eq!(
// runtime
// .get_data_pool()
// .get_integer(runtime.get_data_pool().get_result().unwrap())
// .unwrap(),
// 600
// )
// }
// #[test]
// fn value_before_jump() {
// let mut runtime = GarnishLangRuntime::simple();
// runtime.add_data(ExpressionData::integer(100)).unwrap();
// runtime.add_data(ExpressionData::integer(200)).unwrap();
// runtime.add_data(ExpressionData::integer(300)).unwrap();
// runtime.end_constant_data().unwrap();
// runtime.add_instruction(Instruction::Put, Some(1)).unwrap(); // 1
// runtime.add_instruction(Instruction::JumpTo, Some(0)).unwrap();
// // 3
// runtime.add_instruction(Instruction::Put, Some(1)).unwrap();
// runtime.add_instruction(Instruction::Put, Some(3)).unwrap();
// runtime.add_instruction(Instruction::Put, Some(3)).unwrap();
// runtime.add_instruction(Instruction::EqualityComparison, None).unwrap();
// runtime.add_instruction(Instruction::JumpIfTrue, Some(1)).unwrap();
// // 8
// runtime.add_instruction(Instruction::PerformAddition, None).unwrap();
// runtime.add_instruction(Instruction::EndExpression, None).unwrap();
// runtime.add_expression(8).unwrap();
// runtime.add_expression(1).unwrap();
// runtime.set_instruction_cursor(3).unwrap();
// execute_all_instructions(&mut runtime);
// assert_eq!(
// runtime
// .get_data_pool()
// .get_integer(runtime.get_data_pool().get_result().unwrap())
// .unwrap(),
// 200
// );
// }
// #[test]
// fn pair_with_pair() {
// let mut runtime = GarnishLangRuntime::simple();
// runtime.add_data(ExpressionData::integer(100)).unwrap();
// runtime.add_data(ExpressionData::integer(200)).unwrap();
// runtime.add_data(ExpressionData::integer(300)).unwrap();
// runtime.end_constant_data().unwrap();
// // 1
// runtime.add_instruction(Instruction::Put, Some(2)).unwrap();
// runtime.add_instruction(Instruction::Put, Some(3)).unwrap();
// runtime.add_instruction(Instruction::MakePair, None).unwrap();
// runtime.add_instruction(Instruction::Put, Some(1)).unwrap();
// runtime.add_instruction(Instruction::MakePair, None).unwrap();
// runtime.add_instruction(Instruction::EndExpression, None).unwrap();
// runtime.set_instruction_cursor(1).unwrap();
// execute_all_instructions(&mut runtime);
// let pool = runtime.get_data_pool();
// let (first_left, first_right) = pool.get_pair(pool.get_result().unwrap()).unwrap();
// let (second_left, second_right) = pool.get_pair(first_left).unwrap();
// assert_eq!(pool.get_integer(first_right).unwrap(), 100.into());
// assert_eq!(pool.get_integer(second_left).unwrap(), 200);
// assert_eq!(pool.get_integer(second_right).unwrap(), 300);
// }
// #[test]
// fn add_5_loop() {
// // 5 ~> {
// // $ + 5 @ get number and add 5 to make next element of new list
// // ? == 25 ?> ? |> ^~ ?
// // }
// let mut runtime = GarnishLangRuntime::simple();
// runtime.add_data(ExpressionData::integer(5)).unwrap();
// runtime.add_data(ExpressionData::integer(25)).unwrap();
// runtime.add_data(ExpressionData::expression(0)).unwrap();
// runtime.end_constant_data().unwrap();
// // 1 - subexpression
// runtime.add_instruction(Instruction::PutInput, None).unwrap();
// runtime.add_instruction(Instruction::Put, Some(1)).unwrap();
// runtime.add_instruction(Instruction::PerformAddition, None).unwrap();
// runtime.add_instruction(Instruction::PushResult, None).unwrap();
// // 5
// runtime.add_instruction(Instruction::PutResult, None).unwrap();
// runtime.add_instruction(Instruction::Put, Some(2)).unwrap();
// runtime.add_instruction(Instruction::EqualityComparison, None).unwrap();
// runtime.add_instruction(Instruction::JumpIfFalse, Some(2)).unwrap();
// runtime.add_instruction(Instruction::PutResult, None).unwrap();
// runtime.add_instruction(Instruction::JumpTo, Some(1)).unwrap();
// // 11
// runtime.add_instruction(Instruction::PutResult, None).unwrap();
// runtime.add_instruction(Instruction::Reapply, Some(0)).unwrap();
// // 13
// runtime.add_instruction(Instruction::EndExpression, None).unwrap();
// // 14 - main
// runtime.add_instruction(Instruction::Put, Some(3)).unwrap();
// runtime.add_instruction(Instruction::Put, Some(1)).unwrap();
// runtime.add_instruction(Instruction::Apply, None).unwrap();
// runtime.add_instruction(Instruction::EndExpression, None).unwrap();
// runtime.add_expression(1).unwrap();
// runtime.add_expression(13).unwrap();
// runtime.add_expression(11).unwrap();
// runtime.set_instruction_cursor(14).unwrap();
// execute_all_instructions(&mut runtime);
// assert_eq!(
// runtime
// .get_data_pool()
// .get_integer(runtime.get_data_pool().get_result().unwrap())
// .unwrap(),
// 25
// );
// }