Skip to content

Commit 857546e

Browse files
committed
fix(RawCode): constructor
Account for new instruction `recurse_or_return` as well as hints and break points.
1 parent c0ab463 commit 857546e

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

tasm-lib/src/list/higher_order/inner_function.rs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ currently only work with *one* input element in inner function. \
1212
Use a tuple data type to circumvent this.";
1313

1414
/// A data structure for describing an inner function predicate to filter with,
15-
/// or to map with.
15+
/// or a function to map with.
1616
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
1717
pub struct RawCode {
1818
pub function: Vec<LabelledInstruction>,
@@ -26,9 +26,13 @@ impl RawCode {
2626
input_type: DataType,
2727
output_type: DataType,
2828
) -> 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+
2933
// Verify that 1st line is a label
3034
assert!(
31-
function.len() >= 2,
35+
labels_and_instructions.count() >= 2,
3236
"Inner function must have at least two lines: a label and a return or recurse"
3337
);
3438
assert!(
@@ -41,8 +45,9 @@ impl RawCode {
4145
function.last().unwrap(),
4246
LabelledInstruction::Instruction(AnInstruction::Return)
4347
| LabelledInstruction::Instruction(AnInstruction::Recurse)
48+
| LabelledInstruction::Instruction(AnInstruction::RecurseOrReturn)
4449
),
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: {}",
4651
function.last().unwrap()
4752
);
4853

@@ -268,4 +273,28 @@ mod tests {
268273
let inlined_code = raw_code.inlined_body().unwrap();
269274
assert_eq!(triton_asm!(), inlined_code);
270275
}
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+
}
271300
}

0 commit comments

Comments
 (0)