Пример #1
0
    def execute(self, theToken):
        
        # resolve variables from the token
        resolved = {}

        linearToken = theToken.linearize()
        
        for theVar, theLocation in self._variables.items():
            try:
                assert isinstance(theLocation, VariableLocation)
                resolved[theVar] = theLocation.toValue(linearToken[theLocation.patternIndex])
            except:
                import myclips
                myclips.logger.debug("%s: unresolvable variable %s: %s:%s %s", self.completeRuleName(), theVar, theLocation.patternIndex, theLocation, linearToken )
        
        # prepare the FunctionEnv object    
        theEnv = FunctionEnv(resolved, self._network, self._network.modulesManager, self._network.resources)
        
        # execute all rhs passing FunctionEnv
        # theEnv could be modified from the function call.
        # This THE way to share memory between functions
        
        for action in self._rhs:
            assert isinstance(action, types.FunctionCall)
            
            # get the function definition linked to the FunctionCall
            #funcDefinition = action.funcDefinition
            
            #assert isinstance(funcDefinition, FunctionDefinition)
            # expand the args 
            #funcDefinition.linkedType.__class__.execute(funcDefinition.linkedType, theEnv, *(action.funcArgs))
            
            Function.doExecute(action, theEnv)
Пример #2
0
        except Exception, e:
            print >> theEnv.RESOURCES['werror'], theEnv.network.getParser(
            ).ExceptionPPrint(e, aString)
            os.chdir(oldcwd)
            return types.Symbol('FALSE')
        else:
            cString = ""
            for p in parsed:
                if isinstance(p, types.DefRuleConstruct):
                    theEnv.network.addRule(p)

                elif isinstance(p, types.DefFactsConstruct):
                    theEnv.network.addDeffacts(p)

                elif isinstance(p, types.FunctionCall):
                    theResult = Function.doExecute(p, theEnv)

                    if not isinstance(theResult, types.NullValue):
                        print >> theEnv.RESOURCES['wtrace'], str(theResult)

            os.chdir(oldcwd)
            return types.Symbol('TRUE')


Batch.DEFINITION = FunctionDefinition("?SYSTEM?",
                                      "batch",
                                      Batch(),
                                      types.Symbol,
                                      Batch.do, [
                                          Constraint_ExactArgsLength(1),
                                          Constraint_ArgType(
Пример #3
0
         # add the new rule to the network
         self._network.addRule(parsed)
         
     elif isinstance(parsed, types.DefFactsConstruct):
         # add the deffacts
         self._network.addDeffacts(parsed)
         
     elif isinstance(parsed, types.FunctionCall):
         # execute the function
         assert isinstance(parsed, types.FunctionCall)
         
         # prepare the FunctionEnv object    
         theEnv = FunctionEnv({}, self._network, self._network.modulesManager, self._network.resources)
         #funcDefinition = parsed.funcDefinition
         #theResult = funcDefinition.linkedType.__class__.execute(funcDefinition.linkedType, theEnv, *(parsed.funcArgs))
         # replace old function bootstrap method with a faster one
         theResult = Function.doExecute(parsed, theEnv)
         
         if not isinstance(theResult, types.NullValue):
             return theResult
     
     elif isinstance(parsed, types.GlobalVariable):
         # resolve the global value
         
         return self._network.modulesManager.currentScope.globalsvars.getDefinition(parsed.evaluate()).linkedType.runningValue
         
     elif isinstance(parsed, types.BaseParsedType):
         
         return parsed
 
 
Пример #4
0
            parsed = theEnv.network.getParser().parse(aString, extended=True)
        except Exception, e:
            print >> theEnv.RESOURCES['werror'], theEnv.network.getParser().ExceptionPPrint(e, aString)
            os.chdir(oldcwd)
            return types.Symbol('FALSE')
        else:
            cString = ""
            for p in parsed:
                if isinstance(p, types.DefRuleConstruct):
                    theEnv.network.addRule(p)
                    
                elif isinstance(p, types.DefFactsConstruct):
                    theEnv.network.addDeffacts(p)
                    
                elif isinstance(p, types.FunctionCall):
                    theResult = Function.doExecute(p, theEnv)
                    
                    if not isinstance(theResult, types.NullValue):
                        print >> theEnv.RESOURCES['wtrace'], str(theResult)
                                            
            os.chdir(oldcwd)
            return types.Symbol('TRUE')
    
    
Batch.DEFINITION = FunctionDefinition("?SYSTEM?", "batch", Batch(), types.Symbol, Batch.do ,
            [
                Constraint_ExactArgsLength(1),
                Constraint_ArgType((types.Symbol, types.String), 0)
            ],forward=False)
        
        
Пример #5
0
            elif isinstance(parsed, types.DefFactsConstruct):
                # add the deffacts
                self._network.addDeffacts(parsed)

            elif isinstance(parsed, types.FunctionCall):
                # execute the function
                assert isinstance(parsed, types.FunctionCall)

                # prepare the FunctionEnv object
                theEnv = FunctionEnv({}, self._network,
                                     self._network.modulesManager,
                                     self._network.resources)
                #funcDefinition = parsed.funcDefinition
                #theResult = funcDefinition.linkedType.__class__.execute(funcDefinition.linkedType, theEnv, *(parsed.funcArgs))
                # replace old function bootstrap method with a faster one
                theResult = Function.doExecute(parsed, theEnv)

                if not isinstance(theResult, types.NullValue):
                    return theResult

            elif isinstance(parsed, types.GlobalVariable):
                # resolve the global value

                return self._network.modulesManager.currentScope.globalsvars.getDefinition(
                    parsed.evaluate()).linkedType.runningValue

            elif isinstance(parsed, types.BaseParsedType):

                return parsed