# Path: pyjvm/bytecode.py
# def bytecode(code):
#     def cl(func):
#         BYTECODE[hex(code)] = func
#         return func
# 
#     return cl
# 
# Path: pyjvm/jassert.py
# def jassert_array(array):
#     assert array is None or isinstance(array, JArray)
# 
# 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/jvmo.py
# class JArray(object):
#     '''Java array
# 
#     Lives in heap and has corresponding java_class
#     '''
#     def __init__(self, jc, vm):
#         self.java_class = jc
#         self.fields = {}
#         self.values = []


import logging
from pyjvm.bytecode import bytecode
from pyjvm.jassert import jassert_array
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.jvmo import JArray
    index = (ord(frame.code[frame.pc]) << 8) + ord(frame.code[frame.pc + 1])
    frame.pc += 2
    cp_item = frame.this_class.constant_pool[index]
    assert cp_item[0] == 7  # CONSTANT_Class
    klass_name = frame.this_class.constant_pool[cp_item[1]][1]
    assert type(klass_name) is unicode
    frame.vm.get_class(klass_name)  # make sure it is loaded

    count = frame.stack.pop()
    jassert_int(count)
    if count < 0:
        frame.vm.raise_exception(frame, "java/lang/NegativeArraySizeException")
        return

    values = [None] * count
    array_class = frame.vm.get_class("[L" + klass_name + ";")
    jarray = JArray(array_class, frame.vm)
    jarray.values = values
    ref = frame.vm.add_to_heap(jarray)
    frame.stack.append(ref)


@bytecode(code=0xbe)
def arraylength(frame):
    ref = frame.stack.pop()
    if ref is None:
        frame.vm.raise_exception(frame, "java/lang/NullPointerException")
        return
    assert ref[0] == "ref"
    array = frame.vm.heap[ref[1]]

# Path: pyjvm/bytecode.py
# def bytecode(code):
#     def cl(func):
#         BYTECODE[hex(code)] = func
#         return func
# 
#     return cl
# 
# Path: pyjvm/jassert.py
# def jassert_array(array):
#     assert array is None or isinstance(array, JArray)
# 
# 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/jvmo.py
# class JArray(object):
#     '''Java array
# 
#     Lives in heap and has corresponding java_class
#     '''
#     def __init__(self, jc, vm):
#         self.java_class = jc
#         self.fields = {}
#         self.values = []


# Path: pyjvm/ops/ops_arrays.py
import logging
from pyjvm.bytecode import bytecode
from pyjvm.jassert import jassert_array
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.jvmo import JArray

    index = (ord(frame.code[frame.pc]) << 8) + ord(frame.code[frame.pc + 1])
    frame.pc += 2
    cp_item = frame.this_class.constant_pool[index]
    assert cp_item[0] == 7  # CONSTANT_Class
    klass_name = frame.this_class.constant_pool[cp_item[1]][1]
    assert type(klass_name) is unicode
    frame.vm.get_class(klass_name)  # make sure it is loaded

    count = frame.stack.pop()
    jassert_int(count)
    if count < 0:
        frame.vm.raise_exception(frame, "java/lang/NegativeArraySizeException")
        return

    values = [None] * count
    array_class = frame.vm.get_class("[L" + klass_name + ";")
    jarray = JArray(array_class, frame.vm)
    jarray.values = values
    ref = frame.vm.add_to_heap(jarray)
    frame.stack.append(ref)


@bytecode(code=0xbe)
def arraylength(frame):
    ref = frame.stack.pop()
    if ref is None:
        frame.vm.raise_exception(frame, "java/lang/NullPointerException")
        return
    assert ref[0] == "ref"
    array = frame.vm.heap[ref[1]]

    jassert_array(array)