Skip to content

Commit

Permalink
switched to oasis for build;
Browse files Browse the repository at this point in the history
renamed the bottom up implementation (the first one) to BottomUp;
separate Version file for the version;
separate Default module that packs BottomUp with string constants
  • Loading branch information
c-cube committed Oct 19, 2013
1 parent 0ae5ab5 commit 2434442
Show file tree
Hide file tree
Showing 21 changed files with 6,714 additions and 209 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ datalog/const.ml
*.docdir
.session
TAGS
version.ml
setup.log
setup.data
14 changes: 10 additions & 4 deletions META
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
name="datalog"
version="0.4.1"
description="Simple Datalog fixpoint computation library"
requires=""
# OASIS_START
# DO NOT EDIT (digest: 73f514313ec20c594d2d4fbcfc0e2cdf)
version = "0.4.2"
description = "An in-memory datalog implementation for OCaml"
requires = "unix num str"
archive(byte) = "datalog.cma"
archive(byte, plugin) = "datalog.cma"
archive(native) = "datalog.cmxa"
archive(native, plugin) = "datalog.cmxs"
exists_if = "datalog.cma"
# OASIS_STOP

57 changes: 29 additions & 28 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,45 +1,46 @@
# where to install the command line?
BINDIR ?= /usr/bin/
# OASIS_START
# DO NOT EDIT (digest: bc1e05bfc8b39b664f29dae8dbd3ebbb)

# name of the library
NAME = datalog
SETUP = ocaml setup.ml

CLI = datalog_cli.native topDownCli.native
LIB = datalog.cmxa datalog.cma
DOC = datalog.docdir/index.html
TARGETS = $(DOC) $(LIB) $(CLI)
build: setup.data
$(SETUP) -build $(BUILDFLAGS)

INSTALL_LIB = datalog.cmxa datalog.cma datalog.a datalog.cmi datalog.mli
doc: setup.data build
$(SETUP) -doc $(DOCFLAGS)

# compilation options
OPTIONS ?= -classic-display
test: setup.data build
$(SETUP) -test $(TESTFLAGS)

%.ml: %.mlp
sed -e "s/DATALOG_VERSION/$(VERSION)/g" \
$< > $@
all:
$(SETUP) -all $(ALLFLAGS)

all: prod
install: setup.data
$(SETUP) -install $(INSTALLFLAGS)

prod:
ocamlbuild $(OPTIONS) -tag noassert $(TARGETS)
uninstall: setup.data
$(SETUP) -uninstall $(UNINSTALLFLAGS)

debug:
ocamlbuild $(OPTIONS) -tag debug $(TARGETS)
reinstall: setup.data
$(SETUP) -reinstall $(REINSTALLFLAGS)

profile:
ocamlbuild $(OPTIONS) -tag profile $(TARGETS)
clean:
$(SETUP) -clean $(CLEANFLAGS)

clean:
ocamlbuild -clean
distclean:
$(SETUP) -distclean $(DISTCLEANFLAGS)

setup.data:
$(SETUP) -configure $(CONFIGUREFLAGS)

.PHONY: build doc test all install uninstall reinstall clean distclean configure

# OASIS_STOP

push_doc: prod
scp -r datalog.docdir/* cedeela.fr:~/simon/root/software/datalog/

install: prod
ocamlfind install $(NAME) META $(addprefix _build/,$(INSTALL_LIB))
cp _build/$(CLI) $(BINDIR)/datalog_cli

tags:
otags *.ml *.mli

.PHONY: all clean install tags push_doc
.PHONY: tags push_doc
57 changes: 57 additions & 0 deletions _oasis
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
OASISFormat: 0.3
Name: datalog
Version: 0.4.2
Homepage: https://github.com/c-cube/datalog
Authors: Simon Cruanes
License: BSD3
LicenseFile: LICENSE
Plugins: META (0.3), DevFiles (0.3)
OCamlVersion: >= 4.00.1
BuildTools: ocamlbuild
FilesAB: version.ml.ab

Synopsis: An in-memory datalog implementation for OCaml

Description:
An in-memory datalog implementation for OCaml. It focuses on big sets of rules
with small relations, with frequent updates of the relations. Therefore, it
tries to achieve good behavior in presence of incremental modifications of the
relations.

Library "datalog"
Path: .
Pack: true
Modules: BottomUp, TopDown, Default, BottomUpAst, BottomUpParser,
BottomUpLexer, TopDownParser, TopDownLexer, TopDownAst,
Version
BuildDepends: unix,num,str

Document datalog
Title: documentation for Datalog
Type: ocamlbuild (0.3)
BuildTools+: ocamldoc
Install: true
XOCamlbuildPath: .
XOCamlbuildLibraries: datalog

# CLI client using BottomUp
Executable datalog_cli
Path: .
Install: true
CompiledObject: native
MainIs: datalog_cli.ml
BuildDepends: datalog

# CLI client using TopDown
Executable topDownCli
Path: .
Install: false
CompiledObject: native
MainIs: topDownCli.ml
BuildDepends: datalog

SourceRepository head
Type: git
Location: https://github.com/c-cube/datalog
Browser: https://github.com/c-cube/datalog/tree/master/src

42 changes: 42 additions & 0 deletions _tags
Original file line number Diff line number Diff line change
@@ -1,2 +1,44 @@
# OASIS_START
# DO NOT EDIT (digest: 727e0b43e5d8c6a2effb3ab294ecb18a)
# Ignore VCS directories, you can use the same kind of rule outside
# OASIS_START/STOP if you want to exclude directories that contains
# useless stuff for the build process
<**/.svn>: -traverse
<**/.svn>: not_hygienic
".bzr": -traverse
".bzr": not_hygienic
".hg": -traverse
".hg": not_hygienic
".git": -traverse
".git": not_hygienic
"_darcs": -traverse
"_darcs": not_hygienic
# Library datalog
"datalog.cmxs": use_datalog
"bottomUp.cmx": for-pack(Datalog)
"topDown.cmx": for-pack(Datalog)
"default.cmx": for-pack(Datalog)
"bottomUpAst.cmx": for-pack(Datalog)
"bottomUpParser.cmx": for-pack(Datalog)
"bottomUpLexer.cmx": for-pack(Datalog)
"topDownParser.cmx": for-pack(Datalog)
"topDownLexer.cmx": for-pack(Datalog)
"topDownAst.cmx": for-pack(Datalog)
"version.cmx": for-pack(Datalog)
# Executable datalog_cli
"datalog_cli.native": use_datalog
"datalog_cli.native": pkg_unix
"datalog_cli.native": pkg_num
"datalog_cli.native": pkg_str
# Executable topDownCli
"topDownCli.native": use_datalog
"topDownCli.native": pkg_unix
"topDownCli.native": pkg_num
"topDownCli.native": pkg_str
<*.ml{,i}>: use_datalog
<*.ml{,i}>: pkg_unix
<*.ml{,i}>: pkg_num
<*.ml{,i}>: pkg_str
# OASIS_STOP
<**/*.cmx>: inline(10)

76 changes: 0 additions & 76 deletions datalog.ml → bottomUp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1576,79 +1576,3 @@ module Hashcons(S : SymbolType) = struct
let y = W.merge __table x in
y
end

module Ast = DatalogAst
module Parser = DatalogParser
module Lexer = DatalogLexer

module StringSymbol = Hashcons(struct
type t = string
let equal a b = a = b
let hash x = Hashtbl.hash x
let to_string s = s
end)

(** Default literal base, where symbols are just strings *)
module Default = struct
include Make(StringSymbol)

type vartbl = {
mutable vartbl_count : int;
vartbl_tbl : (string,int) Hashtbl.t;
}

let mk_vartbl () =
{ vartbl_count = 0;
vartbl_tbl = Hashtbl.create 5;
}

let getvar ~tbl name =
try Hashtbl.find tbl.vartbl_tbl name
with Not_found ->
let n = tbl.vartbl_count in
Hashtbl.add tbl.vartbl_tbl name n;
tbl.vartbl_count <- n + 1;
n

let term_of_ast ~tbl ast = match ast with
| Ast.Const s
| Ast.Quoted s ->
mk_const (StringSymbol.make s)
| Ast.Var x ->
mk_var (getvar ~tbl x)

let literal_of_ast ?(tbl=mk_vartbl ()) lit = match lit with
| Ast.Atom (s, args) ->
let s = StringSymbol.make s in
let args = List.map (term_of_ast ~tbl) args in
mk_literal s args

let clause_of_ast c = match c with
| Ast.Clause (a, l) ->
let tbl = mk_vartbl () in
let a = literal_of_ast ~tbl a in
let l = List.map (literal_of_ast ~tbl) l in
mk_clause a l

let query_of_ast q = match q with
| Ast.Query (vars, lits, neg) ->
let tbl = mk_vartbl () in
let lits = List.map (literal_of_ast ~tbl) lits in
let neg = List.map (literal_of_ast ~tbl) neg in
let vars = Array.of_list vars in
let vars = Array.map
(fun t -> match term_of_ast ~tbl t with
| Var i -> i
| Const _ -> failwith "query_of_ast: expected variables")
vars
in
vars, lits, neg
end

module TopDown = TopDown

module TopDownAst = TopDownAst
module TopDownLexer = TopDownLexer
module TopDownParser = TopDownParser

let version = "0.5.0"
77 changes: 0 additions & 77 deletions datalog.mli → bottomUp.mli
Original file line number Diff line number Diff line change
Expand Up @@ -289,80 +289,3 @@ end
can be useful. *)
module Make(Symbol : SymbolType) : S with type symbol = Symbol.t

(** {2 AST for Datalog files} *)

module Ast : sig
type file = clause list
(** Toplevel statement *)
and clause =
| Clause of literal * literal list
and literal =
| Atom of string * term list
and term =
| Var of string
| Const of string
| Quoted of string
and query =
| Query of term list * literal list * literal list
(** Query: projection, positive lits, negative lits *)
end

(** {2 Parser for Datalog files} *)

(** The syntax is a subset of prolog. *)
module Parser : sig
type token
val parse_literal :
(Lexing.lexbuf -> token) -> Lexing.lexbuf -> Ast.literal
val parse_literals :
(Lexing.lexbuf -> token) -> Lexing.lexbuf -> Ast.literal list
val parse_clause :
(Lexing.lexbuf -> token) -> Lexing.lexbuf -> Ast.clause
val parse_file :
(Lexing.lexbuf -> token) -> Lexing.lexbuf -> Ast.file
val parse_query :
(Lexing.lexbuf -> token) -> Lexing.lexbuf -> Ast.query
end

(** {2 Lexer for parsing Datalog files} *)

module Lexer : sig
val token : Lexing.lexbuf -> Parser.token

val print_location : Lexing.lexbuf -> string
end

(** {2 Default symbols: hashconsed strings} *)

module StringSymbol : SymbolType with type t = string

(** {2 Default implementation} *)

(** This is a ready-to-use instance of {!Make}, with hashconsed strings
as symbols. It also features some handy conversion functions from {! Ast}.
*)
module Default : sig
include S with type symbol = string

type vartbl = {
mutable vartbl_count : int;
vartbl_tbl : (string,int) Hashtbl.t;
}

val mk_vartbl : unit -> vartbl

val literal_of_ast : ?tbl:vartbl -> Ast.literal -> literal

val clause_of_ast : Ast.clause -> clause

val query_of_ast : Ast.query -> (int array * literal list * literal list)
end

module TopDown : module type of TopDown

module TopDownAst : module type of TopDownAst
module TopDownLexer : module type of TopDownLexer
module TopDownParser : module type of TopDownParser

val version : string
(** Version of the library *)
File renamed without changes.
Loading

0 comments on commit 2434442

Please sign in to comment.