EvalProgramNaive evaluates a given program on the given facts, modifying the fact store in the process.
(program []ast.Clause, store factstore.SimpleInMemoryStore)
| 35 | |
| 36 | // EvalProgramNaive evaluates a given program on the given facts, modifying the fact store in the process. |
| 37 | func EvalProgramNaive(program []ast.Clause, store factstore.SimpleInMemoryStore) error { |
| 38 | preds := store.ListPredicates() |
| 39 | knownPredicates := make(map[ast.PredicateSym]ast.Decl, len(preds)) |
| 40 | for _, sym := range preds { |
| 41 | knownPredicates[sym] = ast.NewSyntheticDeclFromSym(sym) |
| 42 | } |
| 43 | programInfo, err := analysis.AnalyzeOneUnit(parse.SourceUnit{Clauses: program}, knownPredicates) |
| 44 | if err != nil { |
| 45 | return fmt.Errorf("analysis: %w", err) |
| 46 | } |
| 47 | strata, predToStratum, err := analysis.Stratify(analysis.Program{ |
| 48 | EdbPredicates: programInfo.EdbPredicates, |
| 49 | IdbPredicates: programInfo.IdbPredicates, |
| 50 | Rules: programInfo.Rules, |
| 51 | }) |
| 52 | if err != nil { |
| 53 | return fmt.Errorf("stratification: %w", err) |
| 54 | } |
| 55 | naiveEngine{store, *programInfo, strata, predToStratum}.evalStrata() |
| 56 | return nil |
| 57 | } |
| 58 | |
| 59 | func (e naiveEngine) evalStrata() { |
| 60 | for _, fact := range e.programInfo.InitialFacts { |