package forester

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file Datalog_engine.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
(*
 * SPDX-FileCopyrightText: 2024 The Forester Project Contributors
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 *)

module V = struct
  include Vertex
  let to_string = show
end

module S = Datalog.BottomUp.Hashcons(V)

open struct
  module T = Types
  module D = Datalog.BottomUp.Make(S)
end

type relation = string
type vertex = Vertex.t
type term = D.term
type literal = D.literal
type clause = D.clause
type var = int

let symbol_of_string str : D.symbol =
  let vtx = T.Content_vertex (T.Content [T.Text str]) in
  S.make vtx

let pack_vertex vtx : D.symbol = S.make vtx

let var_of_string = String.hash

let mk_var = D.mk_var
let mk_const vtx = D.mk_const (pack_vertex vtx)
let mk_literal rel = D.mk_literal (symbol_of_string rel)
let mk_clause = D.mk_clause

let vertex_of_term = function
  | D.Const x -> (x : S.t :> Vertex.t)
  | _ -> failwith "const_of_term: unexpected variable"

type db = D.db
let db_create = D.db_create
let db_add_fact db lit = D.db_add_fact db lit
let db_add db clause = D.db_add db clause

type answers = D.Query.set

let list_of_answers answers =
  List.map (Array.map vertex_of_term) @@
    D.Query.to_list answers

let ask = D.Query.ask
OCaml

Innovation. Community. Security.