pax_global_header00006660000000000000000000000064121255112000014477gustar00rootroot0000000000000052 comment=de1b35e8a280149fbc165464787b9ca44dc3d337 camlmix-1.3.1/000077500000000000000000000000001212551120000131335ustar00rootroot00000000000000camlmix-1.3.1/LICENSE000066400000000000000000000025661212551120000141510ustar00rootroot00000000000000Copyright (c) 2004, 2005 Martin Jambon All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. camlmix-1.3.1/Makefile000066400000000000000000000017471212551120000146040ustar00rootroot00000000000000# Type `make' for native code # Type `make byte' for byte code instead of native code VERSION = 1.3.1 export VERSION SOURCES = \ version.ml lexer.mli lexer.mll \ parser_directive.mly directive.ml main.ml RESULT = camlmix .PHONY: default native byte all opt install www version force clean veryclean default: native native: version nc byte: version bc ifndef PREFIX PREFIX := $(shell dirname `which ocaml`)/.. endif export PREFIX all: byte opt: native install: install -m 0755 $(addsuffix $(EXE), \ $(sort $(BCRESULT) $(NCRESULT))) $(PREFIX)/bin/ www: all test install archive version: contents='let version = "$(VERSION)"'; \ if test "`cat version.ml`" != "$$contents"; then \ echo "$$contents" > version.ml;\ fi .PHONY: examples examples: cd examples && $(MAKE) force: $(MAKE) clean $(MAKE) $(MAKE) archive TRASH = META.mlx.ml langmix.* camlmix.exe *~ clean:: cd examples && $(MAKE) clean LIBS = unix OCAMLMAKEFILE = OCamlMakefile include $(OCAMLMAKEFILE) camlmix-1.3.1/OCamlMakefile000066400000000000000000000644011212551120000155140ustar00rootroot00000000000000########################################################################### # OCamlMakefile # Copyright (C) 1999-2004 Markus Mottl # # For updates see: # http://www.oefai.at/~markus/ocaml_sources # # $Id: OCamlMakefile,v 1.52 2004/05/03 10:28:09 mottl Exp $ # ########################################################################### # Modified by damien for .glade.ml compilation # Set these variables to the names of the sources to be processed and # the result variable. Order matters during linkage! ifndef SOURCES SOURCES := foo.ml endif export SOURCES ifndef RES_CLIB_SUF RES_CLIB_SUF := _stubs endif export RES_CLIB_SUF ifndef RESULT RESULT := foo endif export RESULT ifndef DOC_FILES DOC_FILES := $(filter %.mli, $(SOURCES)) endif export DOC_FILES export BCSUFFIX export NCSUFFIX ifndef TOPSUFFIX TOPSUFFIX := .top endif export TOPSUFFIX # Eventually set include- and library-paths, libraries to link, # additional compilation-, link- and ocamlyacc-flags # Path- and library information needs not be written with "-I" and such... # Define THREADS if you need it, otherwise leave it unset (same for # USE_CAMLP4)! export THREADS export VMTHREADS export ANNOTATE export USE_CAMLP4 export INCDIRS export LIBDIRS export EXTLIBDIRS export RESULTDEPS export OCAML_DEFAULT_DIRS export LIBS export CLIBS export OCAMLFLAGS export OCAMLNCFLAGS export OCAMLBCFLAGS export OCAMLLDFLAGS export OCAMLNLDFLAGS export OCAMLBLDFLAGS ifndef OCAMLCPFLAGS OCAMLCPFLAGS := a endif export OCAMLCPFLAGS export PPFLAGS export YFLAGS export IDLFLAGS export OCAMLDOCFLAGS export DVIPSFLAGS export STATIC # Add a list of optional trash files that should be deleted by "make clean" export TRASH #################### variables depending on your OCaml-installation ifdef MINGW export MINGW WIN32 := 1 endif ifdef MSVC export MSVC WIN32 := 1 EXT_OBJ := obj EXT_LIB := lib ifeq ($(CC),gcc) # work around GNU Make default value ifdef THREADS CC := cl -MT else CC := cl endif endif ifeq ($(CXX),g++) # work around GNU Make default value CXX := $(CC) endif CFLAG_O := -Fo endif ifdef WIN32 EXT_CXX := cpp EXE := .exe endif ifndef EXT_OBJ EXT_OBJ := o endif ifndef EXT_LIB EXT_LIB := a endif ifndef EXT_CXX EXT_CXX := cc endif ifndef EXE EXE := # empty endif ifndef CFLAG_O CFLAG_O := -o # do not delete this comment (preserves trailing whitespace)! endif export CC export CXX export CFLAGS export CXXFLAGS export LDFLAGS ifndef RPATH_FLAG RPATH_FLAG := -R endif export RPATH_FLAG ifndef PIC_FLAGS PIC_FLAGS := -fPIC -DPIC endif export PIC_FLAGS BCRESULT := $(addsuffix $(BCSUFFIX), $(RESULT)) NCRESULT := $(addsuffix $(NCSUFFIX), $(RESULT)) TOPRESULT := $(addsuffix $(TOPSUFFIX), $(RESULT)) ifndef OCAMLFIND OCAMLFIND := ocamlfind endif export OCAMLFIND ifndef OCAMLC OCAMLC := ocamlc endif export OCAMLC ifndef OCAMLOPT OCAMLOPT := ocamlopt endif export OCAMLOPT ifndef OCAMLMKTOP OCAMLMKTOP := ocamlmktop endif export OCAMLMKTOP ifndef OCAMLCP OCAMLCP := ocamlcp endif export OCAMLCP ifndef OCAMLDEP OCAMLDEP := ocamldep endif export OCAMLDEP ifndef OCAMLLEX OCAMLLEX := ocamllex endif export OCAMLLEX ifndef OCAMLYACC OCAMLYACC := ocamlyacc endif export OCAMLYACC ifndef OCAMLMKLIB OCAMLMKLIB := ocamlmklib endif export OCAMLMKLIB ifndef OCAML_GLADECC OCAML_GLADECC := lablgladecc2 endif export OCAML_GLADECC ifndef OCAML_GLADECC_FLAGS OCAML_GLADECC_FLAGS := endif export OCAML_GLADECC_FLAGS ifndef CAMELEON_REPORT CAMELEON_REPORT := report endif export CAMELEON_REPORT ifndef CAMELEON_REPORT_FLAGS CAMELEON_REPORT_FLAGS := endif export CAMELEON_REPORT_FLAGS ifndef CAMELEON_ZOGGY CAMELEON_ZOGGY := camlp4o pa_zog.cma pr_o.cmo endif export CAMELEON_ZOGGY ifndef CAMELEON_ZOGGY_FLAGS CAMELEON_ZOGGY_FLAGS := endif export CAMELEON_ZOGGY_FLAGS ifndef CAMLIDL CAMLIDL := camlidl endif export CAMLIDL ifndef CAMLIDLDLL CAMLIDLDLL := camlidldll endif export CAMLIDLDLL ifndef NOIDLHEADER MAYBE_IDL_HEADER := -header endif export NOIDLHEADER export NO_CUSTOM ifndef CAMLP4 CAMLP4 := camlp4 endif export CAMLP4 ifdef PACKS empty := space := $(empty) $(empty) comma := , ifdef PREDS PRE_OCAML_FIND_PREDICATES := $(subst $(space),$(comma),$(PREDS)) PRE_OCAML_FIND_PACKAGES := $(subst $(space),$(comma),$(PACKS)) OCAML_FIND_PREDICATES := -predicates $(PRE_OCAML_FIND_PREDICATES) OCAML_DEP_PREDICATES := -syntax $(PRE_OCAML_FIND_PREDICATES) OCAML_FIND_PACKAGES := $(OCAML_FIND_PREDICATES) -package $(PRE_OCAML_FIND_PACKAGES) OCAML_DEP_PACKAGES := $(OCAML_DEP_PREDICATES) -package $(PRE_OCAML_FIND_PACKAGES) else OCAML_FIND_PACKAGES := -package $(subst $(space),$(comma),$(PACKS)) OCAML_DEP_PACKAGES := endif OCAML_FIND_LINKPKG := -linkpkg REAL_OCAMLFIND := $(OCAMLFIND) endif export OCAML_FIND_PACKAGES export OCAML_DEP_PACKAGES export OCAML_FIND_LINKPKG export REAL_OCAMLFIND ifndef OCAMLDOC OCAMLDOC := ocamldoc endif export OCAMLDOC ifndef LATEX LATEX := latex endif export LATEX ifndef DVIPS DVIPS := dvips endif export DVIPS ifndef PS2PDF PS2PDF := ps2pdf endif export PS2PDF ifndef OCAMLMAKEFILE OCAMLMAKEFILE := OCamlMakefile endif export OCAMLMAKEFILE ifndef OCAMLLIBPATH OCAMLLIBPATH := \ $(shell $(OCAMLC) 2>/dev/null -where || echo /usr/local/lib/ocaml) endif export OCAMLLIBPATH ifndef OCAML_LIB_INSTALL OCAML_LIB_INSTALL := $(OCAMLLIBPATH)/contrib endif export OCAML_LIB_INSTALL ########################################################################### #################### change following sections only if #################### you know what you are doing! # delete target files when a build command fails .PHONY: .DELETE_ON_ERROR .DELETE_ON_ERROR: # for pedants using "--warn-undefined-variables" export MAYBE_IDL export REAL_RESULT export CAMLIDLFLAGS export THREAD_FLAG export RES_CLIB export MAKEDLL export ANNOT_FLAG INCFLAGS := SHELL := /bin/sh MLDEPDIR := ._d BCDIDIR := ._bcdi NCDIDIR := ._ncdi FILTER_EXTNS := %.mli %.ml %.mll %.mly %.idl %.c %.$(EXT_CXX) %.rep %.zog %.glade FILTERED := $(filter $(FILTER_EXTNS), $(SOURCES)) SOURCE_DIRS := $(filter-out ./, $(sort $(dir $(FILTERED)))) FILTERED_REP := $(filter %.rep, $(FILTERED)) DEP_REP := $(FILTERED_REP:%.rep=$(MLDEPDIR)/%.d) AUTO_REP := $(FILTERED_REP:.rep=.ml) FILTERED_ZOG := $(filter %.zog, $(FILTERED)) DEP_ZOG := $(FILTERED_ZOG:%.zog=$(MLDEPDIR)/%.d) AUTO_ZOG := $(FILTERED_ZOG:.zog=.ml) FILTERED_GLADE := $(filter %.glade, $(FILTERED)) DEP_GLADE := $(FILTERED_GLADE:%.glade=$(MLDEPDIR)/%.d) AUTO_GLADE := $(FILTERED_GLADE:.glade=.ml) FILTERED_ML := $(filter %.ml, $(FILTERED)) DEP_ML := $(FILTERED_ML:%.ml=$(MLDEPDIR)/%.d) FILTERED_MLI := $(filter %.mli, $(FILTERED)) DEP_MLI := $(FILTERED_MLI:.mli=.di) FILTERED_MLL := $(filter %.mll, $(FILTERED)) DEP_MLL := $(FILTERED_MLL:%.mll=$(MLDEPDIR)/%.d) AUTO_MLL := $(FILTERED_MLL:.mll=.ml) FILTERED_MLY := $(filter %.mly, $(FILTERED)) DEP_MLY := $(FILTERED_MLY:%.mly=$(MLDEPDIR)/%.d) $(FILTERED_MLY:.mly=.di) AUTO_MLY := $(FILTERED_MLY:.mly=.mli) $(FILTERED_MLY:.mly=.ml) FILTERED_IDL := $(filter %.idl, $(FILTERED)) DEP_IDL := $(FILTERED_IDL:%.idl=$(MLDEPDIR)/%.d) $(FILTERED_IDL:.idl=.di) C_IDL := $(FILTERED_IDL:%.idl=%_stubs.c) ifndef NOIDLHEADER C_IDL += $(FILTERED_IDL:.idl=.h) endif OBJ_C_IDL := $(FILTERED_IDL:%.idl=%_stubs.$(EXT_OBJ)) AUTO_IDL := $(FILTERED_IDL:.idl=.mli) $(FILTERED_IDL:.idl=.ml) $(C_IDL) FILTERED_C_CXX := $(filter %.c %.$(EXT_CXX), $(FILTERED)) OBJ_C_CXX := $(FILTERED_C_CXX:.c=.$(EXT_OBJ)) OBJ_C_CXX := $(OBJ_C_CXX:.$(EXT_CXX)=.$(EXT_OBJ)) PRE_TARGETS += $(AUTO_MLL) $(AUTO_MLY) $(AUTO_IDL) $(AUTO_ZOG) $(AUTO_REP) $(AUTO_GLADE) ALL_DEPS := $(DEP_ML) $(DEP_MLI) $(DEP_MLL) $(DEP_MLY) $(DEP_IDL) $(DEP_ZOG) $(DEP_REP) $(DEP_GLADE) MLDEPS := $(filter %.d, $(ALL_DEPS)) MLIDEPS := $(filter %.di, $(ALL_DEPS)) BCDEPIS := $(MLIDEPS:%.di=$(BCDIDIR)/%.di) NCDEPIS := $(MLIDEPS:%.di=$(NCDIDIR)/%.di) ALLML := $(filter %.mli %.ml %.mll %.mly %.idl %.rep %.zog %.glade, $(FILTERED)) IMPLO_INTF := $(ALLML:%.mli=%.mli.__) IMPLO_INTF := $(foreach file, $(IMPLO_INTF), \ $(basename $(file)).cmi $(basename $(file)).cmo) IMPLO_INTF := $(filter-out %.mli.cmo, $(IMPLO_INTF)) IMPLO_INTF := $(IMPLO_INTF:%.mli.cmi=%.cmi) IMPLX_INTF := $(IMPLO_INTF:.cmo=.cmx) INTF := $(filter %.cmi, $(IMPLO_INTF)) IMPL_CMO := $(filter %.cmo, $(IMPLO_INTF)) IMPL_CMX := $(IMPL_CMO:.cmo=.cmx) IMPL_ASM := $(IMPL_CMO:.cmo=.asm) IMPL_S := $(IMPL_CMO:.cmo=.s) OBJ_LINK := $(OBJ_C_IDL) $(OBJ_C_CXX) OBJ_FILES := $(IMPL_CMO:.cmo=.$(EXT_OBJ)) $(OBJ_LINK) EXECS := $(addsuffix $(EXE), \ $(sort $(TOPRESULT) $(BCRESULT) $(NCRESULT))) ifdef WIN32 EXECS += $(BCRESULT).dll $(NCRESULT).dll endif CLIB_BASE := $(RESULT)$(RES_CLIB_SUF) ifneq ($(strip $(OBJ_LINK)),) RES_CLIB := lib$(CLIB_BASE).$(EXT_LIB) endif ifndef MSVC DLLSONAME := dll$(CLIB_BASE).so endif NONEXECS := $(INTF) $(IMPL_CMO) $(IMPL_CMX) $(IMPL_ASM) $(IMPL_S) \ $(OBJ_FILES) $(PRE_TARGETS) $(BCRESULT).cma $(NCRESULT).cmxa \ $(NCRESULT).$(EXT_LIB) $(BCRESULT).cmi $(BCRESULT).cmo \ $(NCRESULT).cmi $(NCRESULT).cmx $(NCRESULT).o \ $(RES_CLIB) $(IMPL_CMO:.cmo=.annot) ifndef MSVC ifndef STATIC NONEXECS += $(DLLSONAME) endif endif ifndef LIBINSTALL_FILES LIBINSTALL_FILES := $(RESULT).mli $(RESULT).cmi $(RESULT).cma \ $(RESULT).cmxa $(RESULT).$(EXT_LIB) $(RES_CLIB) ifndef MSVC ifndef STATIC ifneq ($(strip $(OBJ_LINK)),) LIBINSTALL_FILES += $(DLLSONAME) endif endif endif endif export LIBINSTALL_FILES ifdef WIN32 # some extra stuff is created while linking DLLs NONEXECS += $(BCRESULT).$(EXT_LIB) $(BCRESULT).exp $(NCRESULT).exp endif TARGETS := $(EXECS) $(NONEXECS) # If there are IDL-files ifneq ($(strip $(FILTERED_IDL)),) MAYBE_IDL := -cclib -lcamlidl endif ifdef USE_CAMLP4 CAMLP4PATH := \ $(shell $(CAMLP4) -where 2>/dev/null || echo /usr/local/lib/camlp4) INCFLAGS := -I $(CAMLP4PATH) CINCFLAGS := -I$(CAMLP4PATH) endif DINCFLAGS := $(INCFLAGS) $(SOURCE_DIRS:%=-I %) $(OCAML_DEFAULT_DIRS:%=-I %) INCFLAGS := $(DINCFLAGS) $(INCDIRS:%=-I %) CINCFLAGS += $(SOURCE_DIRS:%=-I%) $(INCDIRS:%=-I%) $(OCAML_DEFAULT_DIRS:%=-I%) CLIBFLAGS += $(SOURCE_DIRS:%=-L%) $(LIBDIRS:%=-L%) \ $(EXTLIBDIRS:%=-L%) $(EXTLIBDIRS:%=-Wl,$(RPATH_FLAG)%) \ $(OCAML_DEFAULT_DIRS:%=-L%) ifndef PROFILING INTF_OCAMLC := $(OCAMLC) else ifndef THREADS INTF_OCAMLC := $(OCAMLCP) -p $(OCAMLCPFLAGS) else # OCaml does not support profiling byte code # with threads (yet), therefore we force an error. ifndef REAL_OCAMLC $(error Profiling of multithreaded byte code not yet supported by OCaml) endif INTF_OCAMLC := $(OCAMLC) endif endif COMMON_LDFLAGS := $(LDFLAGS:%=-ccopt %) $(SOURCE_DIRS:%=-ccopt -L%) \ $(LIBDIRS:%=-ccopt -L%) $(EXTLIBDIRS:%=-ccopt -L%) \ $(EXTLIBDIRS:%=-ccopt -Wl,$(RPATH_FLAG)%) \ $(OCAML_DEFAULT_DIRS:%=-ccopt -L%) ifndef MSVC CLIBS_OPTS := $(CLIBS:%=-cclib -l%) else # MSVC libraries do not have 'lib' prefix CLIBS_OPTS := $(CLIBS:%=-cclib %.lib) endif ifneq ($(strip $(OBJ_LINK)),) ifdef CREATE_LIB OBJS_LIBS := -cclib -l$(CLIB_BASE) $(CLIBS_OPTS) $(MAYBE_IDL) else OBJS_LIBS := $(OBJ_LINK) $(CLIBS_OPTS) $(MAYBE_IDL) endif else OBJS_LIBS := $(CLIBS_OPTS) $(MAYBE_IDL) endif # If we have to make byte-code ifndef REAL_OCAMLC # EXTRADEPS is added dependencies we have to insert for all # executable files we generate. Ideally it should be all of the # libraries we use, but it's hard to find the ones that get searched on # the path since I don't know the paths built into the compiler, so # just include the ones with slashes in their names. EXTRADEPS := $(addsuffix .cma,$(foreach i,$(LIBS),$(if $(findstring /,$(i)),$(i)))) SPECIAL_OCAMLFLAGS := $(OCAMLBCFLAGS) REAL_OCAMLC := $(INTF_OCAMLC) REAL_IMPL := $(IMPL_CMO) REAL_IMPL_INTF := $(IMPLO_INTF) IMPL_SUF := .cmo DEPFLAGS := MAKE_DEPS := $(MLDEPS) $(BCDEPIS) ifdef CREATE_LIB CFLAGS := $(PIC_FLAGS) $(CFLAGS) ifndef STATIC ifneq ($(strip $(OBJ_LINK)),) MAKEDLL := $(DLLSONAME) ALL_LDFLAGS := -dllib $(DLLSONAME) endif endif endif ifndef NO_CUSTOM ifneq "$(strip $(OBJ_LINK) $(THREADS) $(MAYBE_IDL) $(CLIBS))" "" ALL_LDFLAGS += -custom endif endif ALL_LDFLAGS += $(INCFLAGS) $(OCAMLLDFLAGS) $(OCAMLBLDFLAGS) \ $(COMMON_LDFLAGS) $(LIBS:%=%.cma) CAMLIDLDLLFLAGS := ifdef THREADS ifdef VMTHREADS THREAD_FLAG := -vmthread else THREAD_FLAG := -thread endif ALL_LDFLAGS := $(THREAD_FLAG) $(ALL_LDFLAGS) ifndef CREATE_LIB ifndef REAL_OCAMLFIND ALL_LDFLAGS := unix.cma threads.cma $(ALL_LDFLAGS) endif endif endif # we have to make native-code else EXTRADEPS := $(addsuffix .cmxa,$(foreach i,$(LIBS),$(if $(findstring /,$(i)),$(i)))) ifndef PROFILING SPECIAL_OCAMLFLAGS := $(OCAMLNCFLAGS) PLDFLAGS := else SPECIAL_OCAMLFLAGS := -p $(OCAMLNCFLAGS) PLDFLAGS := -p endif REAL_IMPL := $(IMPL_CMX) REAL_IMPL_INTF := $(IMPLX_INTF) IMPL_SUF := .cmx CFLAGS := -DNATIVE_CODE $(CFLAGS) DEPFLAGS := -native MAKE_DEPS := $(MLDEPS) $(NCDEPIS) ALL_LDFLAGS := $(PLDFLAGS) $(INCFLAGS) $(OCAMLLDFLAGS) \ $(OCAMLNLDFLAGS) $(COMMON_LDFLAGS) CAMLIDLDLLFLAGS := -opt ifndef CREATE_LIB ALL_LDFLAGS += $(LIBS:%=%.cmxa) else CFLAGS := $(PIC_FLAGS) $(CFLAGS) endif ifdef THREADS THREAD_FLAG := -thread ALL_LDFLAGS := $(THREAD_FLAG) $(ALL_LDFLAGS) ifndef CREATE_LIB ifndef REAL_OCAMLFIND ALL_LDFLAGS := unix.cmxa threads.cmxa $(ALL_LDFLAGS) endif endif endif endif export MAKE_DEPS ifdef ANNOTATE ANNOT_FLAG := -dtypes else endif ALL_OCAMLCFLAGS := $(THREAD_FLAG) $(ANNOT_FLAG) $(OCAMLFLAGS) \ $(INCFLAGS) $(SPECIAL_OCAMLFLAGS) ifdef make_deps -include $(MAKE_DEPS) PRE_TARGETS := endif ########################################################################### # USER RULES # Call "OCamlMakefile QUIET=" to get rid of all of the @'s. QUIET=@ # generates byte-code (default) byte-code: $(PRE_TARGETS) $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) $(BCRESULT) \ REAL_RESULT="$(BCRESULT)" make_deps=yes bc: byte-code byte-code-nolink: $(PRE_TARGETS) $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) nolink \ REAL_RESULT="$(BCRESULT)" make_deps=yes bcnl: byte-code-nolink top: $(PRE_TARGETS) $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) $(TOPRESULT) \ REAL_RESULT="$(BCRESULT)" make_deps=yes # generates native-code native-code: $(PRE_TARGETS) $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) $(NCRESULT) \ REAL_RESULT="$(NCRESULT)" \ REAL_OCAMLC="$(OCAMLOPT)" \ make_deps=yes nc: native-code native-code-nolink: $(PRE_TARGETS) $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) nolink \ REAL_RESULT="$(NCRESULT)" \ REAL_OCAMLC="$(OCAMLOPT)" \ make_deps=yes ncnl: native-code-nolink # generates byte-code libraries byte-code-library: $(PRE_TARGETS) $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) \ $(RES_CLIB) $(BCRESULT).cma \ REAL_RESULT="$(BCRESULT)" \ CREATE_LIB=yes \ make_deps=yes bcl: byte-code-library # generates native-code libraries native-code-library: $(PRE_TARGETS) $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) \ $(RES_CLIB) $(NCRESULT).cmxa \ REAL_RESULT="$(NCRESULT)" \ REAL_OCAMLC="$(OCAMLOPT)" \ CREATE_LIB=yes \ make_deps=yes ncl: native-code-library ifdef WIN32 # generates byte-code dll byte-code-dll: $(PRE_TARGETS) $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) \ $(RES_CLIB) $(BCRESULT).dll \ REAL_RESULT="$(BCRESULT)" \ make_deps=yes bcd: byte-code-dll # generates native-code dll native-code-dll: $(PRE_TARGETS) $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) \ $(RES_CLIB) $(NCRESULT).dll \ REAL_RESULT="$(NCRESULT)" \ REAL_OCAMLC="$(OCAMLOPT)" \ make_deps=yes ncd: native-code-dll endif # generates byte-code with debugging information debug-code: $(PRE_TARGETS) $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) $(BCRESULT) \ REAL_RESULT="$(BCRESULT)" make_deps=yes \ OCAMLFLAGS="-g $(OCAMLFLAGS)" \ OCAMLLDFLAGS="-g $(OCAMLLDFLAGS)" dc: debug-code debug-code-nolink: $(PRE_TARGETS) $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) nolink \ REAL_RESULT="$(BCRESULT)" make_deps=yes \ OCAMLFLAGS="-g $(OCAMLFLAGS)" \ OCAMLLDFLAGS="-g $(OCAMLLDFLAGS)" dcnl: debug-code-nolink # generates byte-code libraries with debugging information debug-code-library: $(PRE_TARGETS) $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) \ $(RES_CLIB) $(BCRESULT).cma \ REAL_RESULT="$(BCRESULT)" make_deps=yes \ CREATE_LIB=yes \ OCAMLFLAGS="-g $(OCAMLFLAGS)" \ OCAMLLDFLAGS="-g $(OCAMLLDFLAGS)" dcl: debug-code-library # generates byte-code for profiling profiling-byte-code: $(PRE_TARGETS) $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) $(BCRESULT) \ REAL_RESULT="$(BCRESULT)" PROFILING="y" \ make_deps=yes pbc: profiling-byte-code # generates native-code profiling-native-code: $(PRE_TARGETS) $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) $(NCRESULT) \ REAL_RESULT="$(NCRESULT)" \ REAL_OCAMLC="$(OCAMLOPT)" \ PROFILING="y" \ make_deps=yes pnc: profiling-native-code # generates byte-code libraries profiling-byte-code-library: $(PRE_TARGETS) $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) \ $(RES_CLIB) $(BCRESULT).cma \ REAL_RESULT="$(BCRESULT)" PROFILING="y" \ CREATE_LIB=yes \ make_deps=yes pbcl: profiling-byte-code-library # generates native-code libraries profiling-native-code-library: $(PRE_TARGETS) $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) \ $(RES_CLIB) $(NCRESULT).cmxa \ REAL_RESULT="$(NCRESULT)" PROFILING="y" \ REAL_OCAMLC="$(OCAMLOPT)" \ CREATE_LIB=yes \ make_deps=yes pncl: profiling-native-code-library # packs byte-code objects pack-byte-code: $(PRE_TARGETS) $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) $(BCRESULT).cmo \ REAL_RESULT="$(BCRESULT)" \ PACK_LIB=yes make_deps=yes pabc: pack-byte-code # packs native-code objects pack-native-code: $(PRE_TARGETS) $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) \ $(NCRESULT).cmx $(NCRESULT).o \ REAL_RESULT="$(NCRESULT)" \ REAL_OCAMLC="$(OCAMLOPT)" \ PACK_LIB=yes make_deps=yes panc: pack-native-code # generates HTML-documentation htdoc: doc/$(RESULT)/html # generates Latex-documentation ladoc: doc/$(RESULT)/latex # generates PostScript-documentation psdoc: doc/$(RESULT)/latex/doc.ps # generates PDF-documentation pdfdoc: doc/$(RESULT)/latex/doc.pdf # generates all supported forms of documentation doc: htdoc ladoc psdoc pdfdoc ########################################################################### # LOW LEVEL RULES $(REAL_RESULT): $(REAL_IMPL_INTF) $(OBJ_LINK) $(EXTRADEPS) $(RESULTDEPS) $(REAL_OCAMLFIND) $(REAL_OCAMLC) \ $(OCAML_FIND_PACKAGES) $(OCAML_FIND_LINKPKG) \ $(ALL_LDFLAGS) $(OBJS_LIBS) -o $@$(EXE) \ $(REAL_IMPL) nolink: $(REAL_IMPL_INTF) $(OBJ_LINK) ifdef WIN32 $(REAL_RESULT).dll: $(REAL_IMPL_INTF) $(OBJ_LINK) $(CAMLIDLDLL) $(CAMLIDLDLLFLAGS) $(OBJ_LINK) $(CLIBS) \ -o $@ $(REAL_IMPL) endif %$(TOPSUFFIX): $(REAL_IMPL_INTF) $(OBJ_LINK) $(EXTRADEPS) $(REAL_OCAMLFIND) $(OCAMLMKTOP) \ $(OCAML_FIND_PACKAGES) $(OCAML_FIND_LINKPKG) \ $(ALL_LDFLAGS) $(OBJS_LIBS) -o $@$(EXE) \ $(REAL_IMPL) .SUFFIXES: .mli .ml .cmi .cmo .cmx .cma .cmxa .$(EXT_OBJ) \ .mly .di .d .$(EXT_LIB) .idl .c .$(EXT_CXX) .h .so \ .rep .zog .glade ifndef MSVC $(DLLSONAME): $(OBJ_LINK) $(OCAMLMKLIB) $(INCFLAGS) $(CLIBFLAGS) \ -o $(CLIB_BASE) $(OBJ_LINK) $(CLIBS:%=-l%) \ $(OCAMLMKLIB_FLAGS) endif $(RESULT).cma: $(REAL_IMPL_INTF) $(MAKEDLL) $(EXTRADEPS) $(RESULTDEPS) $(REAL_OCAMLFIND) $(REAL_OCAMLC) -a $(ALL_LDFLAGS) \ $(OBJS_LIBS) -o $@ $(OCAMLBLDFLAGS) $(REAL_IMPL) $(RESULT).cmxa $(RESULT).$(EXT_LIB): $(REAL_IMPL_INTF) $(EXTRADEPS) $(RESULTDEPS) $(REAL_OCAMLFIND) $(OCAMLOPT) -a $(ALL_LDFLAGS) $(OBJS_LIBS) \ $(OCAMLNLDFLAGS) -o $@ $(REAL_IMPL) $(RES_CLIB): $(OBJ_LINK) ifndef MSVC ifneq ($(strip $(OBJ_LINK)),) $(AR) rcs $@ $(OBJ_LINK) endif else ifneq ($(strip $(OBJ_LINK)),) lib -nologo -debugtype:cv -out:$(RES_CLIB) $(OBJ_LINK) endif endif .mli.cmi: $(EXTRADEPS) $(QUIET)pp=`sed -n -e '/^#/d' -e 's/(\*pp \([^*]*\) \*)/\1/p;q' $<`; \ if [ -z "$$pp" ]; then \ echo $(REAL_OCAMLFIND) $(INTF_OCAMLC) $(OCAML_FIND_PACKAGES) \ -c $(THREAD_FLAG) $(ANNOT_FLAG) \ $(OCAMLFLAGS) $(INCFLAGS) $<; \ $(REAL_OCAMLFIND) $(INTF_OCAMLC) $(OCAML_FIND_PACKAGES) \ -c $(THREAD_FLAG) $(ANNOT_FLAG) \ $(OCAMLFLAGS) $(INCFLAGS) $<; \ else \ echo $(REAL_OCAMLFIND) $(INTF_OCAMLC) $(OCAML_FIND_PACKAGES) \ -c -pp \"$$pp $(PPFLAGS)\" $(THREAD_FLAG) $(ANNOT_FLAG) \ $(OCAMLFLAGS) $(INCFLAGS) $<; \ $(REAL_OCAMLFIND) $(INTF_OCAMLC) $(OCAML_FIND_PACKAGES) \ -c -pp "$$pp $(PPFLAGS)" $(THREAD_FLAG) $(ANNOT_FLAG) \ $(OCAMLFLAGS) $(INCFLAGS) $<; \ fi .ml.cmi .ml.$(EXT_OBJ) .ml.cmx .ml.cmo: $(EXTRADEPS) $(QUIET)pp=`sed -n -e '/^#/d' -e 's/(\*pp \([^*]*\) \*)/\1/p;q' $<`; \ if [ -z "$$pp" ]; then \ echo $(REAL_OCAMLFIND) $(REAL_OCAMLC) $(OCAML_FIND_PACKAGES) \ -c $(ALL_OCAMLCFLAGS) $<; \ $(REAL_OCAMLFIND) $(REAL_OCAMLC) $(OCAML_FIND_PACKAGES) \ -c $(ALL_OCAMLCFLAGS) $<; \ else \ echo $(REAL_OCAMLFIND) $(REAL_OCAMLC) $(OCAML_FIND_PACKAGES) \ -c -pp \"$$pp $(PPFLAGS)\" $(ALL_OCAMLCFLAGS) $<; \ $(REAL_OCAMLFIND) $(REAL_OCAMLC) $(OCAML_FIND_PACKAGES) \ -c -pp "$$pp $(PPFLAGS)" $(ALL_OCAMLCFLAGS) $<; \ fi ifdef PACK_LIB $(REAL_RESULT).cmo $(REAL_RESULT).cmx $(REAL_RESULT).o: $(REAL_IMPL_INTF) $(OBJ_LINK) $(EXTRADEPS) $(REAL_OCAMLFIND) $(REAL_OCAMLC) -pack $(ALL_LDFLAGS) \ $(OBJS_LIBS) -o $@ $(REAL_IMPL) endif .PRECIOUS: %.ml %.ml: %.mll $(OCAMLLEX) $< .PRECIOUS: %.ml %.mli %.ml %.mli: %.mly $(OCAMLYACC) $(YFLAGS) $< .PRECIOUS: %.ml %.ml : %.rep $(CAMELEON_REPORT) $(CAMELEON_REPORT_FLAGS) -gen $< .PRECIOUS: %.ml %.ml : %.zog $(CAMELEON_ZOGGY) $(CAMELEON_ZOGGY_FLAGS) -impl $< > $@ .PRECIOUS: %.ml %.ml : %.glade $(OCAML_GLADECC) $(OCAML_GLADECC_FLAGS) $< > $@ .PRECIOUS: %.ml %.mli %_stubs.c %.h %.ml %.mli %_stubs.c %.h: %.idl $(CAMLIDL) $(MAYBE_IDL_HEADER) $(IDLFLAGS) \ $(CAMLIDLFLAGS) $< $(QUIET)if [ $(NOIDLHEADER) ]; then touch $*.h; fi .c.$(EXT_OBJ): $(CC) -c $(CFLAGS) $(CINCFLAGS) -I'$(OCAMLLIBPATH)' \ $< $(CFLAG_O)$@ .$(EXT_CXX).$(EXT_OBJ): $(CXX) -c $(CXXFLAGS) $(CINCFLAGS) -I'$(OCAMLLIBPATH)' \ $< $(CFLAG_O)$@ $(MLDEPDIR)/%.d: %.ml $(QUIET)echo making $@ from $< $(QUIET)if [ ! -d $(@D) ]; then mkdir -p $(@D); fi $(QUIET)pp=`sed -n -e '/^#/d' -e 's/(\*pp \([^*]*\) \*)/\1/p;q' $<`; \ if [ -z "$$pp" ]; then \ $(REAL_OCAMLFIND) $(OCAMLDEP) $(OCAML_DEP_PACKAGES) \ $(DINCFLAGS) $< > $@; \ else \ $(REAL_OCAMLFIND) $(OCAMLDEP) $(OCAML_DEP_PACKAGES) \ -pp "$$pp $(PPFLAGS)" $(DINCFLAGS) $< > $@; \ fi $(BCDIDIR)/%.di $(NCDIDIR)/%.di: %.mli $(QUIET)echo making $@ from $< $(QUIET)if [ ! -d $(@D) ]; then mkdir -p $(@D); fi $(QUIET)pp=`sed -n -e '/^#/d' -e 's/(\*pp \([^*]*\) \*)/\1/p;q' $<`; \ if [ -z "$$pp" ]; then \ $(REAL_OCAMLFIND) $(OCAMLDEP) $(DEPFLAGS) $(DINCFLAGS) $< > $@; \ else \ $(REAL_OCAMLFIND) $(OCAMLDEP) $(DEPFLAGS) \ -pp "$$pp $(PPFLAGS)" $(DINCFLAGS) $< > $@; \ fi doc/$(RESULT)/html: $(DOC_FILES) rm -rf $@ mkdir -p $@ $(QUIET)pp=`sed -n -e '/^#/d' -e 's/(\*pp \([^*]*\) \*)/\1/p;q' $<`; \ if [ -z "$$pp" ]; then \ echo $(OCAMLDOC) -html -d $@ $(OCAMLDOCFLAGS) $(INCFLAGS) $(DOC_FILES); \ $(OCAMLDOC) -html -d $@ $(OCAMLDOCFLAGS) $(INCFLAGS) $(DOC_FILES); \ else \ echo $(OCAMLDOC) -pp \"$$pp $(PPFLAGS)\" -html -d $@ $(OCAMLDOCFLAGS) \ $(INCFLAGS) $(DOC_FILES); \ $(OCAMLDOC) -pp "$$pp $(PPFLAGS)" -html -d $@ $(OCAMLDOCFLAGS) \ $(INCFLAGS) $(DOC_FILES); \ fi doc/$(RESULT)/latex: $(DOC_FILES) rm -rf $@ mkdir -p $@ $(QUIET)pp=`sed -n -e '/^#/d' -e 's/(\*pp \([^*]*\) \*)/\1/p;q' $<`; \ if [ -z "$$pp" ]; then \ echo $(OCAMLDOC) -latex $(OCAMLDOCFLAGS) $(INCFLAGS) \ $(DOC_FILES) -o $@/doc.tex; \ $(OCAMLDOC) -latex $(OCAMLDOCFLAGS) $(INCFLAGS) $(DOC_FILES) \ -o $@/doc.tex; \ else \ echo $(OCAMLDOC) -pp \"$$pp $(PPFLAGS)\" -latex $(OCAMLDOCFLAGS) \ $(INCFLAGS) $(DOC_FILES) -o $@/doc.tex; \ $(OCAMLDOC) -pp "$$pp $(PPFLAGS)" -latex $(OCAMLDOCFLAGS) \ $(INCFLAGS) $(DOC_FILES) -o $@/doc.tex; \ fi doc/$(RESULT)/latex/doc.ps: doc/$(RESULT)/latex cd doc/$(RESULT)/latex && \ $(LATEX) doc.tex && \ $(LATEX) doc.tex && \ $(DVIPS) $(DVIPSFLAGS) doc.dvi -o $(@F) doc/$(RESULT)/latex/doc.pdf: doc/$(RESULT)/latex/doc.ps cd doc/$(RESULT)/latex && $(PS2PDF) $( try match Stream.next stream with String s -> STRING s | Int i -> INT i | Float f -> FLOAT f | Char c -> CHAR c | Ident s -> IDENT s | Kwd ";" -> SEP | Kwd "include" -> INCLUDE | Kwd "skip" -> SKIP | Kwd _ -> invalid_arg "Directive.get_token" with _ -> EOF (* Adapted from String.index *) let rec index_rec s lim i c = if i >= lim then raise Not_found else let cur = s.[i] in if cur = c then i else if cur = ' ' || cur = '\n' || cur = '\t' || cur = '\r' then index_rec s lim (i+1) c else raise Not_found let index s c = index_rec s (String.length s) 0 c (* *) exception Forbidden_file of string let digest_files parents directives = List.map (function `Include file -> let digest = lazy (Digest.file file) in List.iter (fun (pfile, pdigest) -> if Lazy.force digest = Lazy.force pdigest then raise (Forbidden_file file)) parents; `Include (file, digest) | `Skip -> `Skip) directives let find_directives parents (source, line, char) s = try let pos = index s '@' + 1 in let code = String.sub s pos (String.length s - pos) in let char_stream = Stream.of_string code in let token_stream = lexer char_stream in let parsing_result = directive_list (get_token token_stream) (Lexing.from_string "") in let result = digest_files parents parsing_result in Some result with Not_found -> None | e -> eprintf "File %S, line %i, characters %i-%i:\nBad directives\n" source line (char - 1) (char - 1 + String.length s); flush stderr; raise e let find_expr (source, line, char) s = try let pos = index s '=' + 1 in Some (String.sub s pos (String.length s - pos), pos) with Not_found -> None camlmix-1.3.1/examples/000077500000000000000000000000001212551120000147515ustar00rootroot00000000000000camlmix-1.3.1/examples/Makefile000066400000000000000000000020261212551120000164110ustar00rootroot00000000000000.PHONY: all RESULT = simple.txt include.txt prog.ml test.html test2.c dynamic.txt \ dynamic2.txt all: $(RESULT) simple.txt: simple.mlx ../camlmix $< -o $@ include.txt: include1.mlx include2.mlx ../camlmix include2.mlx -o include.txt prog.ml: xpp.mlx prog.mlx ../camlmix $^ -o $@ ocaml prog.ml || : test.html: test.mlx macro.ml ../camlmix test.mlx -o $@ test2.c: test2.mlx macro.ml ../camlmix test2.mlx -o $@ dynamic.txt: dynamic ./dynamic "`date`" > dynamic.txt cat dynamic.txt dynamic: dynamic.ml dynamic_main.ml ocamlc -o dynamic dynamic.ml dynamic_main.ml dynamic.ml: dynamic.mlx ../camlmix -c dynamic.mlx -co dynamic.ml -fun ocamlc -i dynamic.ml dynamic2.txt: dynamic2 ./dynamic2 Johnny Smith 33 > dynamic2.txt cat dynamic2.txt dynamic2: dynamic2.ml dynamic2_main.ml ocamlc -o dynamic2 dynamic2.ml dynamic2_main.ml dynamic2.ml: dynamic2.mlx ../camlmix -c dynamic2.mlx -co dynamic2.ml -fun ocamlc -i dynamic2.ml .PHONY: clean clean: rm -f $(RESULT) *.mlx.ml dynamic.ml dynamic2.ml \ dynamic dynamic2 *~ *.cmo *.cmi camlmix-1.3.1/examples/README000066400000000000000000000014711212551120000156340ustar00rootroot00000000000000The files of this directory are in the public domain. Test with: make Clean with: make clean simple.mlx: minimalist example showing the basic syntax issues include1.mlx, include2.mlx: illustration of the "include" directive xpp.mlx, prog.mlx: example of simple meta-programming. An OCaml file is produced. The main issue is to report error locations correctly, which is achieved by xpp.mlx. test.mlx: a longer test which produces a HTML file (where whitespace is not very significant) test2.mlx: another test, produces a C file dynamic.mlx, dynamic_main.mlx: compiling a template into a regular OCaml module, and calling the render function from a regular program dynamic2.mlx, dynamic2_main.mlx: template with multiple parameters; printing into an explicit buffer instead of stdout. camlmix-1.3.1/examples/dynamic.mlx000066400000000000000000000000641212551120000171170ustar00rootroot00000000000000The parameter of the render function is ##=param##. camlmix-1.3.1/examples/dynamic2.mlx000066400000000000000000000003701212551120000172010ustar00rootroot00000000000000## open Printf let firstname, lastname, age = param .## Parameters are: ## List.iter (fun s -> print s; print " ") [ firstname; lastname; string_of_int age ] ## First name: ##=firstname## Last name: ##=lastname## Age: ##= string_of_int age## camlmix-1.3.1/examples/dynamic2_main.ml000066400000000000000000000005441212551120000200200ustar00rootroot00000000000000let _ = match Sys.argv with [| _; first; last; age_s |] -> let buf = Buffer.create 1000 in let print = Buffer.add_string buf in Dynamic2.render ~print (first, last, int_of_string age_s); let contents = Buffer.contents buf in print_string (String.uppercase contents) | _ -> prerr_string "Usage: dynamic2 firstname lastname age\n"; exit 1 camlmix-1.3.1/examples/dynamic_main.ml000066400000000000000000000001741212551120000177350ustar00rootroot00000000000000let _ = match Sys.argv with [| _; param |] -> Dynamic.render param | _ -> prerr_string "Usage: dynamic PARAM\n" camlmix-1.3.1/examples/hello.html000066400000000000000000000000241212551120000167360ustar00rootroot00000000000000Hello World! camlmix-1.3.1/examples/include1.mlx000066400000000000000000000000751212551120000172010ustar00rootroot00000000000000From include1.mlx: OCaml version: ##= Sys.ocaml_version ## camlmix-1.3.1/examples/include2.mlx000066400000000000000000000000751212551120000172020ustar00rootroot00000000000000## @include "include1.mlx" .## From include2.mlx: Bye bye. camlmix-1.3.1/examples/macro.ml000066400000000000000000000011521212551120000164030ustar00rootroot00000000000000let read_chan f ic = try while true do f (input_char ic) done with End_of_file -> () let include_file file = let ic = open_in_bin file in read_chan print_char ic; close_in ic let html_verbatim file = let ic = open_in_bin file in print_string "
\n";
  read_chan 
    (function
	   | '<' -> print_string "<"
       | '>' -> print_string ">"
       | '&' -> print_string "&"
       | c   -> print_char c)
    ic;
  print_string "
\n"; close_in ic let camlmix file = Sys.command ("./camlmix " ^ file) let author = "Martin Jambon" let some_text = "inserted using Ocaml" camlmix-1.3.1/examples/prog.mlx000066400000000000000000000002351212551120000164420ustar00rootroot00000000000000## let eval num = Printf.sprintf " %s " (string_of_float num) ## let pi = ##= eval (acos (-1.)) ## let x = unbound_value_on_purpose__check_the_location camlmix-1.3.1/examples/simple.mlx000066400000000000000000000005231212551120000167640ustar00rootroot00000000000000( ## print "with whitespace" ## ) ( ##= "with whitespace" ## ) ( ##.= "without whitespace on the left" ## ) ( ##= "without whitespace on the right" .## ) ( ##.= "without whitespace" .## ) ##= "conti-" ## nued on the next line ##= "conti-" .## nued on the same line specials: #### -> ### ####. -> ###. .#### -> .### camlmix-1.3.1/examples/test.mlx000066400000000000000000000012001212551120000164430ustar00rootroot00000000000000## #use "macro.ml" ## ## let source = "hello.html" ##

Source file for this page (test.mlx)

## html_verbatim "test.mlx" ##

Source files for camlmix

lexer.mll

## html_verbatim "../lexer.mll" ##

main.ml

## html_verbatim "../main.ml" ##

Makefile

## html_verbatim "Makefile" ##

Formatted from ##= source ##

## include_file source ##

Source file ##= source ##

## html_verbatim source ##

macro.ml

## html_verbatim "macro.ml" ##
## Camlmix.printer := ignore ## This text will be ignored. ## Camlmix.printer := print ## Author: ##= author ## camlmix-1.3.1/examples/test2.mlx000066400000000000000000000030551212551120000165370ustar00rootroot00000000000000## #use "macro.ml" .## ##. Camlmix.printer := ignore .## Ocaml quotations are delimited by either of the following two character sequences (shown here with an extra # symbol to avoid triggering a quotation): ### or ###. initiate Ocaml interpretation, while ### or .### resume text mode. ###. causes white space to the left to be removed from the output, while .### similarly removes all white space followed by a newline to the right. The delimiters chosen will cause the C comment to be the first line in the output. Two or more # symbols can be placed in the text by adding one extra # character, as seen above. Let's turn printing back on. ## Camlmix.printer := print .## ##..## ## let source = "Makefile" .## /* add some text here: ##= some_text .## - note the newline was ignored! Check whether 2 ###. .### ### A### ###A 3 ####. .#### #### A#### ####A 4 #####. .##### ##### A##### #####A 5 ######. .###### ###### A###### ######A are emitted correctly. */ int main() { int i = ##= string_of_int (3 + 17) (* i.e., 20 *) ##; ##. Camlmix.printer := ignore .## This text will be ignored. ## Camlmix.printer := print .## char* which = "verbatim: ### ##### ### ###= source ####"; ##.(* This text is part of an Ocaml comment. The # symbols in the char assignment above are printed, allbeit with one of each # symbols in a contiguous sequence removed. Note that we allow this comment to produce a newline in the output.*)## return 0; } camlmix-1.3.1/examples/xpp.mlx000066400000000000000000000007241212551120000163050ustar00rootroot00000000000000## (* Load this file and line directives will be printed. Very useful if you use camlmix for preprocessing OCaml programs. Example: camlmix xpp.mlx foo.mlx -o foo.ml -clean *) let line_directive () = Printf.sprintf "\n# %i %S;;\n%s" !Camlmix.line !Camlmix.source (String.make (!Camlmix.char - 1) ' ') let current_printer = !Camlmix.printer let _ = Camlmix.printer := (fun s -> print (line_directive ()); current_printer s) camlmix-1.3.1/lexer.mli000066400000000000000000000001431212551120000147530ustar00rootroot00000000000000val get : Lexing.lexbuf -> [ `Code of string | `Location of int * int | `Text of string ] list camlmix-1.3.1/lexer.mll000066400000000000000000000063721212551120000147700ustar00rootroot00000000000000{ (* Alternate line tracking mechanism using Ocaml 3.08 Lexing (not used yet for compatibility with older versions of OCaml) (* keep track of file position *) let incr_linenum lexbuf = let pos = lexbuf.Lexing.lex_curr_p in lexbuf.Lexing.lex_curr_p <- { pos with Lexing.pos_lnum = pos.Lexing.pos_lnum + 1; Lexing.pos_bol = pos.Lexing.pos_cnum } (* return string line(char) of file position *) let pos_to_string lexbuf = let pos = lexbuf.Lexing.lex_curr_p in (string_of_int pos.Lexing.pos_lnum) ^"."^(string_of_int (pos.Lexing.pos_cnum - pos.Lexing.pos_bol)) (* return file position *) let get_location () = let pos = lexbuf.Lexing.lex_curr_p in `Location ( pos.Lexing.pos_lnum, (pos.Lexing.pos_cnum - pos.Lexing.pos_bol)) *) let buf = Buffer.create 1024 let add_string = Buffer.add_string buf let add_char = Buffer.add_char buf let contents () = Buffer.contents buf let clear () = Buffer.clear buf let flush () = let s = contents () in clear (); s (* the position in the current file *) let line = ref 1 (* line numbered from 1 *) let char = ref 1 (* character in the current line numbered from 1 *) let newfile () = line := 1; char := 1 let location () = `Location (!line, !char) let newline () = add_char '\n'; incr line; char := 1 let newchars n = char := !char + n let init () = clear (); newfile () let add s = add_string s; newchars (String.length s) let addc c = add_char c; newchars 1 let length lexbuf = Lexing.lexeme_end lexbuf - Lexing.lexeme_start lexbuf } let nl = "\r\n" | "\n" | "\r" let text_ignore_ws_in = [ ' ' '\t' ]* "##." let code_ignore_ws_out = ".##" [ ' ' '\t' ]* let code_ignore_wsnl_out = ".##" [ ' ' '\t' ]* nl rule text = parse | "###" "#"+ as str { let len = String.length str - 1 in add (String.sub str 0 len); newchars len; text lexbuf } | "###" { add "##"; newchars 1; text lexbuf } | text_ignore_ws_in | "##" { newchars (length lexbuf); let t = `Text (flush ()) in let loc = location () in t :: loc :: code lexbuf } | nl { newline (); text lexbuf } | eof { [`Text (flush ())] } | _ { addc (Lexing.lexeme_char lexbuf 0); text lexbuf } and code = parse | "."? "###" "#"+ as str { let len = String.length str - 1 in add (String.sub str 0 len); newchars 1; code lexbuf } | "."? "###" as str { let len = String.length str - 1 in add (String.sub str 0 len); newchars 1; code lexbuf } | code_ignore_ws_out { newchars (length lexbuf); let e = `Code (flush ()) in let loc = location () in e :: loc :: text lexbuf } | code_ignore_wsnl_out { newchars (length lexbuf); newline (); let e = `Code (flush ()) in let loc = location () in e :: loc :: text lexbuf } | "##" { newchars 2; let e = `Code (flush ()) in let loc = location () in e :: loc :: text lexbuf } | nl { newline (); code lexbuf } | eof { [`Code (flush ())] } | _ { addc (Lexing.lexeme_char lexbuf 0); code lexbuf } { let get lexbuf = init (); `Location (1, 1) :: text lexbuf } camlmix-1.3.1/macro.ml000066400000000000000000000011031212551120000145610ustar00rootroot00000000000000let read_chan f ic = try while true do f (input_char ic) done with End_of_file -> () let include_file file = let ic = open_in_bin file in read_chan print_char ic; close_in ic let html_verbatim file = let ic = open_in_bin file in print_string "
\n";
  read_chan 
    (function
	   | '<' -> print_string "<"
       | '>' -> print_string ">"
       | '&' -> print_string "&"
       | c   -> print_char c)
    ic;
  print_string "
\n"; close_in ic let camlmix file = Sys.command ("./camlmix " ^ file) let author = "Martin Jambon" camlmix-1.3.1/main.ml000066400000000000000000000176631212551120000144260ustar00rootroot00000000000000open Printf open Arg let sources = ref [] let parse_only = ref false let ml_name = ref None let fun_option = ref false let clean = ref false let ocaml = ref "ocaml" let insertions = ref [] let stdout_file = ref None let remix = ref false let usage_msg = "\ General rules: Text between ## and ## is considered as a block of code. A block of code is normally some OCaml code. It can be any kind of toplevel expressions such as definitions or application of printing functions. The document blocks are printed on stdout. To avoid interpretation of repeated # symbols as OCaml quotations they must be prefixed by an additional # symbol. E.g., ### is replaced by ## both in code and in document blocks. White space introduced by OCaml quotations can be controlled by ##. and .## quotation symbols: ##. causes any white space to the left of the quotation symbol to be omitted from the output. Similarly .## causes any white space followed by one newline to be omitted from the output. Directives: Blocks of code that start with the @ character (possibly preceded by spaces) are directives for Camlmix. The following directives are available: include \"somefile.mlx\"; (* inserts a camlmix file *) skip; (* ignores the next block of text *) e.g.: Hello ## @include \"world.mlx\"; skip .## ## let x = 123 ##! Advanced usage: The OCaml program that is generated from the Camlmix files first defines a module called Camlmix. This module contains several variables that are updated automatically and may be used explicitely by the user. module Camlmix : sig val source : string ref val line : int ref val char : int ref (* source, line and char refer to the location of the first character of the current block in its source file (source file, line number starting from 1, position in the line starting from 1). They are updated automatically at the beginning of each (code or text) block. *) val printer : (string -> unit) ref (* the function that prints text blocks *) val print_with : (string -> unit) -> unit (* print_with f prints the next block of text using f instead of the current printer. Its behavior is undefined if it is called several times in the same OCaml block. *) val print_if : bool -> unit (* print_if cond prints the next block of text only if cond is true. It uses print_with. *) end Usage: camlmix [options] file1 file2 ... fileN A temporary file \"fileN.ml\" is created and then executed with ocaml. Command line options:" let options = [ "-c", Set parse_only, " only generate the .ml file"; "-co", String (fun s -> ml_name := Some s), " specify a name for the .ml file"; "-fun", Set fun_option, " make it the body of a function named \"render\", \ using a single argument named \"param\""; "-e", Set_string ocaml, " specify ocaml executable"; "-o", String (fun s -> stdout_file := Some s), " specify an output file"; "-clean", Set clean, " remove the temporary .ml file after execution"; "-insert", String (fun s -> insertions := s :: !insertions), " insert this code first"; "-remix", Set remix, " try a conversion to the camlremix syntax"; "-version", Unit (fun () -> print_endline Version.version; exit 0), " prints the version of Camlmix and exits"; ] let add_source s = sources := s :: !sources let camlmix_hooks oc = fprintf oc "\ module Camlmix = struct let source = ref \"\" let line = ref 1 let char = ref 1 let printer = ref print let print_with f = let saved_printer = !printer in printer := (fun s -> f s; printer := saved_printer) let print_if test = if not test then print_with ignore end ;; "; List.iter (fun s -> fprintf oc "%s\nlet () = ();;\n" s) (List.rev !insertions) let rec process_file oc grand_parents ((in_file, digest) as file_info) = let parents = file_info :: grand_parents in let (update_location, get_location, print_location) = let source = ref "" and line = ref 1 and char = ref 1 in let update s l c = source := s; line := l; char := c and get () = (!source, !line, !char) and print ?(dline = 0) ?(dchar = 0) oc = fprintf oc "\n# %i %S;;\n%s" (!line + dline) !source (String.make (!char + dchar - 1) ' ') in (update, get, print) in let ic = open_in_bin in_file in let lexbuf = Lexing.from_channel ic in let list = Lexer.get lexbuf in close_in ic; update_location in_file 1 1; print_location oc; let rec iter skip_text = function [] -> () | `Text s :: rest -> if not skip_text then (fprintf oc "\nlet () = !Camlmix.printer "; print_location ~dchar:1 oc; fprintf oc "%S;;\n" s); iter false rest | `Code s :: rest -> let loc = get_location () in (match Directive.find_directives parents loc s with Some l -> let skip_next_text = expand_directives oc parents l in iter skip_next_text rest | None -> (match Directive.find_expr loc s with Some (e, dchar) -> fprintf oc "\nlet () = !Camlmix.printer "; print_location ~dchar:(dchar - 2) oc; fprintf oc "( %s : string);;\n" e | None -> print_location oc; fprintf oc "%s" s); iter false rest) | `Location (line, char) :: rest -> update_location in_file line char; fprintf oc " let () = Camlmix.line := %i; Camlmix.char := %i; Camlmix.source := %S ;; " line char in_file; iter skip_text rest in iter false list and expand_directives oc parents l = let skip = ref false in List.iter (function `Include (file, digest) -> process_file oc parents (file, digest) | `Skip -> skip := true) l; !skip let render_body wrap body oc = if wrap then fprintf oc "\ let render ?(print = fun s -> print_string s; flush stdout) param = let module M = struct %t end in () " body else fprintf oc "\ let print s = print_string s; flush stdout %t " body let protect_remix oc s = String.iter (function '#' -> output_string oc "##" | '~' -> output_string oc "~~" | c -> output_char oc c) s let remix_file in_file = let out_file = in_file ^ ".remix" in let oc = open_out out_file in let ic = open_in_bin in_file in let lexbuf = Lexing.from_channel ic in let list = Lexer.get lexbuf in close_in ic; List.iter (function `Text s -> protect_remix oc s | `Code s -> fprintf oc "#(%a)#" protect_remix s | `Location (line, char) -> ()) list; close_out oc; printf "Wrote %s\n" out_file let exec_ocaml out_file ml_file = let buf = Buffer.create 1000 in let ic = Unix.open_process_in (sprintf "%s %s" !ocaml ml_file) in (try while true do Buffer.add_char buf (input_char ic) done with End_of_file -> let finish () = if !clean then Sys.remove ml_file in match Unix.close_process_in ic with Unix.WEXITED 0 -> finish () | Unix.WEXITED n -> finish (); exit n | _ -> finish (); exit 2); match out_file with None -> Buffer.output_buffer stdout buf | Some file -> let oc = open_out file in Buffer.output_buffer oc buf; close_out oc let _ = parse options add_source usage_msg; let rev_in_files = !sources in match rev_in_files, !stdout_file with [], None -> () | [], Some file -> close_out (open_out file) | l, opt -> if !remix then List.iter remix_file l else let ml_file = match !ml_name with Some s -> s | None -> List.hd l ^ ".ml" in let oc = open_out ml_file in let body oc = camlmix_hooks oc; List.iter (process_file oc []) (List.rev_map (fun file -> (file, lazy (Digest.file file))) rev_in_files) in render_body !fun_option body oc; close_out oc; if !parse_only then exit 0 else exec_ocaml opt ml_file camlmix-1.3.1/parser_directive.mly000066400000000000000000000006651212551120000172170ustar00rootroot00000000000000%token STRING %token INT %token FLOAT %token CHAR %token IDENT %token SEP INCLUDE SKIP %token EOF %start directive_list %type <[`Include of string | `Skip] list> directive_list %% directive_list: | directive SEP directive_list { $1 :: $3 } | directive EOF { [$1] } | EOF { [] } directive: | INCLUDE STRING { `Include $2 } | SKIP { `Skip } camlmix-1.3.1/version.ml000066400000000000000000000000261212551120000151500ustar00rootroot00000000000000let version = "1.3.0"