Skip to content

Commit

Permalink
Implement optional packetbuffer function
Browse files Browse the repository at this point in the history
  • Loading branch information
Pokechu22 committed Feb 17, 2022
1 parent 74876da commit a9d3377
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions burger/toppings/packetinstructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,8 +663,34 @@ def _handle_2_arg_buffer_call(classloader, classes, instruction, verbose,
# the endloop past everything.
operations.append(Operation(instruction.pos + 1 - SUB_INS_EPSILON, "endloop"))
return operations
elif desc.args[0].name == "java/util/Optional" and \
desc.args[1].name == "java/util/function/BiConsumer":
# Write a boolean indicating whether the optional is present.
# Call the consumer with the packetbuffer and value if the optional is present.
operations = []
field = args[0]
assert isinstance(field, StackOperand)
operations.append(Operation(instruction.pos, "write", type="boolean",
field=field.value + ".isPresent()"))
operations.append(Operation(instruction.pos, "if",
condition=field.value + ".isPresent()"))
info = args[1]
assert isinstance(info, InvokeDynamicInfo)
operations += _PIT._lambda_operations(
classloader, classes, instruction, verbose,
info, [instance, field.value + ".get()"]
)
# Jank: the part of the program that converts loop+endloop
# to a nested setup sorts the operations.
# Thus, if instruction.pos is used, _sub_operations
# adds epsilon to each sub-instruction, making them
# come after the endloop.
# Assume that 1 - SUB_INS_EPSILON (e.g. .99) will put
# the endloop past everything.
operations.append(Operation(instruction.pos + 1 - SUB_INS_EPSILON, "endif"))
return operations
else:
raise Exception("Unexpected descriptor " + desc)
raise Exception("Unexpected descriptor " + desc.descriptor)

@staticmethod
def _handle_3_arg_buffer_call(classloader, classes, instruction, verbose,
Expand Down Expand Up @@ -711,7 +737,7 @@ def _handle_3_arg_buffer_call(classloader, classes, instruction, verbose,
operations.append(Operation(instruction.pos + 1 - SUB_INS_EPSILON, "endloop"))
return operations
else:
raise Exception("Unexpected descriptor " + desc)
raise Exception("Unexpected descriptor " + desc.descriptor)

@staticmethod
def _handle_foreach(classloader, classes, instruction, verbose,
Expand Down

0 comments on commit a9d3377

Please sign in to comment.