Commit 4f2d4a09 authored by Stefan Marr's avatar Stefan Marr

Methods and Primitives are now identified by is_invokable()

Using a mixing as introduced in b159370a is not sufficient.
We want to be able to know whether an object is Method/Primitive and using the type test as with multiple inheritance does not work anymore.
Signed-off-by: default avatarStefan Marr <git@stefan-marr.de>
parent 49f61962
# An 'interface', or common super class for methods and primitives.
class Invokable(object):
_mixin_ = True
"""An 'interface', or common super class for methods and primitives.
WARNING: This interface is not used in the RPython version, because
RPython does not support multiple inheritance.
It is kept merely for informative purposes to show the common
parts of Method and Primitive.
"""
# Tells whether this is a primitive
def is_primitive(self):
......
from __future__ import absolute_import
from som.vmobjects.array import Array
from som.vmobjects.invokable import Invokable
from som.vmobjects.array import Array
from som.interpreter.bytecodes import Bytecodes
from som.interpreter.bytecodes import bytecode_length
from array import array
class Method(Array, Invokable):
class Method(Array):
# Static field indices and number of method fields
NUMBER_OF_LOCALS_INDEX = 1 + Array.CLASS_INDEX
......@@ -32,6 +31,12 @@ class Method(Array, Invokable):
def is_primitive(self):
return False
def is_invokable(self):
"""In the RPython version, we use this method to identify methods
and primitives
"""
return True
def get_number_of_locals(self):
# Get the number of locals (converted to a Java integer)
......@@ -69,7 +74,7 @@ class Method(Array, Invokable):
# Make sure all nested invokables have the same holder
for i in range(0, self.get_number_of_indexable_fields()):
if isinstance(self.get_indexable_field(i), Invokable):
if self.get_indexable_field(i).is_invokable():
self.get_indexable_field(i).set_holder(value)
def get_constant(self, bytecode_index):
......@@ -125,7 +130,7 @@ class Method(Array, Invokable):
i = 0
while i < len(self._bytecodes):
bc1 = self._bytecodes[i]
len1 = Bytecodes.get_bytecode_length(bc1)
len1 = bytecode_length(bc1)
if i + len1 >= len(self._bytecodes):
# we're over target, so just copy bc1
......
......@@ -89,6 +89,9 @@ class Object(object):
def send_escaped_block(self, block, universe, interpreter):
arguments = (block, )
self.send("escapedBlock:", arguments, universe, interpreter)
def is_invokable(self):
return False
def __str__(self):
return "a " + self.get_class().get_name().get_string()
from som.vmobjects.object import Object
from som.vmobjects.invokable import Invokable
import types
class Primitive(Object, Invokable):
class Primitive(Object):
# Static field indices and number of primitive fields
SIGNATURE_INDEX = 1 + Object.CLASS_INDEX
......@@ -30,6 +27,12 @@ class Primitive(Object, Invokable):
def is_primitive(self):
return True
def is_invokable(self):
"""In the RPython version, we use this method to identify methods
and primitives
"""
return True
def get_signature(self):
# Get the signature by reading the field with signature index
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment