Example #1
0
def _build_vararg(state, addr, instruction):
    base = instruction.A
    last_slot = base + instruction.B - 2

    if last_slot < base:
        node = nodes.Assignment()
        node.destinations.contents.append(nodes.MULTRES())
        node.expressions.contents.append(nodes.Vararg())
    else:
        node = _build_range_assignment(state, addr, base, last_slot)
        node.expressions.contents.append(nodes.Vararg())

    return node
Example #2
0
def _build_function_definition(prototype, header):
    node = nodes.FunctionDefinition()

    state = _State()

    state.constants = prototype.constants
    state.debuginfo = prototype.debuginfo
    state.header = header

    node._upvalues = prototype.constants.upvalue_references
    node._debuginfo = prototype.debuginfo
    node._instructions_count = len(prototype.instructions)

    if prototype.first_line_number:
        setattr(node, "_lineinfo",
                (prototype.first_line_number, prototype.lines_count))

    node.arguments.contents = _build_function_arguments(state, prototype)

    if prototype.flags.is_variadic:
        node.arguments.contents.append(nodes.Vararg())

    instructions = prototype.instructions
    node.statements.contents = _build_function_blocks(state, instructions)

    return node
Example #3
0
def _build_function_definition(prototype, slot_index):
    node = nodes.FunctionDefinition()

    state = _State()

    state.constants = prototype.constants
    state.debuginfo = prototype.debuginfo
    state.slot_index = slot_index
    node._upvalues = prototype.constants.upvalue_references
    node._debuginfo = prototype.debuginfo
    node._instructions_count = len(prototype.instructions)

    node.arguments.contents = _build_function_arguments(state, prototype)

    if prototype.flags.is_variadic:
        node.arguments.contents.append(nodes.Vararg())

    instructions = prototype.instructions
    node.statements.contents = _build_function_blocks(state, instructions)

    return node