11import numba
22from numba .extending import (box , unbox , typeof_impl , register_model , models ,
3- NativeValue , lower_builtin )
3+ NativeValue , lower_builtin , lower_cast )
44from numba .targets .imputils import lower_constant , impl_ret_new_ref
55from numba import types , typing
66from numba .typing .templates import (signature , AbstractTemplate , infer , infer_getattr ,
@@ -59,6 +59,14 @@ def generic(self, args, kws):
5959 and isinstance (args [1 ], types .Integer )):
6060 return signature (args [0 ], * args )
6161
62+ @infer_global (int )
63+ class StrToInt (AbstractTemplate ):
64+ def generic (self , args , kws ):
65+ assert not kws
66+ [arg ] = args
67+ if isinstance (arg , StringType ):
68+ return signature (types .intp , arg )
69+
6270import hstr_ext
6371ll .add_symbol ('init_string' , hstr_ext .init_string )
6472ll .add_symbol ('init_string_const' , hstr_ext .init_string_const )
@@ -67,6 +75,7 @@ def generic(self, args, kws):
6775ll .add_symbol ('str_equal' , hstr_ext .str_equal )
6876ll .add_symbol ('str_split' , hstr_ext .str_split )
6977ll .add_symbol ('str_substr_int' , hstr_ext .str_substr_int )
78+ ll .add_symbol ('str_to_int64' , hstr_ext .str_to_int64 )
7079
7180@unbox (StringType )
7281def unbox_string (typ , obj , c ):
@@ -151,3 +160,9 @@ def getitem_string(context, builder, sig, args):
151160 # TODO: handle reference counting
152161 #return impl_ret_new_ref(builder.call(fn, args))
153162 return (builder .call (fn , args ))
163+
164+ @lower_cast (StringType , types .int64 )
165+ def dict_empty (context , builder , fromty , toty , val ):
166+ fnty = lir .FunctionType (lir .IntType (64 ), [lir .IntType (8 ).as_pointer ()])
167+ fn = builder .module .get_or_insert_function (fnty , name = "str_to_int64" )
168+ return builder .call (fn , (val ,))
0 commit comments