Skip to content

Commit

Permalink
build with dune
Browse files Browse the repository at this point in the history
  • Loading branch information
leque committed Jun 21, 2018
1 parent d7838dc commit 08b3eda
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 102 deletions.
8 changes: 2 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ obsolete/*.txt
bin/
old/
test/
lexer.ml
parser.ml
parser.mli
parser.output
lexer_hand.ml
*.png
_build/
temp/
Expand All @@ -40,4 +35,5 @@ satysfi
*.jpg
*.satysfi-aux
external/
*_.ml
*.install
*.gen.ml
87 changes: 36 additions & 51 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,52 @@ BACKEND=src/backend
FRONTEND=src/frontend
CHARDECODER=src/chardecoder
BYTECOMP=$(FRONTEND)/bytecomp
OCB_FLAGS = -cflags -w,-3 \
-use-ocamlfind -use-menhir \
-I $(SRCROOT)/ -I $(FRONTEND)/ -I $(BACKEND)/ -I $(CHARDECODER)/ -I $(BYTECOMP) \
-pkgs "str,ppx_deriving.show,core_kernel,uutf,batteries, \
menhirLib,yojson,camlimages,camlimages.jpeg,otfm,camlpdf" \
-tag bin_annot -tag thread -tag unsafe_string -yaccflags "--table --explain"
TARGET=satysfi
OCB = ocamlbuild $(OCB_FLAGS)
BINDIR=$(PREFIX)/bin
RM=rm -f
RUBY=ruby
GENCODE=./gen_code.rb
DUNE=jbuilder
INSTDEF=$(BYTECOMP)/vminstdef.yaml
INSTTYPE_GEN=$(FRONTEND)/__insttype.gen.ml
ATTYPE_GEN=$(FRONTEND)/__attype.gen.ml
VM_GEN=$(BYTECOMP)/__vm.gen.ml
IR_GEN=$(BYTECOMP)/__ir.gen.ml
EVAL_GEN=$(FRONTEND)/__evaluator.gen.ml
PRIM_GEN=$(FRONTEND)/__primitives.gen.ml
GENS= \
$(INSTTYPE_GEN) \
$(ATTYPE_GEN) \
$(VM_GEN) \
$(IR_GEN) \
$(EVAL_GEN) \
$(PRIM_GEN)

all: $(FRONTEND)/types_.ml $(FRONTEND)/evaluator_.ml $(FRONTEND)/primitives_.ml $(BYTECOMP)/vm_.ml $(BYTECOMP)/ir_.ml
mkdir -p _build/
$(OCB) main.native
mv main.native $(TARGET)
.PHONY: all gen install lib uninstall clean

$(FRONTEND)/types_.ml: $(FRONTEND)/types_template.ml $(INSTDEF) $(GENCODE)
$(RUBY) $(GENCODE) --gen-insttype $(INSTDEF) > $(FRONTEND)/__insttype.ml
$(RUBY) $(GENCODE) --gen-attype $(INSTDEF) > $(FRONTEND)/__attype.ml
$(RUBY) $(GENCODE) --pp-include $(FRONTEND)/types_template.ml > $(FRONTEND)/types_.ml
$(RM) $(FRONTEND)/__insttype.ml
$(RM) $(FRONTEND)/__attype.ml
all: gen
$(DUNE) build
cp _build/install/default/bin/$(TARGET) .

$(BYTECOMP)/vm_.ml: $(BYTECOMP)/vm_template.ml $(INSTDEF) $(GENCODE)
$(RUBY) $(GENCODE) --gen-vm $(INSTDEF) > $(BYTECOMP)/__vm.ml
$(RUBY) $(GENCODE) --pp-include $(BYTECOMP)/vm_template.ml > $(BYTECOMP)/vm_.ml
$(RM) $(BYTECOMP)/__vm.ml
gen: $(GENS)

$(BYTECOMP)/ir_.ml: $(BYTECOMP)/ir_template.ml $(INSTDEF) $(GENCODE)
$(RUBY) $(GENCODE) --gen-ir $(INSTDEF) > $(BYTECOMP)/__ir.ml
$(RUBY) $(GENCODE) --pp-include $(BYTECOMP)/ir_template.ml > $(BYTECOMP)/ir_.ml
$(RM) $(BYTECOMP)/__ir.ml
$(ATTYPE_GEN): $(INSTDEF) $(GENCODE)
$(RUBY) $(GENCODE) --gen-attype $(INSTDEF) > $@

$(FRONTEND)/evaluator_.ml: $(FRONTEND)/evaluator_template.ml $(INSTDEF) $(GENCODE)
$(RUBY) $(GENCODE) --gen-interps $(INSTDEF) > $(FRONTEND)/__evaluator.ml
$(RUBY) $(GENCODE) --pp-include $(FRONTEND)/evaluator_template.ml > $(FRONTEND)/evaluator_.ml
$(RM) $(FRONTEND)/__evaluator.ml
$(INSTTYPE_GEN): $(INSTDEF) $(GENCODE)
$(RUBY) $(GENCODE) --gen-insttype $(INSTDEF) > $@

$(FRONTEND)/primitives_.ml: $(FRONTEND)/primitives_template.ml $(INSTDEF) $(GENCODE)
$(RUBY) $(GENCODE) --gen-prims $(INSTDEF) > $(FRONTEND)/__primitives.ml
$(RUBY) $(GENCODE) --pp-include $(FRONTEND)/primitives_template.ml > $(FRONTEND)/primitives_.ml
$(RM) $(FRONTEND)/__primitives.ml
$(VM_GEN): $(INSTDEF) $(GENCODE)
$(RUBY) $(GENCODE) --gen-vm $(INSTDEF) > $@

$(IR_GEN): $(INSTDEF) $(GENCODE)
$(RUBY) $(GENCODE) --gen-ir $(INSTDEF) > $@

$(EVAL_GEN): $(INSTDEF) $(GENCODE)
$(RUBY) $(GENCODE) --gen-interps $(INSTDEF) > $@

$(PRIM_GEN): $(INSTDEF) $(GENCODE)
$(RUBY) $(GENCODE) --gen-prims $(INSTDEF) > $@

install: $(TARGET)
mkdir -p $(BINDIR)
Expand Down Expand Up @@ -89,21 +90,5 @@ uninstall:
rm -rf $(LIBDIR)

clean:
$(OCB) -clean
$(RM) $(FRONTEND)/types_.ml
$(RM) $(FRONTEND)/primitives_.ml
$(RM) $(FRONTEND)/evaluator_.ml
$(RM) $(BYTECOMP)/vm_.ml
$(RM) $(BYTECOMP)/ir_.ml
$(RM) $(FRONTEND)/__insttype.ml
$(RM) $(FRONTEND)/__attype.ml
$(RM) $(FRONTEND)/__primitives.ml
$(RM) $(FRONTEND)/__evaluator.ml
$(RM) $(BYTECOMP)/__vm.ml
$(RM) $(BYTECOMP)/__ir.ml


#clean-sub:
# rm -f $(FRONTEND)/lexer.ml $(FRONTEND)/parser.mli $(FRONTEND)/parser.ml $(FRONTEND)/*.cmi $(FRONTEND)/*.cmx $(FRONTEND)/*.o
#
.PHONY: clean
$(DUNE) clean
$(RM) $(GENS)
37 changes: 0 additions & 37 deletions gen_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,42 +201,6 @@ def gen_ircases
end
end

def pp_include
srcpath = Pathname.new(ARGV[0])

puts "(***********************************************************)"
puts "(* *)"
puts "(* *)"
puts "(* *)"
puts "(* AUTO-GENERATED FILE *)"
puts "(* DO NOT MODIFY *)"
puts "(* *)"
puts "(* *)"
puts "(* *)"
puts "(***********************************************************)"

ARGF.each_line do |line|
match = line.match(/\(\*\*\*\*.*include *: *(.*) *\*\*\*\*\)/)
if match then
inspath = Pathname.new(match[1].strip)
if inspath.absolute? then
openpath = inspath
else
openpath = srcpath.dirname.join(inspath.basename)
end

File.open(openpath) do |file|
file.each_line do |line|
puts line
end
end
else
puts line
end
end
end


opt = OptionParser.new

func = nil
Expand All @@ -247,7 +211,6 @@ def pp_include
opt.on('--gen-attype') {|v| func = method(:gen_attype) }
opt.on('--gen-interps') {|v| func = method(:gen_interps) }
opt.on('--gen-prims') {|v| func = method(:gen_prims) }
opt.on('--pp-include') {|v| func = method(:pp_include) }

opt.parse!(ARGV)

Expand Down
5 changes: 4 additions & 1 deletion opam → satysfi.opam
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
opam-version: "1.2"
name: "satysfi"
version: ""
maintainer: "gfngfn"
authors: [
"gfngfn"
Expand All @@ -23,9 +25,10 @@ depends: [
"camlimages" {>= "5.0.1"}
"camlpdf" {= "2.2.1+satysfi"}
"core_kernel" {>= "v0.10.0"}
"cppo" {build & >= "1.6.4" & < "1.7.0"}
"depext"
"jbuilder" {build}
"menhir"
"ocamlbuild" {build}
"ocamlfind" {build}
"otfm" {= "0.3.0+satysfi"}
"ppx_deriving"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,4 +454,4 @@ and transform (env : frame) ast : (ir * frame) =
let (iraft, env) = transform env astaft in
(IRModule(irmdl, iraft), env)

(**** include: __ir.ml ****)
#include "__ir.gen.ml"
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,4 @@ and exec (stack : syntactic_value list) (env : vmenv) (code : instruction list)
| c :: code ->
(*Format.printf "\nexec ---> %a\n" pp_instruction c;*)
match c with
(**** include: __vm.ml ****)
#include "__vm.gen.ml"
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ and interpret env ast =
let (pathelemlst, closingopt) = interpret_path env pathcomplst cycleopt in
PathValue([GeneralPath(pt0, pathelemlst, closingopt)])

(**** include: __evaluator.ml ****)
#include "__evaluator.gen.ml"


and interpret_intermediate_input_vert env (valuectx : syntactic_value) (imivlst : intermediate_input_vert_element list) : syntactic_value =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ let make_environments () =
( ">=" , ~% (tI @-> tI @-> tB) , lambda2 (fun v1 v2 -> LogicalNot(LessThan(v1, v2))) );
( "<=" , ~% (tI @-> tI @-> tB) , lambda2 (fun v1 v2 -> LogicalNot(GreaterThan(v1, v2))) );

(**** include: __primitives.ml ****)
#include "__primitives.gen.ml"

]
in
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -544,8 +544,7 @@ and ir_pattern_tree =
| IRPVariable of varloc
| IRPAsVariable of varloc * ir_pattern_tree
| IRPConstructor of constructor_name * ir_pattern_tree

(**** include: __insttype.ml ****)
#include "__insttype.gen.ml"

and input_horz_element =
| InputHorzText of string
Expand Down Expand Up @@ -662,7 +661,7 @@ and abstract_tree =
| LambdaHorz of EvalVarID.t * abstract_tree
| LambdaVert of EvalVarID.t * abstract_tree
| PrimitiveTupleCons of abstract_tree * abstract_tree
(**** include: __attype.ml ****)
#include "__attype.gen.ml"

and pattern_branch =
| PatternBranch of pattern_tree * abstract_tree
Expand Down
59 changes: 59 additions & 0 deletions src/jbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
;;; -*- mode: lisp -*-
(executable
((name main)
(public_name satysfi)
(flags (-w -3 -bin-annot -thread -unsafe-string))
(libraries (str
batteries
camlimages
camlimages.jpeg
camlpdf
core_kernel
menhirLib
otfm
uutf
yojson
))
(preprocess (pps (ppx_deriving.show)))
))

;; dune requires all the .ml/.mli files to be in the same directory as the jbuild.
;; https://github.com/ocaml/dune/issues/109
(copy_files# backend/*.{ml,mli})
(copy_files# chardecoder/*.{ml,mli})
(copy_files chardecoder/*.{mll,mly})
(copy_files# frontend/*.{ml,mli})
(copy_files frontend/*.{mll,mly})
(copy_files# frontend/bytecomp/*.{ml,mli})

(ocamllex
(lexer dataLexer))

(menhir
((modules (parser dataParser))
(flags (--table --explain))))

(rule
((targets (types_.ml))
(deps (types_.cppo.ml __insttype.gen.ml __attype.gen.ml))
(action (run ${bin:cppo} ${<} -o ${@}))))

(rule
((targets (vm_.ml))
(deps (vm_.cppo.ml __vm.gen.ml))
(action (run ${bin:cppo} ${<} -o ${@}))))

(rule
((targets (ir_.ml))
(deps (ir_.cppo.ml __ir.gen.ml))
(action (run ${bin:cppo} ${<} -o ${@}))))

(rule
((targets (evaluator_.ml))
(deps (evaluator_.cppo.ml __evaluator.gen.ml))
(action (run ${bin:cppo} ${<} -o ${@}))))

(rule
((targets (primitives_.ml))
(deps (primitives_.cppo.ml __primitives.gen.ml))
(action (run ${bin:cppo} ${<} -o ${@}))))

0 comments on commit 08b3eda

Please sign in to comment.