stack_assembly/effect.rs
1/// # An event triggered by scripts, to signal a specific condition
2///
3/// Evaluating an operator can trigger an effect. Active effects are stored in
4/// in [`Eval`]'s [`effect`] field. Please refer to the documentation of that
5/// field, for more information on effects and how to handle them.
6///
7/// [`Eval`]: crate::Eval
8/// [`effect`]: struct.Eval.html#structfield.effect
9#[derive(Debug, Eq, PartialEq)]
10pub enum Effect {
11 /// # An assertion failed
12 ///
13 /// Can trigger when evaluating `assert`, if its input is zero.
14 AssertionFailed,
15
16 /// # Tried to divide by zero
17 ///
18 /// Can trigger when evaluating the `/` operator, if its second input is
19 /// `0`.
20 DivisionByZero,
21
22 /// # Division resulted in integer overflow
23 ///
24 /// Can only trigger when evaluating the `/` operator, if its first input is
25 /// the lowest signed (two's complement) 32-bit integer, and its second
26 /// input is `-1`.
27 ///
28 /// All other arithmetic operators wrap on overflow and don't trigger this
29 /// effect.
30 IntegerOverflow,
31
32 /// # A memory address is out of bounds
33 ///
34 /// Can trigger when evaluating the `read` or `write` operators, if their
35 /// _address_ input (when interpreted as an unsigned 32-bit integer) does
36 /// not refer to an address that is within the bounds of the memory.
37 InvalidAddress,
38
39 /// # Evaluated a reference that is not paired with a matching label
40 ///
41 /// Can trigger when evaluating a reference, if that reference does not
42 /// refer to a label.
43 InvalidReference,
44
45 /// # An index that supposedly refers to a value on the stack, doesn't
46 ///
47 /// Can trigger when evaluating the `copy` or `drop` operators, if their
48 /// _index_ input is too large to refer to a value on the stack.
49 InvalidStackIndex,
50
51 /// # Ran out of operators to evaluate
52 ///
53 /// Triggers when evaluation reaches the end of the script, where no more
54 /// operators are available. This signals the regular end of the evaluation.
55 OutOfOperators,
56
57 /// # Tried popping a value from an empty stack
58 ///
59 /// Can trigger when evaluating any operator that has more inputs than the
60 /// number of values currently on the stack.
61 StackUnderflow,
62
63 /// # Evaluated an identifier that the language does not recognize
64 ///
65 /// Can trigger when evaluating an identifier, if that identifier does not
66 /// refer to a known operation.
67 UnknownIdentifier,
68
69 /// # The evaluating script yields control to the host
70 ///
71 /// Triggers when evaluating the `yield` operator.
72 Yield,
73}