예제 #1
0
def heap_allocate(caller, builder, type, env):
    """
    Heap allocate an object of type `type`
    """
    phase = env['flypy.state.phase']
    # TODO: implement untyped pykit builder !

    # Put object on the heap: call gc.gc_alloc(nitems, type)
    gcmod = gc.gc_impl(env["flypy.gc.impl"])
    context = env['flypy.typing.context']

    # Build arguments for gc_alloc
    n = Const(1, ptypes.Opaque)
    ty = Const(type, ptypes.Opaque)
    context[n] = int64
    context[ty] = Type[type]

    # Type the gc_alloc function
    p = caller.call(phase, gcmod.gc_alloc, [n, ty])
    obj = builder.convert(ptypes.Opaque, p)

    # Update type context
    context[p] = Pointer[void]

    return [p, obj], obj
예제 #2
0
def heap_allocate(caller, builder, type, env):
    """
    Heap allocate an object of type `type`
    """
    phase = env['flypy.state.phase']
    # TODO: implement untyped pykit builder !

    # Put object on the heap: call gc.gc_alloc(nitems, type)
    gcmod = gc.gc_impl(env["flypy.gc.impl"])
    context = env['flypy.typing.context']

    # Build arguments for gc_alloc
    n = Const(1, ptypes.Opaque)
    ty = Const(type, ptypes.Opaque)
    context[n] = int64
    context[ty] = Type[type]

    # Type the gc_alloc function
    p = caller.call(phase, gcmod.gc_alloc, [n, ty])
    obj = builder.convert(ptypes.Opaque, p)

    # Update type context
    context[p] = Pointer[void]

    return [p, obj], obj
예제 #3
0
def allocator(func, env):
    context = env['flypy.typing.context']
    b = OpBuilder()
    caller = Caller(b, context, env)
    gcmod = gc.gc_impl(env["flypy.gc.impl"])

    for op in func.ops:
        newop = None
        if op.opcode == 'allocate_obj':
            stmts, newop = allocate_object(caller, b, context[op], env)
            newop.result = op.result
        elif op.opcode == 'register_finalizer':
            stmts = register_finalizer(caller, b, env, context,
                                       context[op.args[0]], gcmod, op.args[0])
        else:
            continue

        if stmts:
            op.replace(stmts)
        else:
            op.delete()
예제 #4
0
def allocator(func, env):
    context = env['flypy.typing.context']
    b = OpBuilder()
    caller = Caller(b, context, env)
    gcmod = gc.gc_impl(env["flypy.gc.impl"])

    for op in func.ops:
        newop = None
        if op.opcode == 'allocate_obj':
            stmts, newop = allocate_object(caller, b, context[op], env)
            newop.result = op.result
        elif op.opcode == 'register_finalizer':
            stmts = register_finalizer(caller, b, env, context,
                                       context[op.args[0]], gcmod, op.args[0])
        else:
            continue

        if stmts:
            op.replace(stmts)
        else:
            op.delete()