示例#1
0
 def interpret(context, methodName, cmdLineArgs):
     try:
         method = Interpreter.locateMethod(context, methodName, cmdLineArgs)
         arguments = Interpreter.buildArguments(method, cmdLineArgs)
         call = MethodCall(MethodSelector(methodName), arguments)
         call.interpret(context)
     finally:
         context.terminated()
示例#2
0
 def setParent(self, parent):
     if parent is not None:
         if isinstance(self.caller, UnresolvedIdentifier):
             self.caller = MethodSelector(self.caller.name, parent)
         elif isinstance(self.caller, SelectorExpression):
             self.caller.parent = parent
         else:
             raise Exception("Should never happen!")
示例#3
0
 def resolveUnresolvedDeclaration(self, context, name):
     decl = context.getRegisteredDeclaration(IDeclaration, name)
     if decl is None:
         raise SyntaxError("Unknown name:" + name)
     if isinstance(decl, CategoryDeclaration):
         return ConstructorExpression(CategoryType(name), None, self.arguments)
     else:
         return MethodCall(MethodSelector(name), self.arguments)
示例#4
0
 def resolveUnresolvedMemberMethod(self, context, name):
     instance = context.getClosestInstanceContext()
     if instance is None:
         return None
     decl = self.resolveUnresolvedMember(instance, name)
     if decl is not None:
         return MethodCall(MethodSelector(name), self.arguments)
     else:
         return None
示例#5
0
 def resolveMethodCall(self, context):
     if not self.dialect is Dialect.E:
         return None
     from prompto.statement.MethodCall import MethodCall
     from prompto.expression.MethodSelector import MethodSelector
     try:
         method = MethodCall(MethodSelector(self.name))
         method.check(context)
         return method
     except SyntaxError:
         return None
示例#6
0
 def tryResolveMethod(self, context, arguments):
     try:
         resolvedParent = self.parent
         if isinstance(resolvedParent, UnresolvedIdentifier):
             resolvedParent.checkMember(context)
             resolvedParent = resolvedParent.resolved
         method = UnresolvedCall(MethodSelector(self.name, resolvedParent), arguments)
         method.check(context)
         return method
     except SyntaxError:
         return None
示例#7
0
 def globalMethodExists(self, context, name):
     from prompto.statement.MethodCall import MethodCall
     from prompto.runtime.MethodFinder import MethodFinder
     try:
         exp = ValueExpression(self, self.newInstance(context))
         arg = Argument(None, exp)
         args = ArgumentList(items=[arg])
         proto = MethodCall(MethodSelector(name), args)
         finder = MethodFinder(context, proto)
         return finder.findBest(True) is not None
     except PromptoError:
         return False
示例#8
0
    def getGlobalMethodSortKeyReader(self, context, name):
        from prompto.statement.MethodCall import MethodCall
        exp = ValueExpression(self, self.newInstance(context))
        arg = Argument(None, exp)
        args = ArgumentList(items=[arg])
        call = MethodCall(MethodSelector(name), args)

        def keyGetter(o):
            argument = call.arguments[0]
            argument.setExpression(ValueExpression(self, o))
            return call.interpret(context)

        return keyGetter
示例#9
0
 def resolveUnresolvedMethodReference(self, context, name):
     # it could be a reference to a local closure
     named = context.getRegisteredValue(INamed, name)
     if named is None:
         return None
     itype = named.getType(context)
     if itype is not None:
         itype = itype.resolve(context)
         if isinstance(itype, MethodType):
             call = MethodCall(MethodSelector(name), self.arguments)
             call.variableName = name
             return call
     return None
示例#10
0
 def resolveMember(self, context):
     parent = self.caller.getParent()
     name = self.caller.getName()
     return MethodCall(MethodSelector(name, parent), self.arguments)
示例#11
0
 def resolveMember(self, context: Context):
     parent = self.caller.parent
     name = self.caller.name
     return MethodCall(MethodSelector(name, parent), self.arguments)