To protect your data, the CISO officer has suggested users to enable GitLab 2FA as soon as possible.

array_primitives.py 1.19 KB
Newer Older
Stefan Marr's avatar
Stefan Marr committed
1
2
3
from som.vmobjects.primitive   import Primitive
from som.primitives.primitives import Primitives

4
5
6
7
def _at(ivkbl, frame, interpreter):
    i    = frame.pop()
    rcvr = frame.pop()
    frame.push(rcvr.get_indexable_field(i.get_embedded_integer() - 1)) 
Stefan Marr's avatar
Stefan Marr committed
8
9


10
11
12
13
14
15
def _atPut(ivkbl, frame, interpreter):
    value = frame.pop()
    index = frame.pop()
    rcvr  = frame.get_stack_element(0)
    rcvr.set_indexable_field(index.get_embedded_integer() - 1, value)

Stefan Marr's avatar
Stefan Marr committed
16

17
18
19
20
def _length(ivkbl, frame, interpreter):
    rcvr = frame.pop()
    frame.push(interpreter.get_universe().new_integer(rcvr.get_number_of_indexable_fields()))

Stefan Marr's avatar
Stefan Marr committed
21

22
23
24
25
26
27
def _new(ivkbl, frame, interpreter):
    length = frame.pop()
    frame.pop() # not required
    frame.push(interpreter.get_universe().new_array_with_length(length.get_embedded_integer()))


Stefan Marr's avatar
Stefan Marr committed
28
29
30
31
32
33
34
class ArrayPrimitives(Primitives):
    
    def install_primitives(self):
        self._install_instance_primitive(Primitive("at:", self._universe, _at))
        self._install_instance_primitive(Primitive("at:put:", self._universe, _atPut))
        self._install_instance_primitive(Primitive("length", self._universe, _length))
        
Stefan Marr's avatar
Stefan Marr committed
35
        self._install_class_primitive(Primitive("new:", self._universe, _new))