2121
2222
2323if typing .TYPE_CHECKING :
24- from .SExp import SExp
24+ from .SExp import CastableType , SExp
2525
2626
2727MAX_SINGLE_BYTE = 0x7F
3030
3131T = typing .TypeVar ("T" )
3232
33+ ToSExp = typing .Callable [["CastableType" ], CLVMStorage ]
3334
3435OpCallable = typing .Callable [
35- ["OpStackType" , "ValStackType" , typing .BinaryIO , typing . Type ], None
36+ ["OpStackType" , "ValStackType" , typing .BinaryIO , ToSExp ], None
3637]
3738
38- ValStackType = typing .List ["SExp" ]
39+ ValStackType = typing .List [CLVMStorage ]
3940OpStackType = typing .List [OpCallable ]
4041
4142
@@ -100,7 +101,7 @@ def sexp_to_stream(sexp: SExp, f: typing.BinaryIO) -> None:
100101
101102
102103def _op_read_sexp (
103- op_stack : OpStackType , val_stack : ValStackType , f : typing .BinaryIO , to_sexp : typing . Callable [[ bytes ], SExp ] ,
104+ op_stack : OpStackType , val_stack : ValStackType , f : typing .BinaryIO , to_sexp : ToSExp ,
104105) -> None :
105106 blob = f .read (1 )
106107 if len (blob ) == 0 :
@@ -118,14 +119,14 @@ def _op_cons(
118119 op_stack : OpStackType ,
119120 val_stack : ValStackType ,
120121 f : typing .BinaryIO ,
121- to_sexp : typing . Callable [[ typing . Tuple [ SExp , SExp ]], SExp ] ,
122+ to_sexp : ToSExp ,
122123) -> None :
123124 right = val_stack .pop ()
124125 left = val_stack .pop ()
125126 val_stack .append (to_sexp ((left , right )))
126127
127128
128- def sexp_from_stream (f : typing .BinaryIO , to_sexp : typing . Callable [[ SExp ], T ] ) -> T :
129+ def sexp_from_stream (f : typing .BinaryIO , to_sexp : ToSExp ) -> CLVMStorage :
129130 op_stack : OpStackType = [_op_read_sexp ]
130131 val_stack : ValStackType = []
131132
@@ -188,8 +189,8 @@ def sexp_buffer_from_stream(f: typing.BinaryIO) -> bytes:
188189
189190
190191def _atom_from_stream (
191- f : typing .BinaryIO , b : int , to_sexp : typing . Callable [[ bytes ], T ]
192- ) -> T :
192+ f : typing .BinaryIO , b : int , to_sexp : ToSExp
193+ ) -> CLVMStorage :
193194 if b == 0x80 :
194195 return to_sexp (b"" )
195196 if b <= MAX_SINGLE_BYTE :
0 commit comments