예제 #1
0
파일: dict_ext.py 프로젝트: samaid/sdc
def lower_dict_getitem(context, builder, sig, args):
    dict_typ, key_typ = sig.args
    dct, key = args
    val_typ = dict_typ.val_typ

    fname = "dict_{}_{}_getitem".format(key_typ, val_typ)

    if key_typ == string_type:
        key_typ = types.voidptr
        key = gen_unicode_to_std_str(context, builder, key)

    ll_val_typ = context.get_value_type(val_typ)
    if val_typ == string_type:
        ll_val_typ = context.get_value_type(types.voidptr)

    fnty = lir.FunctionType(
        ll_val_typ,
        [lir.IntType(8).as_pointer(),
         context.get_value_type(key_typ)])

    fn = builder.module.get_or_insert_function(fnty, name=fname)
    val = builder.call(fn, [dct, key])
    if val_typ == string_type:
        val = gen_std_str_to_unicode(context, builder, val)
    return val
예제 #2
0
파일: dict_ext.py 프로젝트: rowhit/sdc
def setitem_dict(context, builder, sig, args):
    _, key_typ, val_typ = sig.args
    dct, key, val = args
    fname = "dict_{}_{}_setitem".format(key_typ, val_typ)

    if key_typ == string_type:
        key_typ = types.voidptr
        key = gen_unicode_to_std_str(context, builder, key)

    if val_typ == string_type:
        val_typ = types.voidptr
        val = gen_unicode_to_std_str(context, builder, val)

    fnty = lir.FunctionType(lir.VoidType(),
                            [lir.IntType(8).as_pointer(),
                             context.get_value_type(key_typ),
                             context.get_value_type(val_typ)])
    fn = builder.module.get_or_insert_function(fnty, name=fname)
    return builder.call(fn, [dct, key, val])
예제 #3
0
파일: dict_ext.py 프로젝트: rowhit/sdc
def lower_dict_in_op(context, builder, sig, args):
    dict_typ, key_typ = sig.args
    dct, key = args

    fname = "dict_{}_{}_in".format(key_typ, dict_typ.val_typ)

    if key_typ == string_type:
        key_typ = types.voidptr
        key = gen_unicode_to_std_str(context, builder, key)

    fnty = lir.FunctionType(lir.IntType(1), [lir.IntType(8).as_pointer(),
                                             context.get_value_type(key_typ), ])
    fn = builder.module.get_or_insert_function(fnty, name=fname)
    return builder.call(fn, [dct, key])