How to use the vyper.parser.parser_utils.LLLnode function in vyper

To help you get started, we’ve selected a few vyper examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vyperlang / vyper / tests / parser / features / test_gas.py View on Github external
def test_gas_estimate_repr():
    code = """
x: int128

@public
def __init__():
    self.x = 1
    """
    parser_utils.LLLnode.repr_show_gas = True
    out = parse_to_lll(code)
    assert '35303' in str(out)[:28]
    parser_utils.LLLnode.repr_show_gas = False
github vyperlang / vyper / vyper / optimizer.py View on Github external
return LLLnode.from_list(
                [node.value] + argz,
                typ=node.typ,
                location=node.location,
                pos=node.pos,
                annotation=node.annotation,
                # let from_list handle valency and gas_estimate
                )
    elif node.value == "seq":
        xs: List[Any] = []
        for arg in argz:
            if arg.value == "seq":
                xs.extend(arg.args)
            else:
                xs.append(arg)
        return LLLnode(
            node.value,
            xs,
            node.typ,
            node.location,
            node.pos,
            node.annotation,
            add_gas_estimate=node.add_gas_estimate,
            valency=node.valency,
        )
    elif node.total_gas is not None:
        o = LLLnode(
            node.value,
            argz,
            node.typ,
            node.location,
            node.pos,
github vyperlang / vyper / vyper / cli / vyper_lll.py View on Github external
def compile_to_lll(input_file, output_formats, show_gas_estimates=False):
    with open(input_file) as fh:
        s_expressions = parse_s_exp(fh.read())

    if show_gas_estimates:
        LLLnode.repr_show_gas = True

    compiler_data = {}
    lll = LLLnode.from_list(s_expressions[0])
    if 'ir' in output_formats:
        compiler_data['ir'] = lll

    if 'opt_ir' in output_formats:
        compiler_data['opt_ir'] = optimizer.optimize(lll)

    asm = compile_lll.compile_to_assembly(lll)
    if 'asm' in output_formats:
        compiler_data['asm'] = asm

    if 'bytecode' in output_formats:
        (bytecode, _srcmap) = compile_lll.assembly_to_evm(asm)
        compiler_data['bytecode'] = '0x' + bytecode.hex()

    return compiler_data
github vyperlang / vyper / vyper / functions / functions.py View on Github external
def as_unitless_number(expr, args, kwargs, context):
    return LLLnode(
        value=args[0].value,
        args=args[0].args,
        typ=BaseType(args[0].typ.typ, {}),
        pos=getpos(expr),
    )
github vyperlang / vyper / vyper / functions / functions.py View on Github external
def method_id(expr, args, kwargs, context):
    if b' ' in args[0]:
        raise TypeMismatchException('Invalid function signature no spaces allowed.')
    method_id = fourbytes_to_int(keccak256(args[0])[:4])
    if args[1] == 'bytes32':
        return LLLnode(method_id, typ=BaseType('bytes32'), pos=getpos(expr))
    elif args[1] == 'bytes[4]':
        placeholder = LLLnode.from_list(context.new_placeholder(ByteArrayType(4)))
        return LLLnode.from_list(
            ['seq',
                ['mstore', ['add', placeholder, 4], method_id],
                ['mstore', placeholder, 4], placeholder],
            typ=ByteArrayType(4), location='memory', pos=getpos(expr))
    else:
        raise StructureException('Can only produce bytes32 or bytes[4] as outputs')
github vyperlang / vyper / vyper / optimizer.py View on Github external
if get_int_at(argz, 0, True) > get_int_at(argz, 1, True):
            raise Exception("Clamp always fails")
        else:
            return LLLnode(
                "clample",
                [argz[1], argz[2]],
                node.typ,
                node.location,
                node.pos,
                node.annotation,
                add_gas_estimate=node.add_gas_estimate,
                valency=node.valency,
            )
    elif node.value == "clamp_nonzero" and int_at(argz, 0):
        if get_int_at(argz, 0) != 0:
            return LLLnode(
                argz[0].value,
                [],
                node.typ,
                node.location,
                node.pos,
                node.annotation,
                add_gas_estimate=node.add_gas_estimate,
                valency=node.valency,
            )
        else:
            raise Exception("Clamp always fails")
    # [eq, x, 0] is the same as [iszero, x].
    elif node.value == 'eq' and int_at(argz, 1) and argz[1].value == 0:
        return LLLnode(
            'iszero',
            [argz[0]],
github Neroysq / VyperFlow / vyper / parser / parser.py View on Github external
# Create the main statement
    o = ['seq']
    if _events:
        sigs = parse_events(sigs, _events, _custom_units)
    if _contracts:
        external_contracts = parse_external_contracts(external_contracts, _contracts)
    # If there is an init func...
    if initfunc:
        o.append(['seq', initializer_lll])
        o.append(parse_func(initfunc[0], _globals, {**{'self': sigs}, **external_contracts}, origcode, _custom_units))
    # If there are regular functions...
    if otherfuncs or defaultfunc:
        o = parse_other_functions(
            o, otherfuncs, _globals, sigs, external_contracts, origcode, _custom_units, defaultfunc, runtime_only
        )
    return LLLnode.from_list(o, typ=None)
github vyperlang / vyper / vyper / optimizer.py View on Github external
argz = [optimize(arg) for arg in node.args]
    if node.value in arith and int_at(argz, 0) and int_at(argz, 1):
        left, right = get_int_at(argz, 0), get_int_at(argz, 1)
        calcer, symb = arith[node.value]
        new_value = calcer(left, right)
        if argz[0].annotation and argz[1].annotation:
            annotation = argz[0].annotation + symb + argz[1].annotation
        elif argz[0].annotation or argz[1].annotation:
            annotation = (
                argz[0].annotation or str(left)
            ) + symb + (
                argz[1].annotation or str(right)
            )
        else:
            annotation = ''
        return LLLnode(
            new_value,
            [],
            node.typ,
            None,
            node.pos,
            annotation,
            add_gas_estimate=node.add_gas_estimate,
            valency=node.valency,
        )
    elif _is_constant_add(node, argz):
        calcer, symb = arith[node.value]
        if argz[0].annotation and argz[1].args[0].annotation:
            annotation = argz[0].annotation + symb + argz[1].args[0].annotation
        elif argz[0].annotation or argz[1].args[0].annotation:
            annotation = (
                argz[0].annotation or str(argz[0].value)
github vyperlang / vyper / vyper / functions / functions.py View on Github external
def send(expr, args, kwargs, context):
    to, value = args
    if context.is_constant():
        raise ConstancyViolationException(
            f"Cannot send ether inside {context.pp_constancy()}!",
            expr,
        )
    enforce_units(value.typ, expr.args[1], BaseType('uint256', {'wei': 1}))
    return LLLnode.from_list(
        ['assert', ['call', 0, to, value, 0, 0, 0, 0]],
        typ=None,
        pos=getpos(expr),
    )