@@ -25,11 +25,25 @@ class StringAdd(ConcreteTemplate):
2525 key = "+"
2626 cases = [signature (string_type , string_type , string_type )]
2727
28+ @infer
29+ class StringOpEq (AbstractTemplate ):
30+ key = '=='
31+ def generic (self , args , kws ):
32+ assert not kws
33+ (arg1 , arg2 ) = args
34+ if isinstance (arg1 , StringType ) and isinstance (arg2 , StringType ):
35+ return signature (types .boolean , arg1 , arg2 )
36+
37+ @infer
38+ class StringOpNotEq (StringOpEq ):
39+ key = '!='
40+
2841import hstr_ext
2942ll .add_symbol ('init_string' , hstr_ext .init_string )
3043ll .add_symbol ('init_string_const' , hstr_ext .init_string_const )
3144ll .add_symbol ('get_c_str' , hstr_ext .get_c_str )
3245ll .add_symbol ('str_concat' , hstr_ext .str_concat )
46+ ll .add_symbol ('str_equal' , hstr_ext .str_equal )
3347
3448@unbox (StringType )
3549def unbox_string (typ , obj , c ):
@@ -71,3 +85,17 @@ def impl_string_concat(context, builder, sig, args):
7185 [lir .IntType (8 ).as_pointer (), lir .IntType (8 ).as_pointer ()])
7286 fn = builder .module .get_or_insert_function (fnty , name = "str_concat" )
7387 return builder .call (fn , args )
88+
89+ @lower_builtin ('==' , string_type , string_type )
90+ def string_eq_impl (context , builder , sig , args ):
91+ fnty = lir .FunctionType (lir .IntType (1 ),
92+ [lir .IntType (8 ).as_pointer (), lir .IntType (8 ).as_pointer ()])
93+ fn = builder .module .get_or_insert_function (fnty , name = "str_equal" )
94+ return builder .call (fn , args )
95+
96+ @lower_builtin ('!=' , string_type , string_type )
97+ def string_neq_impl (context , builder , sig , args ):
98+ fnty = lir .FunctionType (lir .IntType (1 ),
99+ [lir .IntType (8 ).as_pointer (), lir .IntType (8 ).as_pointer ()])
100+ fn = builder .module .get_or_insert_function (fnty , name = "str_equal" )
101+ return builder .not_ (builder .call (fn , args ))
0 commit comments