@@ -344,14 +344,13 @@ class Argument(NamedValue):
344
344
def __str__ (self ):
345
345
return self .as_operand ()
346
346
347
- class Function ( Value ) :
347
+ class Function :
348
348
"""
349
349
A function containing SSA IR.
350
350
"""
351
351
352
352
def __init__ (self , typ , name , arguments ):
353
- super ().__init__ (typ )
354
- self .name = name
353
+ self .type , self .name = typ , name
355
354
self .names , self .arguments , self .basic_blocks = set (), [], []
356
355
self .set_arguments (arguments )
357
356
@@ -389,10 +388,6 @@ def predecessors_of(self, successor):
389
388
return [block for block in self .basic_blocks
390
389
if block .is_terminated () and successor in block .successors ()]
391
390
392
- def as_operand (self ):
393
- return "{} @{}" .format (types .TypePrinter ().name (self .type ),
394
- escape_name (self .name ))
395
-
396
391
def __str__ (self ):
397
392
printer = types .TypePrinter ()
398
393
lines = []
@@ -766,6 +761,30 @@ def __init__(self, op, operands, typ, name=""):
766
761
def opcode (self ):
767
762
return "builtin({})" .format (self .op )
768
763
764
+ class Closure (Instruction ):
765
+ """
766
+ A closure creation operation.
767
+
768
+ :ivar target_function: (:class:`Function`) function to invoke
769
+ """
770
+
771
+ """
772
+ :param func: (:class:`Function`) function
773
+ :param env: (:class:`Value`) outer environment
774
+ """
775
+ def __init__ (self , func , env , name = "" ):
776
+ assert isinstance (func , Function )
777
+ assert isinstance (env , Value )
778
+ assert is_environment (env .type )
779
+ super ().__init__ ([env ], func .type , name )
780
+ self .target_function = func
781
+
782
+ def opcode (self ):
783
+ return "closure({})" .format (self .target_function .name )
784
+
785
+ def get_environment (self ):
786
+ return self .operands [0 ]
787
+
769
788
class Call (Instruction ):
770
789
"""
771
790
A function call operation.
@@ -776,7 +795,6 @@ class Call(Instruction):
776
795
:param args: (list of :class:`Value`) function arguments
777
796
"""
778
797
def __init__ (self , func , args , name = "" ):
779
- print (func )
780
798
assert isinstance (func , Value )
781
799
for arg in args : assert isinstance (arg , Value )
782
800
super ().__init__ ([func ] + args , func .type .ret , name )
0 commit comments