Skip to content

Commit ec4406b

Browse files
authored
Merge pull request #18 from Kodowa/feature/runtime-block-removal
Add support for block removal at the runtime level
2 parents b5812df + 7569db7 commit ec4406b

File tree

2 files changed

+35
-23
lines changed

2 files changed

+35
-23
lines changed

examples/db-explorer.eve

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Add tag completions to queries with no existing filters.
7878
~~~ eve
7979
search
8080
query = [#db-explorer/query]
81-
// not(string/contains[text: query.value substring: " "]) // @TODO: This filter goes back on once dynamic completion is ready
81+
not(string/contains[text: query.value substring: " "])
8282
[tag]
8383
bind
8484
query.completion += [text: "#{{tag}}" value: tag]
@@ -89,7 +89,7 @@ Add attribute completions to queries with no existing filters.
8989
~~~ eve
9090
search
9191
query = [#db-explorer/query]
92-
// not(string/contains[text: query.value substring: " "]) // @TODO: This filter goes back on once dynamic completion is ready
92+
not(string/contains[text: query.value substring: " "])
9393
lookup[attribute]
9494
bind
9595
query.completion += [text: attribute value: attribute]
@@ -137,18 +137,17 @@ end
137137

138138
Find records that match the current completer pattern.
139139
When the completion pattern has at least one attribute, create a completer block.
140-
@TODO: Gotta implement block removal as a result of CodeTransaction's or this'll panic on changes.
141140
~~~ eve
142-
// search
143-
// [#db-explorer/query completion-pattern]
144-
// completion-pattern.attribute
145-
// bind
146-
// output-var = [#eve/compiler/variable name: "completion" completion-pattern]
147-
// record-var = [#eve/compiler/variable name: "record" completion-pattern]
148-
// [#eve/compiler/block #db-explorer/completer type: "bind" | record-var constraint:
149-
// [#eve/compiler/output entity: output-var attribute: "tag" value: "db-explorer/completion-record"]
150-
// [#eve/compiler/output entity: output-var attribute: "record" value: record-var]]
151-
// end
141+
search
142+
[#db-explorer/query completion-pattern]
143+
completion-pattern.attribute
144+
bind
145+
output-var = [#eve/compiler/variable name: "completion" completion-pattern]
146+
record-var = [#eve/compiler/variable name: "record" completion-pattern]
147+
[#eve/compiler/block #db-explorer/completer type: "bind" | record-var constraint:
148+
[#eve/compiler/output entity: output-var attribute: "tag" value: "db-explorer/completion-record"]
149+
[#eve/compiler/output entity: output-var attribute: "record" value: record-var]]
150+
end
152151
~~~
153152

154153
Fully formed AVs translate into eAV scans.

src/ops.rs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ impl Frame {
837837
// Instruction
838838
//-------------------------------------------------------------------------
839839

840-
#[derive(Debug, Clone)]
840+
#[derive(Debug, Clone, PartialEq)]
841841
pub enum Instruction {
842842
StartBlock { block: usize },
843843
GetIterator {iterator: usize, bail: i32, constraint: usize},
@@ -2847,8 +2847,21 @@ impl Program {
28472847
}
28482848

28492849
pub fn unregister_block(&mut self, name:String) {
2850-
println!("Unregister: {}", name);
2851-
unimplemented!();
2850+
if let Some(block_ix) = self.block_info.block_names.remove(&name) {
2851+
let block = self.block_info.blocks.remove(block_ix);
2852+
for (pipe_ix, pipe) in block.pipes.iter().enumerate() {
2853+
for shape in block.shapes[pipe_ix].iter() {
2854+
match shape {
2855+
&PipeShape::Scan(e, a, v) => {
2856+
self.block_info.pipe_lookup.get_mut(&(e, a, v)).unwrap().remove_item(pipe);
2857+
},
2858+
&PipeShape::Intermediate(id) => {
2859+
self.block_info.intermediate_pipe_lookup.get_mut(&id).unwrap().remove_item(pipe);
2860+
}
2861+
}
2862+
}
2863+
}
2864+
}
28522865
}
28532866

28542867
pub fn insert_block(&mut self, name:&str, code:&str) {
@@ -3119,13 +3132,6 @@ impl CodeTransaction {
31193132
let ref mut frame = self.frame;
31203133
let ref mut iter_pool = self.iter_pool;
31213134

3122-
for add in to_add {
3123-
frame.reset();
3124-
frame.input = Some(Change { e:0,a:0,v:0,n: 0, transaction:0, round:0, count:1 });
3125-
program.register_block(add);
3126-
interpret(&mut program.state, &program.block_info, iter_pool, frame, &program.block_info.blocks.last().unwrap().pipes[0]);
3127-
}
3128-
31293135
for name in to_remove {
31303136
{
31313137
let block_ix = match program.block_info.block_names.get(&name) {
@@ -3141,6 +3147,13 @@ impl CodeTransaction {
31413147
program.unregister_block(name);
31423148
}
31433149

3150+
for add in to_add {
3151+
frame.reset();
3152+
frame.input = Some(Change { e:0,a:0,v:0,n: 0, transaction:0, round:0, count:1 });
3153+
program.register_block(add);
3154+
interpret(&mut program.state, &program.block_info, iter_pool, frame, &program.block_info.blocks.last().unwrap().pipes[0]);
3155+
}
3156+
31443157
let mut max_round = 0;
31453158
intermediate_flow(frame, &mut program.state, &program.block_info, iter_pool, 0, &mut max_round);
31463159

0 commit comments

Comments
 (0)