Improve creating custom methods to checking specifier of generic types (list)

This commit is contained in:
Bartłomiej Pluta
2019-07-08 18:18:40 +02:00
parent 6d56706354
commit 05dfe46f9f
3 changed files with 23 additions and 12 deletions

View File

@@ -1,16 +1,26 @@
from smnp.ast.node.none import NoneNode
from smnp.library.signature import ofType, signature
from smnp.runtime.evaluator import Evaluator
from smnp.runtime.evaluators.function import argumentsNodeToMethodSignature
from smnp.runtime.evaluators.type import TypeEvaluator
from smnp.runtime.evaluators.function import argumentsNodeToMethodSignature, listSpecifier
from smnp.type.model import Type
class ExtendEvaluator(Evaluator):
@classmethod
def evaluator(cls, node, environment):
type = TypeEvaluator.evaluate(node.type, environment).value #TODO check if it isn't necessary to verify 'result' attr of EvaluatioNResult
type = cls._typeToMethodSignature(node.type) # TODO check if it isn't necessary to verify 'result' attr of EvaluatioNResult
variable = node.variable.value
cls._evaluateExtend(node.methods, environment, type, variable)
@classmethod
def _typeToMethodSignature(cls, node):
if type(node.specifier) == NoneNode:
return signature(ofType(node.type))
elif node.type == Type.LIST:
return signature(listSpecifier(node.specifier))
@classmethod
def _evaluateExtend(cls, node, environment, type, variable):
for child in node.children:
@@ -22,4 +32,5 @@ class ExtendEvaluator(Evaluator):
signature = argumentsNodeToMethodSignature(node.arguments)
arguments = [arg.variable.value for arg in node.arguments]
body = node.body
environment.addCustomMethod(type, variable, name, signature, arguments, body)
environment.addCustomMethod(type, variable, name, signature, arguments, body)