Exemple #1
0
def return_statement(subtree):
    method = enclosing_method(subtree)
    if method.tag == "constructor_declaration":
        subtree.assembly = """
; return from constructor
mov eax, {this}
leave
ret
""".format(
            this=stack_slot_to_operand(this)
        )
        return

    expression = subtree.find("expression")
    subtree.assembly = """
leave
ret
; end return statement
"""
    if expression is not None:
        child_slot = expression.slot
        subtree.assembly = """
mov eax, {child_slot}
{return_assembly}
""".format(
            child_slot=stack_slot_to_operand(child_slot), return_assembly=subtree.assembly
        )
Exemple #2
0
def generate_new_stack_slot(subtree):
    method = enclosing_method(subtree)
    if method:
        method.slot += 1
        return method.slot

    CurrentFile.static_slot += 1
    return CurrentFile.static_slot