16
16
ValidationError ,
17
17
)
18
18
19
-
19
+ import collections . UserList as rstack
20
20
"""
21
21
This module simply implements for the return stack the exact same design used for the data stack.
22
22
As this stack must simply push_int or pop1_int any time a subroutine is accessed or left, only those two functions are provided.
23
23
For the same reason, the class RStack doesn't inherit from the abc StackAPI, as it would require to implement all the abstract methods defined.
24
24
"""
25
25
26
-
27
- def _busted_type (item_type : type , value : Union [int , bytes ]) -> ValidationError :
28
- return ValidationError (
29
- "Stack must always be bytes or int, "
30
- f"got { item_type !r} type, val { value !r} "
31
- )
32
-
33
26
class RStack ():
34
27
"""
35
28
VM Return Stack
@@ -39,10 +32,10 @@ class RStack():
39
32
40
33
def __init__ (self ) -> None :
41
34
values : List [int ]
42
- self .values = values
43
- self ._append = values .append
44
- self ._pop_typed = values .pop
45
- self .__len__ = values .__len__
35
+ self .values = rstack . data
36
+ self ._append = rstack . data .append
37
+ self ._pop_typed = rstack . data .pop
38
+ self .__len__ = rstack . data .__len__
46
39
47
40
def push_int (self ) -> int :
48
41
if len (self .values ) > 1023 :
@@ -66,5 +59,8 @@ def pop1_int(self) -> int:
66
59
elif item_type is bytes :
67
60
return big_endian_to_int (popped ) # type: ignore
68
61
else :
69
- raise _busted_type (item_type , popped )
62
+ raise ValidationError (
63
+ "Stack must always be bytes or int, "
64
+ f"got { item_type !r} type, val { value !r} "
65
+ )
70
66
0 commit comments