1515from typed_python import *
1616import textwrap
1717
18+
1819def indent (x , indentBy = " " ):
1920 return textwrap .indent (str (x ), indentBy )
2021
22+
2123def type_attr_ix (t , attr ):
2224 for i in range (len (t .element_types )):
2325 if t .element_types [i ][0 ] == attr :
2426 return i
2527 return None
2628
29+
2730def type_str (c ):
2831 if c .matches .Function :
2932 return "func((%s)->%s%s)" % (
@@ -48,6 +51,7 @@ def type_str(c):
4851
4952 assert False , type (c )
5053
54+
5155def raising (e ):
5256 raise e
5357
@@ -78,6 +82,7 @@ def const_truth_value(c):
7882 return c .val != 0
7983 return False
8084
85+
8186def const_str (c ):
8287 if c .matches .Float :
8388 if c .bits == 64 :
@@ -163,6 +168,7 @@ def const_str(c):
163168 can_throw = bool
164169 )
165170
171+
166172def filterCallTargetArgs (args ):
167173 """Given a list of native expressions or typed expressions, filter them down,
168174 dropping 'empty' arguments, as per our calling convention."""
@@ -190,6 +196,7 @@ def filterCallTargetArgs(args):
190196 call = lambda self , * args : Expression .Call (target = self , args = filterCallTargetArgs (args ))
191197 )
192198
199+
193200def teardown_str (self ):
194201 if self .matches .Always :
195202 return str (self .expr )
@@ -203,6 +210,7 @@ def teardown_str(self):
203210 __str__ = teardown_str
204211 )
205212
213+
206214def expr_concatenate (self , other ):
207215 if self .matches .Constant :
208216 return other
@@ -326,6 +334,7 @@ def expr_str(self):
326334
327335 assert False
328336
337+
329338def expr_is_simple (expr ):
330339 if expr .matches .StackSlot :
331340 return True
@@ -440,35 +449,43 @@ def ensureExpr(x):
440449trueExpr = Expression .Constant (val = Constant .Int (bits = 1 , val = 1 , signed = False ))
441450falseExpr = Expression .Constant (val = Constant .Int (bits = 1 , val = 0 , signed = False ))
442451
452+
443453def const_float_expr (f ):
444454 return Expression .Constant (
445455 val = Constant .Float (bits = 64 , val = f )
446456 )
447457
458+
448459def const_int_expr (i ):
449460 return Expression .Constant (
450461 val = Constant .Int (bits = 64 , val = i , signed = True )
451462 )
452463
464+
453465def const_int32_expr (i ):
454466 return Expression .Constant (
455467 val = Constant .Int (bits = 32 , val = i , signed = True )
456468 )
457469
470+
458471def const_uint8_expr (i ):
459472 return Expression .Constant (
460473 val = Constant .Int (bits = 8 , val = i , signed = False )
461474 )
462475
476+
463477def const_bool_expr (i ):
464478 return Expression .Constant (
465479 val = Constant .Int (bits = 1 , val = i , signed = False )
466480 )
467481
482+
468483def const_utf8_cstr (i ):
469484 return Expression .Constant (
470485 val = Constant .ByteArray (val = i .encode ('utf-8' ))
471486 )
487+
488+
472489def const_bytes_cstr (i ):
473490 return Expression .Constant (
474491 val = Constant .ByteArray (val = i )
@@ -495,5 +512,6 @@ def const_bytes_cstr(i):
495512Int64 = Type .Int (bits = 64 , signed = True )
496513Int32 = Type .Int (bits = 32 , signed = True )
497514
515+
498516def var (name ):
499517 return Expression .Variable (name = name )
0 commit comments