Exemple #1
0
 def _invokeCustomFunction(self, name, args):
     for function in self.customFunctions:
         if function.name == name:
             signatureCheckresult = function.signature.check(args)
             if signatureCheckresult[0]:
                 self.appendScope(function.defaultArgs)
                 appendedScopeIndex = len(self.scopes) - 1
                 self.scopes[-1].update({
                     argName: argValue
                     for argName, argValue in zip(
                         function.arguments, list(signatureCheckresult[1:]))
                 })
                 self.callStack.append(CallStackItem(name))
                 result = Type.void()
                 try:
                     BodyEvaluator.evaluate(
                         function.body, self
                     ).value  #TODO check if it isn't necessary to verify 'result' attr of EvaluatioNResult
                 except Return as r:
                     result = r.value
                 self.callStack.pop(-1)
                 self.popScope(mergeVariables=False)
                 self.removeScopesAfter(appendedScopeIndex)
                 return (True, result)
             raise IllegalFunctionInvocationException(
                 f"{function.name}{function.signature.string}",
                 f"{name}{argsTypesToString(args)}")
     return (False, None)
Exemple #2
0
 def _invokeCustomMethod(self, object, name, args):
     for method in self.customMethods:
         if method.typeSignature.check([
                 object
         ])[0] and method.name == name:  #Todo sprawdzic sygnature typu
             signatureCheckresult = method.signature.check(args)
             if signatureCheckresult[0]:
                 self.scopes.append(method.defaultArgs)
                 self.scopes[-1].update({
                     argName: argValue
                     for argName, argValue in zip(
                         method.arguments, list(signatureCheckresult[1:]))
                 })
                 self.scopes[-1][method.alias] = object
                 self.callStack.append(CallStackItem(name))
                 result = Type.void()
                 try:
                     BodyEvaluator.evaluate(
                         method.body, self
                     ).value  # TODO check if it isn't necessary to verify 'result' attr of EvaluatioNResult
                 except Return as r:
                     result = r.value
                 self.callStack.pop(-1)
                 self.scopes.pop(-1)
                 return (True, result)
             raise IllegalFunctionInvocationException(
                 f"{method.name}{method.signature.string}",
                 f"{name}{argsTypesToString(args)}")
     return (False, None)
Exemple #3
0
    def call(self, env, args):
        from smnp.environment.environment import CallStackItem

        for function in self.functions:
            result = function.signature.check(args)
            if result[0]:
                env.callStack.append(CallStackItem(self.name))
                ret = function.function(env, *result[1:])
                env.callStack.pop(-1)
                if ret is None:
                    return Type.void()
                return ret
        raise IllegalFunctionInvocationException(
            self.stringSignature(), f"{self.name}{argsTypesToString(args)}")
Exemple #4
0
    def __init__(self, value):
        if value is None:
            value = Type.void()

        self.value = value
Exemple #5
0
 def evaluate(cls, node, environment):
     result = cls.evaluator(node, environment)
     if result is None:
         return EvaluationResult.OK(Type.void())
     return EvaluationResult.OK(result)