コード例 #1
0
    def newInstanceContext(self, context: Context):
        from prompto.type.CategoryType import CategoryType
        from prompto.expression.CategorySymbol import CategorySymbol
        from prompto.value.ConcreteInstance import ConcreteInstance
        from prompto.value.NativeInstance import NativeInstance
        from prompto.declaration.SingletonCategoryDeclaration import SingletonCategoryDeclaration

        value = self.parent.interpret(context)
        if value is None or value is NullValue.instance:
            from prompto.error.NullReferenceError import NullReferenceError
            raise NullReferenceError()
        if isinstance(value, TypeValue):
            typ = value.value
            if isinstance(typ, CategoryType):
                decl = typ.getDeclaration(context)
                if isinstance(decl, SingletonCategoryDeclaration):
                    value = context.loadSingleton(value.value)
        if isinstance(value, CategorySymbol):
            value = value.interpret(context)
        if isinstance(value, TypeValue):
            return context.newChildContext()
        elif isinstance(value, (ConcreteInstance, NativeInstance)):
            context = context.newInstanceContext(value, None)
            return context.newChildContext()
        else:
            context = context.newBuiltInContext(value)
            return context.newChildContext()
コード例 #2
0
 def check(self, context: Context):
     resultType = self.resolveAndCheck(context)
     context = context.newChildContext()
     if self.resultName is not None:
         context.registerValue(Variable(self.resultName, resultType))
     self.andThen.check(context, VoidType.instance)
     return VoidType.instance
コード例 #3
0
 def newInstanceCheckContext(self, context: Context):
     from prompto.type.CategoryType import CategoryType
     from prompto.type.TypeType import TypeType
     from prompto.declaration.IDeclaration import IDeclaration
     from prompto.declaration.SingletonCategoryDeclaration import SingletonCategoryDeclaration
     typ = self.parent.check(context)
     # if calling singleton method, parent is the singleton type
     if isinstance(typ, TypeType):
         decl = context.getRegisteredDeclaration(IDeclaration,
                                                 typ.typ.typeName)
         if isinstance(decl, SingletonCategoryDeclaration):
             typ = decl.getType(context)
     if isinstance(typ, CategoryType):
         context = context.newInstanceContext(None, typ)
         return context.newChildContext()
     else:
         return context.newChildContext()
コード例 #4
0
 def interpret(self, context: Context):
     resultType = self.resolveAndCheck(context)
     resultValue = super().interpret(context)
     context = context.newChildContext()
     if self.resultName is not None:
         context.registerValue(Variable(self.resultName, resultType))
         context.setValue(self.resultName, resultValue)
     self.andThen.interpret(context)
     return None