@@ -802,6 +802,25 @@ def visit_Num(self, node):
802
802
def visit_Str (self , node ):
803
803
crep .set_rep (node , crep .cpp_value ('"{0}"' .format (node .s ), self ._gc .current_scope (), ctyp .terminal ("string" )))
804
804
805
+ def visit_Constant (self , node : ast .Constant ):
806
+ '''Visit Constnat node.
807
+
808
+ Note that this has to take the place of `visit_Str` and `visit_Num` as we roll
809
+ python versions forward. So those methods and this method must be kept in sync.
810
+
811
+ Args:
812
+ node (ast.Constant): The constant to visit
813
+ '''
814
+ value = node .value
815
+ if type (value ) is str :
816
+ crep .set_rep (node , crep .cpp_value (f'"{ value } "' , self ._gc .current_scope (), ctyp .terminal ("string" )))
817
+ elif type (value ) is int :
818
+ crep .set_rep (node , crep .cpp_value (value , self ._gc .current_scope (), ctyp .terminal ("int" )))
819
+ elif type (value ) is float :
820
+ crep .set_rep (node , crep .cpp_value (value , self ._gc .current_scope (), ctyp .terminal ("double" )))
821
+ else :
822
+ raise Exception (f"Unsupported constant type: { type (value )} " )
823
+
805
824
def code_fill_ttree (self , e_rep : crep .cpp_rep_base , e_name : crep .cpp_variable ,
806
825
scope_fill : Union [gc_scope , gc_scope_top_level ]) -> Union [gc_scope , gc_scope_top_level ]:
807
826
'''
@@ -1016,11 +1035,10 @@ def call_Where(self, node: ast.AST, args: List[ast.AST]):
1016
1035
new_sequence_var = w_val .copy_with_new_scope (self ._gc .current_scope ())
1017
1036
crep .set_rep (node , crep .cpp_sequence (new_sequence_var , seq .iterator_value (), self ._gc .current_scope ()))
1018
1037
1019
- def call_Range (self , node : ast .AST , args : List [ast .AST ]):
1038
+ def call_Range (self , node : ast .Call , args : List [ast .AST ]):
1020
1039
'Create a collection of numbers from lower_bound'
1021
1040
1022
- if len (args ) != 2 :
1023
- raise Exception ('blah blah' )
1041
+ assert len (args ) == 2 , 'Range(lower bound, upper bound) is the only allowed form'
1024
1042
lower_bound = args [0 ]
1025
1043
upper_bound = args [1 ]
1026
1044
0 commit comments