Skip to content

Commit

Permalink
manual, code example preprocessor : full conversion to compiler-libs (#…
Browse files Browse the repository at this point in the history
…1863)

* manual tools: use toploop directly in caml_tex2
* manual tool: improved error messages
* manual: always print errors and warnings
* fix nefarious interaction with GPR#1120
* move manual/tools/caml_tex2 to tools/caml_tex
* Basic text for caml-tex
  • Loading branch information
Octachron committed Jul 25, 2018
1 parent cc2b15e commit 4be6caf
Show file tree
Hide file tree
Showing 14 changed files with 373 additions and 164 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ _ocamltestd
/tools/stripdebug.opt
/tools/make_opcodes
/tools/make_opcodes.ml
/tools/caml-tex

/utils/config.ml

Expand Down
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ Working version
- GPR#1831: move the local exceptions and exception cases to the main chapters.
(Florian Angeletti, review by Perry E. Metzger and Jeremy Yallop)

- GPR#1863: caml-tex2, move to compiler-libs
(Florian Angeletti, review by Sébastien Hinderer and Gabriel Scherer)

### Compiler distribution build system:

- GPR#1776: add -no-install-bytecode-programs and related configure options to
Expand Down
6 changes: 3 additions & 3 deletions manual/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Latex extensions

### Caml environments

The tool `tools/caml-tex2` is used to generate the latex code for the examples
The tool `tools/caml-tex` is used to generate the latex code for the examples
in the introduction and language extension parts of the manual. It implements
two pseudo-environments: `caml_example` and `caml_eval`.

Expand Down Expand Up @@ -145,10 +145,10 @@ otherwise an error would be raised.
The `verbatim` does not require a final `;;` and is intended to be
a lighter mode for code examples.

By default, `caml_tex2` raises an error and stops if the output of one
By default, `caml-tex` raises an error and stops if the output of one
the `caml_example` environment contains an unexpected error or warning.
If such an error or warning is, in fact, expected, it is necessary to
indicate the expected output status to `caml_tex2` by adding either
indicate the expected output status to `caml-tex` by adding either
an option to the `caml_example` environment:
```latex
\begin{caml_example}{toplevel}[error]
Expand Down
5 changes: 2 additions & 3 deletions manual/manual/cmds/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ LD_PATH = "$(TOPDIR)/otherlibs/str:$(TOPDIR)/otherlibs/unix"

TOOLS = ../../tools
CAMLLATEX = $(SET_LD_PATH) \
$(OCAMLRUN) $(TOOLS)/caml-tex2 \
-caml "TERM=norepeat $(OCAML)" -n 80 -v false
$(OCAMLRUN) $(TOPDIR)/tools/caml-tex \
-repo-root $(TOPDIR) -n 80 -v false
TEXQUOTE = $(OCAMLRUN) $(TOOLS)/texquote2
TRANSF = $(SET_LD_PATH) $(OCAMLRUN) $(TOOLS)/transf


FILES = comp.tex top.tex runtime.tex native.tex lexyacc.tex intf-c.tex \
depend.tex profil.tex debugger.tex browser.tex ocamldoc.tex \
warnings-help.tex ocamlbuild.tex flambda.tex spacetime.tex \
Expand Down
4 changes: 2 additions & 2 deletions manual/manual/refman/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ LD_PATH = "$(TOPDIR)/otherlibs/str:$(TOPDIR)/otherlibs/unix"

TOOLS = ../../tools
CAMLLATEX = $(SET_LD_PATH) \
$(OCAMLRUN) $(TOOLS)/caml-tex2 \
-caml "TERM=norepeat $(OCAML)" -n 80 -v false
$(OCAMLRUN) $(TOPDIR)/tools/caml-tex \
-repo-root $(TOPDIR) -n 80 -v false
TEXQUOTE = $(OCAMLRUN) $(TOOLS)/texquote2
TRANSF = $(SET_LD_PATH) $(OCAMLRUN) $(TOOLS)/transf

Expand Down
4 changes: 2 additions & 2 deletions manual/manual/tutorials/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ LD_PATH = "$(TOPDIR)/otherlibs/str:$(TOPDIR)/otherlibs/unix"

TOOLS = ../../tools
CAMLLATEX = $(SET_LD_PATH) \
$(OCAMLRUN) $(TOOLS)/caml-tex2 \
-caml "TERM=norepeat $(OCAML)" -n 80 -v false
$(OCAMLRUN) $(TOPDIR)/tools/caml-tex \
-repo-root $(TOPDIR) -n 80 -v false
TEXQUOTE = $(OCAMLRUN) $(TOOLS)/texquote2
TRANSF = $(SET_LD_PATH) $(OCAMLRUN) $(TOOLS)/transf

Expand Down
2 changes: 1 addition & 1 deletion manual/manual/tutorials/objectexamples.etex
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ The following idiom separates description and definition.
\begin{caml_example*}{toplevel}
class type ['a] iterator =
object method fold : ('b -> 'a -> 'b) -> 'b -> 'b end;;
class intlist l =
class intlist' l =
object (self : int #iterator)
method empty = (l = [])
method fold f accu = List.fold_left f accu l
Expand Down
1 change: 0 additions & 1 deletion manual/tools/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ htmlgen
htmlquote
latexscan.ml
dvi2txt
caml-tex2
*.dSYM
*.cm[io]
*.o
10 changes: 2 additions & 8 deletions manual/tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,17 @@ TOPDIR=../..
COMPFLAGS=-I $(OTOPDIR)/otherlibs/str -I $(OTOPDIR)/otherlibs/unix
include $(TOPDIR)/Makefile.tools

all: texquote2 transf caml-tex2
all: texquote2 transf


transf: transf.cmo htmltransf.cmo transfmain.cmo
$(OCAMLC) -o $@ -g $^

transfmain.cmo: transf.cmo htmltransf.cmo


caml-tex2: caml_tex2.ml
$(OCAMLC) $(TOPDIR)/compilerlibs/ocamlcommon.cma -I $(TOPDIR)/parsing \
-o $@ str.cma unix.cma $<

texquote2: texquote2.ml
$(OCAMLC) -o $@ $<


%.cmo: %.ml
$(OCAMLC) -c $<

Expand All @@ -33,4 +27,4 @@ texquote2: texquote2.ml
clean:
rm -f *.o *.cm? *.cmx?
rm -f transf.ml htmltransf.ml
rm -f texquote2 transf caml-tex2
rm -f texquote2 transf
1 change: 1 addition & 0 deletions testsuite/tests/tool-caml-tex/ocamltests
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
redirections.ml
19 changes: 19 additions & 0 deletions testsuite/tests/tool-caml-tex/redirections.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
(* TEST
reference="${test_source_directory}/redirections.reference"
output="redirections.output"
script = "${ocamlrun} ${ocamlsrcdir}/tools/caml-tex \
-repo-root ${ocamlsrcdir} ${test_source_directory}/${test_file} -o ${output}"
* script with unix,str
** check-program-output
*)

\begin{caml_example}{toplevel}
[@@@warning "+A"];;
1 + 2. [@@expect error];;
let f x = () [@@expect warning 27];;
\end{caml_example}

\begin{caml_example}{toplevel}
Format.printf "Hello@.";
print_endline "world";;
\end{caml_example}
30 changes: 30 additions & 0 deletions testsuite/tests/tool-caml-tex/redirections.reference
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
(* TEST
reference="${test_source_directory}/redirections.reference"
output="redirections.output"
script = "${ocamlrun} ${ocamlsrcdir}/tools/caml-tex \
-repo-root ${ocamlsrcdir} ${test_source_directory}/${test_file} -o ${output}"
* script with unix,str
** check-program-output
*)

\camlexample{toplevel}
\caml\camlinput\?[@@@warning "+A"];;
\endcamlinput\endcaml
\caml\camlinput\?1 + \<2.\> ;;
\endcamlinput\camlerror\:Error: This expression has type float but an expression was expected of type
\: int
\endcamlerror\endcaml
\caml\camlinput\?let f \<x\> = () ;;
\endcamlinput\camlwarn\:Warning 27: unused variable x.
\:val f : \textquotesingle\-a -> unit = <fun>
\endcamlwarn\endcaml
\endcamlexample

\camlexample{toplevel}
\caml\camlinput\?Format.printf "Hello@.";
\?print_endline "world";;
\endcamlinput\camloutput\:Hello
\:world
\:- : unit = ()
\endcamloutput\endcaml
\endcamlexample
20 changes: 20 additions & 0 deletions tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,26 @@ install::
"$(INSTALL_BINDIR)/"
endif

CAMLTEX= ../compilerlibs/ocamlcommon.cma \
../compilerlibs/ocamlbytecomp.cma \
../compilerlibs/ocamltoplevel.cma \
../otherlibs/str/str.cma \
../otherlibs/$(UNIXLIB)/unix.cma \
caml_tex.ml

#Scan latex files, and run ocaml code examples

caml-tex: INCLUDES+= -I ../otherlibs/str -I ../otherlibs/$(UNIXLIB)
caml-tex: $(CAMLTEX)
../runtime/ocamlrun ../ocamlc -nostdlib -I ../stdlib $(LINKFLAGS) \
-linkall -o $@ $(CAMLTEX)

# we need str and unix which depend on the bytecode version of other tools
# thus we delay building caml-tex to the opt.opt stage
opt.opt:caml-tex
clean::
rm -f -- caml-tex caml_tex.cm?

# Common stuff

.SUFFIXES:
Expand Down
Loading

0 comments on commit 4be6caf

Please sign in to comment.