@@ -25,29 +25,21 @@ use super::inner_function::InnerFunction;
25
25
26
26
/// Filters a given list for elements that satisfy a predicate. A new
27
27
/// list is created, containing only those elements that satisfy the
28
- /// predicate. The predicate must be given as an InnerFunction.
28
+ /// predicate. The predicate must be given as an [` InnerFunction`] .
29
29
pub struct Filter {
30
30
pub f : InnerFunction ,
31
31
}
32
32
33
33
impl BasicSnippet for Filter {
34
34
fn inputs ( & self ) -> Vec < ( DataType , String ) > {
35
- let list_type = match & self . f {
36
- InnerFunction :: BasicSnippet ( basic_snippet) => {
37
- DataType :: List ( Box :: new ( basic_snippet. inputs ( ) [ 0 ] . 0 . clone ( ) ) )
38
- }
39
- _ => DataType :: VoidPointer ,
40
- } ;
35
+ let element_type = self . f . domain ( ) ;
36
+ let list_type = DataType :: List ( Box :: new ( element_type) ) ;
41
37
vec ! [ ( list_type, "*input_list" . to_string( ) ) ]
42
38
}
43
39
44
40
fn outputs ( & self ) -> Vec < ( DataType , String ) > {
45
- let list_type = match & self . f {
46
- InnerFunction :: BasicSnippet ( basic_snippet) => {
47
- DataType :: List ( Box :: new ( basic_snippet. inputs ( ) [ 0 ] . 0 . clone ( ) ) )
48
- }
49
- _ => DataType :: VoidPointer ,
50
- } ;
41
+ let element_type = self . f . range ( ) ;
42
+ let list_type = DataType :: List ( Box :: new ( element_type) ) ;
51
43
vec ! [ ( list_type, "*output_list" . to_string( ) ) ]
52
44
}
53
45
@@ -90,7 +82,7 @@ impl BasicSnippet for Filter {
90
82
// If function was supplied as raw instructions, we need to append the inner function to the function
91
83
// body. Otherwise, `library` handles the imports.
92
84
let maybe_inner_function_body_raw = match & self . f {
93
- InnerFunction :: RawCode ( rc) => rc. function . iter ( ) . map ( |x| x . to_string ( ) ) . join ( "\n " ) ,
85
+ InnerFunction :: RawCode ( rc) => rc. function . iter ( ) . join ( "\n " ) ,
94
86
InnerFunction :: DeprecatedSnippet ( _) => String :: default ( ) ,
95
87
InnerFunction :: NoFunctionBody ( _) => todo ! ( ) ,
96
88
InnerFunction :: BasicSnippet ( _) => String :: default ( ) ,
@@ -114,7 +106,7 @@ impl BasicSnippet for Filter {
114
106
call { main_loop} // _ *input_list *output_list input_len input_len output_len
115
107
116
108
swap 2 pop 2 // _ *input_list *output_list output_len
117
- call { set_length} // _input_list *output_list
109
+ call { set_length} // _ *input_list *output_list
118
110
119
111
swap 1 // _ *output_list *input_list
120
112
pop 1 // _ *output_list
@@ -123,7 +115,7 @@ impl BasicSnippet for Filter {
123
115
// INVARIANT: _ *input_list *output_list input_len input_index output_index
124
116
{ main_loop} :
125
117
// test return condition
126
- dup 1 // _ *input_list *output_list input_len input_index output_index input_index
118
+ dup 1 // _ *input_list *output_list input_len input_index output_index input_index
127
119
dup 3 eq // _ *input_list *output_list input_len input_index output_index input_index==input_len
128
120
129
121
skiz return
0 commit comments