# Path: pyjvm/bytecode.py
# def bytecode(code):
#     def cl(func):
#         BYTECODE[hex(code)] = func
#         return func
# 
#     return cl
# 
# Path: pyjvm/jassert.py
# def jassert_float(value):
#     assert type(value) is tuple and value[0] == "float"
# 
# Path: pyjvm/jassert.py
# def jassert_double(value):
#     assert type(value) is tuple and value[0] == "double"
# 
# Path: pyjvm/jassert.py
# def jassert_int(value):
#     assert type(value) is int or type(value) is long
#     assert -2147483648 <= value <= 2147483647
# 
# Path: pyjvm/jassert.py
# def jassert_long(value):
#     assert type(value) is tuple and value[0] == "long"
#     assert -9223372036854775808 <= value[1] <= 9223372036854775807
# 
# Path: pyjvm/jassert.py
# def jassert_ref(ref):
#     assert ref is None or (type(ref) is tuple and ref[0] in ("ref", "vm_ref"))
# 
# Path: pyjvm/throw.py
# class JavaException(Exception):
#     '''PY excpetion.
# 
#     Real heap reference is stored in ref
#     '''
# 
#     def __init__(self, _vm, _ref):
#         self.vm = _vm
#         self.ref = _ref
#         self.stack = []
# 
#     def __str__(self):
#         ex = self.vm.heap[self.ref[1]]
#         return str(ex)


import logging
from pyjvm.bytecode import bytecode
from pyjvm.jassert import jassert_float
from pyjvm.jassert import jassert_double
from pyjvm.jassert import jassert_int
from pyjvm.jassert import jassert_long
from pyjvm.jassert import jassert_ref
from pyjvm.throw import JavaException
@bytecode(code=0xaf)
def dreturn(frame):
    value = frame.stack.pop()
    logger.debug("To be returned {0}".format(value))
    jassert_double(value)
    frame.ret = value
    frame.has_result = True
    frame.pc = len(frame.code) + 1


@bytecode(code=0xb0)
def areturn(frame):
    value = frame.stack.pop()
    jassert_ref(value)
    frame.ret = value
    frame.has_result = True
    frame.pc = len(frame.code) + 1


@bytecode(code=0xb1)
def return_(frame):
    frame.pc = len(frame.code) + 1


@bytecode(code=0xbf)
def athrow(frame):
    ref = frame.stack.pop()
    if ref is None:
        frame.vm.raise_exception(frame, "java/lang/NullPointerException")
        return

# Path: pyjvm/bytecode.py
# def bytecode(code):
#     def cl(func):
#         BYTECODE[hex(code)] = func
#         return func
# 
#     return cl
# 
# Path: pyjvm/jassert.py
# def jassert_float(value):
#     assert type(value) is tuple and value[0] == "float"
# 
# Path: pyjvm/jassert.py
# def jassert_double(value):
#     assert type(value) is tuple and value[0] == "double"
# 
# Path: pyjvm/jassert.py
# def jassert_int(value):
#     assert type(value) is int or type(value) is long
#     assert -2147483648 <= value <= 2147483647
# 
# Path: pyjvm/jassert.py
# def jassert_long(value):
#     assert type(value) is tuple and value[0] == "long"
#     assert -9223372036854775808 <= value[1] <= 9223372036854775807
# 
# Path: pyjvm/jassert.py
# def jassert_ref(ref):
#     assert ref is None or (type(ref) is tuple and ref[0] in ("ref", "vm_ref"))
# 
# Path: pyjvm/throw.py
# class JavaException(Exception):
#     '''PY excpetion.
# 
#     Real heap reference is stored in ref
#     '''
# 
#     def __init__(self, _vm, _ref):
#         self.vm = _vm
#         self.ref = _ref
#         self.stack = []
# 
#     def __str__(self):
#         ex = self.vm.heap[self.ref[1]]
#         return str(ex)


# Path: pyjvm/ops/ops_ret.py
import logging
from pyjvm.bytecode import bytecode
from pyjvm.jassert import jassert_float
from pyjvm.jassert import jassert_double
from pyjvm.jassert import jassert_int
from pyjvm.jassert import jassert_long
from pyjvm.jassert import jassert_ref
from pyjvm.throw import JavaException

@bytecode(code=0xaf)
def dreturn(frame):
    value = frame.stack.pop()
    logger.debug("To be returned {0}".format(value))
    jassert_double(value)
    frame.ret = value
    frame.has_result = True
    frame.pc = len(frame.code) + 1


@bytecode(code=0xb0)
def areturn(frame):
    value = frame.stack.pop()
    jassert_ref(value)
    frame.ret = value
    frame.has_result = True
    frame.pc = len(frame.code) + 1


@bytecode(code=0xb1)
def return_(frame):
    frame.pc = len(frame.code) + 1


@bytecode(code=0xbf)
def athrow(frame):
    ref = frame.stack.pop()
    if ref is None:
        frame.vm.raise_exception(frame, "java/lang/NullPointerException")
        return

    jassert_ref(ref)