Esempio n. 1
0
def do_commit(ctx: Context, prim, args, annots):
    debug, ctx.debug = ctx.debug, False

    output = ctx.pop1()
    assert_stack_type(output, Pair)

    operations = output.get_element(0)
    assert_stack_type(operations, List)
    assert operations.val_type() == Operation, f'expected list of operations'

    s_type_expr = ctx.get('storage')
    assert s_type_expr, f'storage type is not initialized'
    storage = output.get_element(1)
    assert_expr_equal(s_type_expr, storage.type_expr)

    storage, big_map_diff = ctx.big_maps.diff(storage)
    ctx.big_maps.commit(big_map_diff)

    res = Pair.new(operations, storage)
    ctx.push(res)
    ctx.debug = debug
    return {'kind': 'output',
            'operations': operations,
            'storage': storage,
            'big_map_diff': big_map_diff}
Esempio n. 2
0
def do_begin(ctx: Context, prim, args, annots):
    p_type_expr = ctx.get('parameter')
    assert p_type_expr, f'parameter type is not initialized'

    entrypoint = next((a for a in annots if a[0] == '%'), '%default')
    ctx.print(f'use {entrypoint}')

    network = ctx.get('NETWORK')
    if network:
        ctx.print(f'use {network}')

    p_val_expr = restore_entry_expr(val_expr=args[0],
                                    type_expr=p_type_expr,
                                    field_annot=entrypoint)
    parameter = ctx.big_maps.pre_alloc(p_val_expr,
                                       p_type_expr,
                                       copy=True,
                                       network=network)

    s_type_expr = ctx.get('storage')
    assert s_type_expr, f'storage type is not initialized'
    s_val_expr = ctx.get('STORAGE') if is_prim(args[1], 'STORAGE') else args[1]
    storage = ctx.big_maps.pre_alloc(s_val_expr, s_type_expr, network=network)

    ctx.drop_all()
    run_input = Pair.new(parameter, storage)
    ctx.push(run_input, annots=annots)
Esempio n. 3
0
def do_map(ctx: Context, prim, args, annots):
    container = ctx.pop1()
    assert_stack_type(container, [List, Map])

    if type(container) == List:
        items = list()
        for item in container:
            ctx.push(item)
            do_interpret(ctx, args[0])
            ret = ctx.pop1()
            items.append(ret)
    elif type(container) == Map:
        items = list()
        for key, val in container:
            ctx.push(Pair.new(key, val))
            do_interpret(ctx, args[0])
            ret = ctx.pop1()
            items.append((key, ret))
    else:
        assert False

    if len(items) == 0:
        res = container
    else:
        res = type(container).new(items)
    ctx.push(res, annots=annots)
Esempio n. 4
0
def do_ediv(ctx: Context, prim, args, annots):
    a, b = ctx.pop2()
    q_type, r_type = dispatch_type_map(
        a, b, {
            (Nat, Nat): (Nat, Nat),
            (Nat, Int): (Int, Nat),
            (Int, Nat): (Int, Nat),
            (Int, Int): (Int, Nat),
            (Mutez, Nat): (Mutez, Mutez),
            (Mutez, Mutez): (Nat, Mutez)
        })
    if int(b) == 0:
        res = Option.none(Pair.new(q_type(), r_type()).type_expr)
    else:
        q, r = divmod(int(a), int(b))
        if r < 0:
            r += abs(int(b))
            q += 1
        res = Option.some(Pair.new(q_type(q), r_type(r)))
    ctx.push(res, annots=annots)
Esempio n. 5
0
def do_map(ctx: Context, prim, args, annots):
    assert_no_annots(prim, annots)
    container = ctx.pop1()
    inferred_annots = [f'@{container.name}.elt'] if container.name else None
    if type(container) in [List, Set]:
        for item in container:
            ctx.push(item, annots=inferred_annots)
            do_interpret(ctx, args[0])
    elif type(container) == Map:
        for key, val in container:
            ctx.push(Pair.new(key, val), annots=inferred_annots)
            do_interpret(ctx, args[0])
    else:
        assert False, f'unexpected type {type(container)}'
Esempio n. 6
0
def do_pair(ctx: Context, prim, args, annots):
    left, right = ctx.pop2()
    res = Pair.new(left, right)
    ctx.push(res, annots=annots)