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()
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
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
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)
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
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
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
def resolveMember(self, context): parent = self.caller.getParent() name = self.caller.getName() return MethodCall(MethodSelector(name, parent), self.arguments)
def resolveMember(self, context: Context): parent = self.caller.parent name = self.caller.name return MethodCall(MethodSelector(name, parent), self.arguments)