@@ -12,7 +12,7 @@ currently only work with *one* input element in inner function. \
12
12
Use a tuple data type to circumvent this.";
13
13
14
14
/// A data structure for describing an inner function predicate to filter with,
15
- /// or to map with.
15
+ /// or a function to map with.
16
16
#[ derive( Debug , Clone , Eq , PartialEq , Hash ) ]
17
17
pub struct RawCode {
18
18
pub function : Vec < LabelledInstruction > ,
@@ -26,9 +26,13 @@ impl RawCode {
26
26
input_type : DataType ,
27
27
output_type : DataType ,
28
28
) -> Self {
29
+ let is_label = |x : & _ | matches ! ( x, LabelledInstruction :: Label ( _) ) ;
30
+ let is_instruction = |x : & _ | matches ! ( x, LabelledInstruction :: Instruction ( _) ) ;
31
+ let labels_and_instructions = function. iter ( ) . filter ( |i| is_label ( i) || is_instruction ( i) ) ;
32
+
29
33
// Verify that 1st line is a label
30
34
assert ! (
31
- function . len ( ) >= 2 ,
35
+ labels_and_instructions . count ( ) >= 2 ,
32
36
"Inner function must have at least two lines: a label and a return or recurse"
33
37
) ;
34
38
assert ! (
@@ -41,8 +45,9 @@ impl RawCode {
41
45
function. last( ) . unwrap( ) ,
42
46
LabelledInstruction :: Instruction ( AnInstruction :: Return )
43
47
| LabelledInstruction :: Instruction ( AnInstruction :: Recurse )
48
+ | LabelledInstruction :: Instruction ( AnInstruction :: RecurseOrReturn )
44
49
) ,
45
- "Last line of inner function must be either return or recurse . Got: {}" ,
50
+ "Last line of inner function must be either return, recurse, or recurse_or_return . Got: {}" ,
46
51
function. last( ) . unwrap( )
47
52
) ;
48
53
@@ -268,4 +273,28 @@ mod tests {
268
273
let inlined_code = raw_code. inlined_body ( ) . unwrap ( ) ;
269
274
assert_eq ! ( triton_asm!( ) , inlined_code) ;
270
275
}
276
+
277
+ #[ test]
278
+ fn allow_raw_code_with_recurse_or_return_instruction ( ) {
279
+ let raw_code = triton_asm ! (
280
+ please_help_me:
281
+ hint im_falling = stack[ 0 ]
282
+ hint in_love_with_you = stack[ 1 ]
283
+
284
+ call close_the_door_to_temptation
285
+
286
+ return
287
+
288
+ close_the_door_to_temptation:
289
+ hint turn_away_from_me_darling = stack[ 5 ]
290
+ break
291
+ merkle_step_mem
292
+ recurse_or_return
293
+ ) ;
294
+ let raw_code = RawCode :: new ( raw_code, DataType :: VoidPointer , DataType :: VoidPointer ) ;
295
+ assert ! (
296
+ raw_code. inlined_body( ) . is_none( ) ,
297
+ "Disallow inling of code with `recurse_or_return` instruction"
298
+ ) ;
299
+ }
271
300
}
0 commit comments