Esempio n. 1
0
def test_value_pool_no_default():
    test1, test2 = object(), object()
    pool = ValuePool(None)

    assert pool.index_for(test1) == 0
    assert pool.value_at(0) == test1

    assert pool.index_for(test2) == 1
    assert pool.value_at(1) == test2
Esempio n. 2
0
def test_value_pool_default():
    test = object()
    pool = ValuePool(None, default=test)

    assert pool.value_at(0) == test
    assert pool.index_for(test) == 0

    assert pool.index_for(1) == 1
    assert pool.index_for(1) == 1

    assert pool.value_at(0) == test
    assert pool.value_at(1) == 1
Esempio n. 3
0
    def __init__(self):
        self.int       = ValuePool(self, 0)

        # don't match -- pushuint is dumb
        self.uint      = ValuePool(self, 0, lambda v: False)
        self.double    = ValuePool(self, float('nan'), isnan)

        # don't match due to https://bugzilla.mozilla.org/show_bug.cgi?id=628031
        self.utf8      = ValuePool(self, "", lambda v: False)
        self.namespace = ValuePool(self, ANY_NAMESPACE)
        self.nsset     = ValuePool(self, "non-existant", lambda v: False)
        self.multiname = ValuePool(self, QName("*"))
Esempio n. 4
0
    def __init__(self, constants=None):
        self.constants = constants or ConstantPool()

        self.methods   = ValuePool(self)
        self.metadatas = ValuePool(self)
        self.instances = ValuePool(self)
        self.classes   = ValuePool(self)
        self.scripts   = ValuePool(self)
        self.bodies    = ValuePool(self)
Esempio n. 5
0
    def __init__(self, local_names):
        self.local_names = local_names
        self.locals = ValuePool(None)
        for i in local_names:
            self.locals.index_for(i)

        self.instructions = []

        self._stack_depth = 0
        self._scope_depth = 0

        self.max_local_count = len(local_names)
        self.max_stack_depth = 0
        self.max_scope_depth = 0

        # jump-like instructions
        self.jumps = []

        # name -> Label
        self.labels = {}

        self.flags = 0