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

primitive.py 2.24 KB
Newer Older
Stefan Marr's avatar
Stefan Marr committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from som.vmobjects.object    import Object
from som.vmobjects.invokable import Invokable

class Primitive(Object, Invokable):
    
    # Static field indices and number of primitive fields
    SIGNATURE_INDEX            = 1 + Object.CLASS_INDEX
    HOLDER_INDEX               = 1 + SIGNATURE_INDEX
    NUMBER_OF_PRIMITIVE_FIELDS = 1 + HOLDER_INDEX
    
    def __init__(self, signature_string, universe, invoke, is_empty = None):
        super(Primitive, self).__init__(universe.nilObject)
        
        # Set the class of this primitive to be the universal primitive class
        self.set_class(universe.primitiveClass)

        # Set the signature of this primitive
        self._set_signature(universe.symbol_for(signature_string))
        
        self.invoke = invoke
        if is_empty:
            self.is_empty = is_empty

    def is_primitive(self):
        return True

    def get_signature(self):
        # Get the signature by reading the field with signature index
        return self.get_field(self.SIGNATURE_INDEX)

    def _set_signature(self, value):
        # Set the signature by writing to the field with signature index
        self.set_field(self.SIGNATURE_INDEX, value)


    def get_holder(self):
        # Get the holder of this method by reading the field with holder index
        return self.get_field(self.HOLDER_INDEX)

    def set_holder(self, value):
        # Set the holder of this method by writing to the field with holder index
        self.set_field(self.HOLDER_INDEX, value)

    def _get_default_number_of_fields(self):
        # Return the default number of fields for a primitive
        return self.NUMBER_OF_PRIMITIVE_FIELDS

    def is_empty(self):
        # By default a primitive is not empty
        return False

    @classmethod
    def get_empty_primitive(cls, signature_string, universe):
        # Return an empty primitive with the given signature
        def invoke(self, frame, interpreter):
            # Write a warning to the screen
            universe.println("Warning: undefined primitive " +
                             self.get_signature().get_string() + " called")
      
        # The empty primitives are empty
        def is_empty(self): return True
        return Primitive(signature_string, universe, invoke, is_empty)